summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2009-02-22 17:42:54 +0100
committerDanny Baumann <dannybaumann@web.de>2009-02-22 17:42:54 +0100
commit03f611e6cfd26019bd2ec1701b1b84679722e1cb (patch)
tree1863f7493e4b9e517d5e19cd1b9ace6f7187ab63
parent91fcc47d14c249168d514f74fe27e8e9b212ff9b (diff)
downloadzcomp-03f611e6cfd26019bd2ec1701b1b84679722e1cb.tar.gz
zcomp-03f611e6cfd26019bd2ec1701b1b84679722e1cb.tar.bz2
Option API improvements:
- Better reference usage - Improve const correctness
-rw-r--r--include/core/option.h49
-rw-r--r--src/option.cpp62
2 files changed, 60 insertions, 51 deletions
diff --git a/include/core/option.h b/include/core/option.h
index e603263..0ee362e 100644
--- a/include/core/option.h
+++ b/include/core/option.h
@@ -150,26 +150,35 @@ class CompOption {
static CompOption * findOption (Vector &options, CompString name,
unsigned int *index = NULL);
- static bool getBoolOptionNamed (Vector &options, CompString name,
- bool defaultValue = false);
-
- static int getIntOptionNamed (Vector &options, CompString name,
- int defaultValue = 0);
-
- static float getFloatOptionNamed (Vector &options, CompString name,
- float defaultValue = 0.0);
-
- static CompString getStringOptionNamed (Vector &options,
- CompString name,
- CompString defaultValue = "");
-
- static unsigned short * getColorOptionNamed (Vector &options,
- CompString name,
- unsigned short *defaultValue);
-
- static CompMatch & getMatchOptionNamed (Vector &options,
- CompString name,
- CompMatch &defaultValue);
+ static bool
+ getBoolOptionNamed (const Vector& options,
+ const CompString& name,
+ bool defaultValue = false);
+
+ static int
+ getIntOptionNamed (const Vector& options,
+ const CompString& name,
+ int defaultValue = 0);
+
+ static float
+ getFloatOptionNamed (const Vector& options,
+ const CompString& name,
+ const float& defaultValue = 0.0);
+
+ static CompString
+ getStringOptionNamed (const Vector& options,
+ const CompString& name,
+ const CompString& defaultValue = "");
+
+ static unsigned short *
+ getColorOptionNamed (const Vector& options,
+ const CompString& name,
+ unsigned short *defaultValue);
+
+ static CompMatch
+ getMatchOptionNamed (const Vector& options,
+ const CompString& name,
+ const CompMatch& defaultValue);
static CompString typeToString (Type type);
diff --git a/src/option.cpp b/src/option.cpp
index 9739ab8..66b76cb 100644
--- a/src/option.cpp
+++ b/src/option.cpp
@@ -672,24 +672,24 @@ CompOption::operator= (const CompOption &option)
bool
-CompOption::getBoolOptionNamed (Vector &options, CompString name,
- bool defaultValue)
+CompOption::getBoolOptionNamed (const Vector& options,
+ const CompString& name,
+ bool defaultValue)
{
- foreach (CompOption &o, options)
- if (o.priv->type == CompOption::TypeBool &&
- o.priv->name.compare(name) == 0)
+ foreach (const CompOption &o, options)
+ if (o.priv->type == CompOption::TypeBool && o.priv->name == name)
return o.priv->value.b ();
return defaultValue;
}
int
-CompOption::getIntOptionNamed (Vector &options, CompString name,
- int defaultValue)
+CompOption::getIntOptionNamed (const Vector& options,
+ const CompString& name,
+ int defaultValue)
{
- foreach (CompOption &o, options)
- if (o.priv->type == CompOption::TypeInt &&
- o.priv->name.compare(name) == 0)
+ foreach (const CompOption &o, options)
+ if (o.priv->type == CompOption::TypeInt && o.priv->name == name)
return o.priv->value.i ();
return defaultValue;
@@ -697,12 +697,12 @@ CompOption::getIntOptionNamed (Vector &options, CompString name,
float
-CompOption::getFloatOptionNamed (Vector &options, CompString name,
- float defaultValue)
+CompOption::getFloatOptionNamed (const Vector& options,
+ const CompString& name,
+ const float& defaultValue)
{
- foreach (CompOption &o, options)
- if (o.priv->type == CompOption::TypeFloat &&
- o.priv->name.compare(name) == 0)
+ foreach (const CompOption &o, options)
+ if (o.priv->type == CompOption::TypeFloat && o.priv->name == name)
return o.priv->value.f ();
return defaultValue;
@@ -710,12 +710,12 @@ CompOption::getFloatOptionNamed (Vector &options, CompString name,
CompString
-CompOption::getStringOptionNamed (Vector &options, CompString name,
- CompString defaultValue)
+CompOption::getStringOptionNamed (const Vector& options,
+ const CompString& name,
+ const CompString& defaultValue)
{
- foreach (CompOption &o, options)
- if (o.priv->type == CompOption::TypeString &&
- o.priv->name.compare(name) == 0)
+ foreach (const CompOption &o, options)
+ if (o.priv->type == CompOption::TypeString && o.priv->name == name)
return o.priv->value.s ();
return defaultValue;
@@ -723,25 +723,25 @@ CompOption::getStringOptionNamed (Vector &options, CompString name,
unsigned short *
-CompOption::getColorOptionNamed (Vector &options, CompString name,
- unsigned short *defaultValue)
+CompOption::getColorOptionNamed (const Vector& options,
+ const CompString& name,
+ unsigned short *defaultValue)
{
- foreach (CompOption &o, options)
- if (o.priv->type == CompOption::TypeColor &&
- o.priv->name.compare(name) == 0)
+ foreach (const CompOption &o, options)
+ if (o.priv->type == CompOption::TypeColor && o.priv->name == name)
return o.priv->value.c ();
return defaultValue;
}
-CompMatch &
-CompOption::getMatchOptionNamed (Vector &options, CompString name,
- CompMatch &defaultValue)
+CompMatch
+CompOption::getMatchOptionNamed (const Vector& options,
+ const CompString& name,
+ const CompMatch& defaultValue)
{
- foreach (CompOption &o, options)
- if (o.priv->type == CompOption::TypeMatch &&
- o.priv->name.compare(name) == 0)
+ foreach (const CompOption &o, options)
+ if (o.priv->type == CompOption::TypeMatch && o.priv->name == name)
return o.priv->value.match ();
return defaultValue;