Created
January 2, 2013 23:20
-
-
Save triffid/4439278 to your computer and use it in GitHub Desktop.
smoothie config design pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* intended design pattern: | |
* | |
* void YourModule::on_config_value(void *argument) | |
* { | |
* ConfigValue* value = staticcast<ConfigValue*>(argument); | |
* if (value->is_for_me(my_string)) | |
* { | |
* if (value->is_for_my_submodule()) | |
* { | |
* value->pass() | |
* for (int i = 0; i < submodules; i++) | |
* submodule[i]->on_config_value(value); | |
* value->pop(); | |
* } | |
* else | |
* { | |
* this->doSomethingWith(value->as_something_useful()); | |
* } | |
* } | |
* } | |
*/ | |
bool is_for_me(const char *name) | |
{ | |
return (strcasecmp(this->names[this->c], name) == 0); | |
} | |
bool is_for_my_submodule() | |
{ | |
return (this->c < (this->name - 1)); | |
} | |
ConfigValue* pass() | |
{ | |
if (this->c < (this->name - 1)) | |
{ | |
this->c++; | |
return this; | |
} | |
return NULL; | |
} | |
ConfigValue* pop() | |
{ | |
if (this->c) | |
{ | |
this->c--; | |
return this; | |
} | |
return NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment