summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2009-03-01 12:03:11 +0100
committerDanny Baumann <dannybaumann@web.de>2009-03-01 12:03:11 +0100
commit2b4e5bd3bb99506930ee6ebf2177a9fa494d53c9 (patch)
tree8bab0ea8c0a3438bce280b835ddcbf59ada73f14
parentdca84f09b862d8a5bcbff585b66255894ed79cf7 (diff)
downloadmobilebling-2b4e5bd3bb99506930ee6ebf2177a9fa494d53c9.tar.gz
mobilebling-2b4e5bd3bb99506930ee6ebf2177a9fa494d53c9.tar.bz2
Distinguish between unset and not matching option type.
-rw-r--r--include/core/option.h4
-rw-r--r--src/option.cpp73
-rw-r--r--src/privateoption.h3
3 files changed, 40 insertions, 40 deletions
diff --git a/include/core/option.h b/include/core/option.h
index d288496..d058755 100644
--- a/include/core/option.h
+++ b/include/core/option.h
@@ -53,7 +53,9 @@ class CompOption {
TypeEdge,
TypeBell,
TypeMatch,
- TypeList
+ TypeList,
+ /* internal use only */
+ TypeUnset
} Type;
class Value {
diff --git a/src/option.cpp b/src/option.cpp
index 784e884..0140812 100644
--- a/src/option.cpp
+++ b/src/option.cpp
@@ -205,12 +205,8 @@ checkIsAction (CompOption::Type type)
bool
CompOption::Value::b ()
{
- if (priv->type != CompOption::TypeBool)
- {
- compLogMessage("core", CompLogLevelWarn,
- "CompOption::Value not a bool");
+ if (!priv->checkType (CompOption::TypeBool))
return false;
- }
return priv->value.b;
}
@@ -218,12 +214,8 @@ CompOption::Value::b ()
int
CompOption::Value::i ()
{
- if (priv->type != CompOption::TypeInt)
- {
- compLogMessage("core", CompLogLevelWarn,
- "CompOption::Value not an int");
+ if (!priv->checkType (CompOption::TypeInt))
return 0;
- }
return priv->value.i;
}
@@ -231,12 +223,8 @@ CompOption::Value::i ()
float
CompOption::Value::f ()
{
- if (priv->type != CompOption::TypeFloat)
- {
- compLogMessage("core", CompLogLevelWarn,
- "CompOption::Value not a float");
+ if (!priv->checkType (CompOption::TypeFloat))
return 0.0;
- }
return priv->value.f;
}
@@ -246,12 +234,8 @@ static unsigned short defaultColor[4] = { 0x0, 0x0, 0x0, 0xffff};
unsigned short *
CompOption::Value::c ()
{
- if (priv->type != CompOption::TypeColor)
- {
- compLogMessage("core", CompLogLevelWarn,
- "CompOption::Value not a color");
+ if (!priv->checkType (CompOption::TypeColor))
return reinterpret_cast<unsigned short *> (defaultColor);
- }
return priv->value.c;
}
@@ -259,12 +243,8 @@ CompOption::Value::c ()
CompString
CompOption::Value::s ()
{
- if (priv->type != CompOption::TypeString)
- {
- compLogMessage("core", CompLogLevelWarn,
- "CompOption::Value not a string");
+ if (!priv->checkType (CompOption::TypeString))
return "";
- }
return priv->string;
}
@@ -272,9 +252,7 @@ CompOption::Value::s ()
CompMatch &
CompOption::Value::match ()
{
- if (priv->type != CompOption::TypeMatch)
- compLogMessage("core", CompLogLevelWarn,
- "CompOption::Value not a match");
+ priv->checkType (CompOption::TypeMatch);
return priv->match;
}
@@ -282,7 +260,9 @@ CompOption::Value::match ()
CompAction &
CompOption::Value::action ()
{
- if (!checkIsAction(priv->type))
+ priv->checkType (priv->type);
+
+ if (!checkIsAction (priv->type))
compLogMessage("core", CompLogLevelWarn,
"CompOption::Value not an action");
@@ -292,9 +272,7 @@ CompOption::Value::action ()
CompOption::Type
CompOption::Value::listType ()
{
- if (priv->type != CompOption::TypeList)
- compLogMessage("core", CompLogLevelWarn,
- "CompOption::Value not a list");
+ priv->checkType (CompOption::TypeList);
return priv->listType;
}
@@ -302,9 +280,7 @@ CompOption::Value::listType ()
CompOption::Value::Vector &
CompOption::Value::list ()
{
- if (priv->type != CompOption::TypeList)
- compLogMessage("core", CompLogLevelWarn,
- "CompOption::Value not a list");
+ priv->checkType (CompOption::TypeList);
return priv->list;
}
@@ -435,11 +411,11 @@ CompOption::Value::operator= (const CompOption::Value &val)
}
PrivateValue::PrivateValue () :
- type (CompOption::TypeBool),
+ type (CompOption::TypeUnset),
string (""),
action (),
match (),
- listType (CompOption::TypeBool),
+ listType (CompOption::TypeUnset),
list ()
{
memset (&value, 0, sizeof (ValueUnion));
@@ -456,6 +432,27 @@ PrivateValue::PrivateValue (const PrivateValue& p) :
memcpy (&value, &p.value, sizeof (ValueUnion));
}
+bool
+PrivateValue::checkType (CompOption::Type refType)
+{
+ if (type == CompOption::TypeUnset)
+ {
+ compLogMessage ("core", CompLogLevelWarn,
+ "Value type is not yet set");
+ return false;
+ }
+
+ if (type != refType)
+ {
+ compLogMessage ("core", CompLogLevelWarn,
+ "Value type does not match (is %d, expected %d)",
+ type, refType);
+ return false;
+ }
+
+ return true;
+}
+
void
PrivateValue::reset ()
{
@@ -925,7 +922,7 @@ CompOption::setOption (CompOption &o,
PrivateOption::PrivateOption () :
name (""),
- type (CompOption::TypeBool),
+ type (CompOption::TypeUnset),
value (),
rest ()
{
diff --git a/src/privateoption.h b/src/privateoption.h
index b65614b..fb74280 100644
--- a/src/privateoption.h
+++ b/src/privateoption.h
@@ -69,7 +69,8 @@ class PrivateValue {
PrivateValue (const PrivateValue&);
void reset ();
-
+ bool checkType (CompOption::Type refType);
+
CompOption::Type type;
ValueUnion value;
CompString string;