[Orxonox-commit 6351] r11008 - code/branches/cpp11_v2/src/libraries/util
landauf at orxonox.net
landauf at orxonox.net
Thu Dec 31 01:04:04 CET 2015
Author: landauf
Date: 2015-12-31 01:04:04 +0100 (Thu, 31 Dec 2015)
New Revision: 11008
Modified:
code/branches/cpp11_v2/src/libraries/util/MultiType.cc
code/branches/cpp11_v2/src/libraries/util/MultiType.h
code/branches/cpp11_v2/src/libraries/util/MultiTypeValue.h
code/branches/cpp11_v2/src/libraries/util/SubString.cc
code/branches/cpp11_v2/src/libraries/util/SubString.h
Log:
and finally some strongly typed enums in util.
Modified: code/branches/cpp11_v2/src/libraries/util/MultiType.cc
===================================================================
--- code/branches/cpp11_v2/src/libraries/util/MultiType.cc 2015-12-30 23:43:34 UTC (rev 11007)
+++ code/branches/cpp11_v2/src/libraries/util/MultiType.cc 2015-12-31 00:04:04 UTC (rev 11008)
@@ -42,7 +42,7 @@
@brief Converts the current value of the MultiType to a new type.
@param type The type
*/
- bool MultiType::convert(Type::Enum type)
+ bool MultiType::convert(Type type)
{
switch (type)
{
@@ -105,7 +105,7 @@
*/
std::string MultiType::getTypename() const
{
- Type::Enum type = (this->value_) ? this->value_->type_ : Type::Null;
+ Type type = (this->value_) ? this->value_->type_ : Type::Null;
switch (type)
{
Modified: code/branches/cpp11_v2/src/libraries/util/MultiType.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/util/MultiType.h 2015-12-30 23:43:34 UTC (rev 11007)
+++ code/branches/cpp11_v2/src/libraries/util/MultiType.h 2015-12-31 00:04:04 UTC (rev 11008)
@@ -131,38 +131,35 @@
_UtilExport friend std::ostream& operator<<(std::ostream& outstream, const MultiType& mt);
template <typename T> friend class MT_Value;
- struct Type
+ /**
+ @brief Enum of all possible types of a MultiType.
+ */
+ enum class Type : uint8_t
{
- /**
- @brief Enum of all possible types of a MultiType.
- */
- enum Enum
- {
- Null,
- Char,
- UnsignedChar,
- Short,
- UnsignedShort,
- Int,
- UnsignedInt,
- Long,
- UnsignedLong,
- LongLong,
- UnsignedLongLong,
- Float,
- Double,
- LongDouble,
- Bool,
- VoidPointer,
- String,
- Vector2,
- Vector3,
- Vector4,
- ColourValue,
- Quaternion,
- Radian,
- Degree
- };
+ Null,
+ Char,
+ UnsignedChar,
+ Short,
+ UnsignedShort,
+ Int,
+ UnsignedInt,
+ Long,
+ UnsignedLong,
+ LongLong,
+ UnsignedLongLong,
+ Float,
+ Double,
+ LongDouble,
+ Bool,
+ VoidPointer,
+ String,
+ Vector2,
+ Vector3,
+ Vector4,
+ ColourValue,
+ Quaternion,
+ Radian,
+ Degree
};
public:
@@ -173,7 +170,7 @@
class _UtilExport MT_ValueBase
{
public:
- inline MT_ValueBase(void* data, Type::Enum type) : type_(type), bLastConversionSuccessful(true), data_(data) {}
+ inline MT_ValueBase(void* data, Type type) : type_(type), bLastConversionSuccessful(true), data_(data) {}
virtual inline ~MT_ValueBase() {}
virtual MT_ValueBase* clone() const = 0;
@@ -181,7 +178,7 @@
virtual void reset() = 0;
/// Returns the type of the current value.
- inline const Type::Enum& getType() const { return this->type_; }
+ inline const Type& getType() const { return this->type_; }
/// Returns true if the type of the stored value is T. Note: the actual implementations for all supported types are defined outside of the class.
template <typename T> /* for normal classes */ typename std::enable_if<!std::is_enum<T>::value, bool>::type
@@ -297,7 +294,7 @@
virtual void exportData(uint8_t*& mem) const = 0;
virtual uint8_t getSize() const = 0;
- Type::Enum type_; ///< The type of the current value
+ Type type_; ///< The type of the current value
bool bLastConversionSuccessful; ///< True if the last conversion was successful
void* data_; ///< For direct access to the value if the type is known
};
@@ -408,16 +405,16 @@
/// Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT
inline void exportData(uint8_t*& mem) const
{
- assert(sizeof(Type::Enum) <= 8);
- *static_cast<uint8_t*>(mem) = this->getType();
+ assert(sizeof(Type) <= 8);
+ *static_cast<uint8_t*>(mem) = static_cast<uint8_t>(this->getType());
mem += sizeof(uint8_t);
this->value_->exportData(mem);
}
/// Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT
inline void importData(uint8_t*& mem)
{
- assert(sizeof(Type::Enum) <= 8);
- this->setType(static_cast<Type::Enum>(*static_cast<uint8_t*>(mem)));
+ assert(sizeof(Type) <= 8);
+ this->setType(static_cast<Type>(*static_cast<uint8_t*>(mem)));
mem += sizeof(uint8_t);
this->value_->importData(mem);
}
@@ -457,11 +454,11 @@
}
/// Resets the value and changes the internal type to the given type.
- inline void setType(Type::Enum type) { this->reset(); this->convert(type); this->resetValue(); }
+ inline void setType(Type type) { this->reset(); this->convert(type); this->resetValue(); }
/// Returns the current type.
- inline Type::Enum getType() const { return (this->value_) ? this->value_->type_ : Type::Null; }
+ inline Type getType() const { return (this->value_) ? this->value_->type_ : Type::Null; }
/// Converts the current value to the given type.
- bool convert(Type::Enum type);
+ bool convert(Type type);
/// Changes the value container.
template <typename T> inline void changeValueContainer(const T& value)
Modified: code/branches/cpp11_v2/src/libraries/util/MultiTypeValue.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/util/MultiTypeValue.h 2015-12-30 23:43:34 UTC (rev 11007)
+++ code/branches/cpp11_v2/src/libraries/util/MultiTypeValue.h 2015-12-31 00:04:04 UTC (rev 11008)
@@ -54,7 +54,7 @@
{
public:
/// Constructor: Assigns the value and the type identifier.
- MT_Value(const T& value, MultiType::Type::Enum type) : MT_ValueBase(&this->value_, type), value_(value) {}
+ MT_Value(const T& value, MultiType::Type type) : MT_ValueBase(&this->value_, type), value_(value) {}
/// Creates a copy of itself.
virtual inline MT_ValueBase* clone() const override { return new MT_Value<T>(this->value_, this->type_); }
Modified: code/branches/cpp11_v2/src/libraries/util/SubString.cc
===================================================================
--- code/branches/cpp11_v2/src/libraries/util/SubString.cc 2015-12-30 23:43:34 UTC (rev 11007)
+++ code/branches/cpp11_v2/src/libraries/util/SubString.cc 2015-12-31 00:04:04 UTC (rev 11008)
@@ -264,12 +264,12 @@
std::string token;
bool inSafemode = false;
- if(start_state != SL_NORMAL && tokens.size() > 0)
+ if(start_state != SPLIT_LINE_STATE::NORMAL && tokens.size() > 0)
{
token = tokens[tokens.size()-1];
tokens.pop_back();
}
- if(start_state != SL_NORMAL && bTokenInSafemode.size() > 0)
+ if(start_state != SPLIT_LINE_STATE::NORMAL && bTokenInSafemode.size() > 0)
{
inSafemode = bTokenInSafemode[bTokenInSafemode.size()-1];
bTokenInSafemode.pop_back();
@@ -279,17 +279,17 @@
{
switch(state)
{
- case SL_NORMAL:
+ case SPLIT_LINE_STATE::NORMAL:
if(line[i] == escapeChar)
{
- state = SL_ESCAPE;
+ state = SPLIT_LINE_STATE::ESCAPE;
if (!bRemoveEscapeChar)
token += line[i];
fallBackNeighbours = 0;
}
else if(line[i] == safemodeChar)
{
- state = SL_SAFEMODE;
+ state = SPLIT_LINE_STATE::SAFEMODE;
inSafemode = true;
if (!bRemoveSafemodeChar)
token += line[i];
@@ -297,7 +297,7 @@
}
else if(line[i] == openparenthesisChar)
{
- state = SL_PARENTHESES;
+ state = SPLIT_LINE_STATE::PARENTHESES;
inSafemode = true;
if (!bRemoveParenthesisChars)
token += line[i];
@@ -317,7 +317,7 @@
inSafemode = false;
}
token += line[i]; // EAT
- state = SL_COMMENT;
+ state = SPLIT_LINE_STATE::COMMENT;
}
else if(delimiters.find(line[i]) != std::string::npos)
{
@@ -333,7 +333,7 @@
bTokenInSafemode.push_back(inSafemode);
inSafemode = false;
}
- state = SL_NORMAL;
+ state = SPLIT_LINE_STATE::NORMAL;
}
else
{
@@ -352,7 +352,7 @@
token += line[i]; // EAT
}
break;
- case SL_ESCAPE:
+ case SPLIT_LINE_STATE::ESCAPE:
if (!bRemoveSafemodeChar)
token += line[i];
else
@@ -367,18 +367,18 @@
else if(line[i] == '?') token += '\?';
else token += line[i]; // EAT
}
- state = SL_NORMAL;
+ state = SPLIT_LINE_STATE::NORMAL;
break;
- case SL_SAFEMODE:
+ case SPLIT_LINE_STATE::SAFEMODE:
if(line[i] == safemodeChar)
{
- state = SL_NORMAL;
+ state = SPLIT_LINE_STATE::NORMAL;
if (!bRemoveSafemodeChar)
token += line[i];
}
else if(line[i] == escapeChar)
{
- state = SL_SAFEESCAPE;
+ state = SPLIT_LINE_STATE::SAFEESCAPE;
}
else
{
@@ -386,7 +386,7 @@
}
break;
- case SL_SAFEESCAPE:
+ case SPLIT_LINE_STATE::SAFEESCAPE:
if(line[i] == 'n') token += '\n';
else if(line[i] == 't') token += '\t';
else if(line[i] == 'v') token += '\v';
@@ -396,19 +396,19 @@
else if(line[i] == 'a') token += '\a';
else if(line[i] == '?') token += '\?';
else token += line[i]; // EAT
- state = SL_SAFEMODE;
+ state = SPLIT_LINE_STATE::SAFEMODE;
break;
- case SL_PARENTHESES:
+ case SPLIT_LINE_STATE::PARENTHESES:
if(line[i] == closeparenthesisChar)
{
- state = SL_NORMAL;
+ state = SPLIT_LINE_STATE::NORMAL;
if (!bRemoveParenthesisChars)
token += line[i];
}
else if(line[i] == escapeChar)
{
- state = SL_PARENTHESESESCAPE;
+ state = SPLIT_LINE_STATE::PARENTHESESESCAPE;
}
else
{
@@ -416,7 +416,7 @@
}
break;
- case SL_PARENTHESESESCAPE:
+ case SPLIT_LINE_STATE::PARENTHESESESCAPE:
if(line[i] == 'n') token += '\n';
else if(line[i] == 't') token += '\t';
else if(line[i] == 'v') token += '\v';
@@ -426,10 +426,10 @@
else if(line[i] == 'a') token += '\a';
else if(line[i] == '?') token += '\?';
else token += line[i]; // EAT
- state = SL_PARENTHESES;
+ state = SPLIT_LINE_STATE::PARENTHESES;
break;
- case SL_COMMENT:
+ case SPLIT_LINE_STATE::COMMENT:
if(line[i] == '\n')
{
// FINISH
@@ -440,7 +440,7 @@
bTokenInSafemode.push_back(inSafemode);
inSafemode = false;
}
- state = SL_NORMAL;
+ state = SPLIT_LINE_STATE::NORMAL;
}
else
{
Modified: code/branches/cpp11_v2/src/libraries/util/SubString.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/util/SubString.h 2015-12-30 23:43:34 UTC (rev 11007)
+++ code/branches/cpp11_v2/src/libraries/util/SubString.h 2015-12-31 00:04:04 UTC (rev 11008)
@@ -101,15 +101,15 @@
class _UtilExport SubString
{
/// An enumerator for the internal state of the parser
- enum SPLIT_LINE_STATE
+ enum class SPLIT_LINE_STATE
{
- SL_NORMAL, //!< Normal state
- SL_ESCAPE, //!< After an escape character
- SL_SAFEMODE, //!< In safe mode (usually between quotation marks).
- SL_SAFEESCAPE, //!< In safe mode with the internal escape character, that escapes even the savemode character.
- SL_COMMENT, //!< In Comment mode.
- SL_PARENTHESES, //!< Between parentheses (usually '{' and '}')
- SL_PARENTHESESESCAPE, //!< Between parentheses with the internal escape character, that escapes even the closing parenthesis character.
+ NORMAL, //!< Normal state
+ ESCAPE, //!< After an escape character
+ SAFEMODE, //!< In safe mode (usually between quotation marks).
+ SAFEESCAPE, //!< In safe mode with the internal escape character, that escapes even the savemode character.
+ COMMENT, //!< In Comment mode.
+ PARENTHESES, //!< Between parentheses (usually '{' and '}')
+ PARENTHESESESCAPE, //!< Between parentheses with the internal escape character, that escapes even the closing parenthesis character.
};
public:
@@ -203,7 +203,7 @@
char closeparenthesisChar = '}',
bool bRemoveParenthesisChars = true,
char commentChar = '\0',
- SPLIT_LINE_STATE start_state = SL_NORMAL);
+ SPLIT_LINE_STATE start_state = SPLIT_LINE_STATE::NORMAL);
std::vector<std::string> tokens_; ///< The tokens after splitting the input line
std::vector<bool> bTokenInSafemode_; ///< Saves for each token if it was in safe mode (between quotation marks or parenthesis)
More information about the Orxonox-commit
mailing list