Remarks and ideas:
- No need to write Console's destructor.
- It seems more natural to keep previous lines and pop as necessary (presumably your commented out deque was to that end?
- line 65 of Console.cpp - instead of insert(make_pair()) can simply do commandList.emplace(c, f);
- The states parameter isn't used in the draw function - either pass it to the draw calls or unname it.
- line 41 of Console.cpp - gcc points out that t < 128 is always true
- I would rather the commands the user registers return an ostream instead of a string - streaming makes for nicer syntax than string concatenation and you 're already using a stringstream in handleCommand.
- Could Up and Down be used to cycle through command history instead?
- (If you want to be really fancy) Provide autocomplete.
- I know there isn't, but I tend to keep it just in case I ever want to use it.
- Yes, that is correct. The deque is there for that purpose, I just wanted something working first. It's on the todo list!
- Of course... Not sure how I missed that, thanks.
- That's kind of in the same boat as the deque, should be used soon.
- SFML's text tutorial has a check for that, so I was more following that. In any case, it was more of a sanity check. Thanks for the info.
- That's a good idea... I agree, I'll look into doing that.
- That's the plan for the future!
- That is definitely a future addition!
I like the fact that one can simply bind lambda expressions to a command
std::function<const std::string(std::vector<std::string> args)>
Omit the const (returning a const object is a bad idea). Pass by value is fine, as long as you use move semantics (call std::move() to pass the vector), otherwise you copy unnecessarily. And I would use a typedef for the vector of strings, and maybe also for the function.
One thing to add would be functionality that helps with parsing and interpreting the command arguments.
Thanks! I love lambdas. They make things so much easier/add so much more functionality (captures are awesome).
Alright, I was trying to show that the string wasn't going to be changed, and for dealing with temporaries.
Same deal with passing the vector and strings by value, avoiding the temporaries issue. And I thought move semantics was the default in C++11 (or is it for C++14?)?
I played with a typedef previously, since you think it's a good idea, I'll go through with it!
You don't think a vector is enough for that? I was trying to C++icize the int argc, char** argv argument handling. With a vector, one can use:
for(auto &a : args) {}
syntax, which is nice and to the point. Or am I misunderstanding you?
In any case, thanks for the remarks!