Skip to content

Instantly share code, notes, and snippets.

@triffid
Created January 2, 2013 23:20
Show Gist options
  • Save triffid/4439278 to your computer and use it in GitHub Desktop.
Save triffid/4439278 to your computer and use it in GitHub Desktop.
smoothie config design pattern
/*
* 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