Commit b52ce7a0 authored by Jonas Stienen's avatar Jonas Stienen
Browse files

Linux compat test (template problems). and style.

parent 423a7ff5
......@@ -17,7 +17,7 @@
class CVAMotionState;
//! Sleep function
void VASleep(int iMilliseconds);
void VASleep( int iMilliseconds );
//! Identitt (ID) des aktuellen Threads zurckgeben
long getCurrentThreadID();
......@@ -29,10 +29,10 @@ CVAException getDefaultUnexpectedVAException();
float getCurrentProcessSystemLoad();
//! ITAException in eine CVAException konvertieren
CVAException convert2VAException(const ITAException& e);
CVAException convert2VAException( const ITAException& e );
//! VistaExceptionBase in eine CVAException konvertieren
CVAException convert2VAException(const VistaExceptionBase& e);
CVAException convert2VAException( const VistaExceptionBase& e );
//! Yaw-Pitch-Roll angle orientation to View-Up-Vector conversion (angles in radiants)
void ConvertYPR2VU_RAD( const VAOrientYPR& oOrientYPRRAD, VAVec3& vView, VAVec3& vUp );
......@@ -53,28 +53,32 @@ double GetAzimuthOnTarget_DEG( const VAVec3& vOriginPos, const VAVec3& vView, co
double GetElevationOnTarget_DEG( const VAVec3& vOriginPos, const VAVec3& vView, const VAVec3& vUp, const VAVec3& vTargetPos );
//! Ersetzt Backslashes (bzw. PATH_SEPARATOR) durch doppelte Backslashes (bzw. PATH_SEPARATOR)
std::string correctPathForLUA(const std::string& sPath);
std::string correctPathForLUA( const std::string& sPath );
//! Lies eine INI-Datei ein und gibt sie als VAStruct zurck
void readINIFileAsStruct(const std::string& sFilename, CVAStruct& oData);
void readINIFileAsStruct( const std::string& sFilename, CVAStruct& oData );
//! Sets all motion related parameters in a core event based on a motion event
void SetCoreEventParams(CVACoreEvent& oEvent, const CVAMotionState* pMotionState);
void SetCoreEventParams( CVACoreEvent& oEvent, const CVAMotionState* pMotionState );
//! Case-insensitive literals
template <class T> class CVALiterals {
template< class T > class CVALiterals
{
public:
void Add(const std::string& sLiteral, const T& value) {
m_mLiterals.insert( std::pair<std::string, T>(toUppercase(sLiteral), value) );
}
inline void Add( const std::string& sLiteral, const T& value )
{
m_mLiterals.insert( std::pair< std::string, T >( toUppercase( sLiteral ), value ) );
};
bool Translate(const std::string& s, T& dest) const {
std::string t = toUppercase( stripSpaces(s) );
std::map<std::string, T>::const_iterator it = m_mLiterals.find(t);
if (it == m_mLiterals.end()) return false;
inline bool Translate( const std::string& s, T& dest ) const
{
std::string t = toUppercase( stripSpaces( s ) );
std::map< std::string, T >::const_iterator it = m_mLiterals.find( t );
if( it == m_mLiterals.end() )
return false;
dest = it->second;
return true;
}
};
private:
std::map<std::string, T> m_mLiterals;
......@@ -97,7 +101,7 @@ public:
// Customize to your needs
inline virtual void SetErrorPrefix( const std::string& sPrefix )
{
if (sPrefix.empty())
if( sPrefix.empty() )
m_sErrorPrefix = "";
else
m_sErrorPrefix = sPrefix + ": ";
......@@ -107,24 +111,24 @@ public:
// Customize to your needs
inline virtual void Error( const std::string& sErrorMessage ) const
{
VA_EXCEPT1(m_sErrorPrefix + sErrorMessage);
VA_EXCEPT1( m_sErrorPrefix + sErrorMessage );
}
// --= Error messages =--
inline void ErrorMissKey( const std::string& sKey ) const
{
Error(std::string("Missing a key \"") + sKey + std::string("\""));
Error( std::string( "Missing a key \"" ) + sKey + std::string( "\"" ) );
}
inline void ErrorWrongType( const std::string& sKey, const std::string& sType ) const
{
Error(std::string("Key \"") + sKey + std::string("\" must be ") + sType);
Error( std::string( "Key \"" ) + sKey + std::string( "\" must be " ) + sType );
}
inline void ErrorEmptyKey( const std::string& sKey ) const
{
Error(std::string("Key \"") + sKey + std::string("\" must not be empty"));
Error( std::string( "Key \"" ) + sKey + std::string( "\" must not be empty" ) );
}
// --= Sub groups =--
......@@ -132,11 +136,11 @@ public:
// Semantic: check HasKey(s) && IsStruct(s)
inline const CVAStruct& ReqStruct( const std::string& sStructName ) const
{
if (!m_oStruct.HasKey(sStructName)) ErrorMissKey(sStructName);
const CVAStructValue& oKey = m_oStruct[sStructName];
if (!oKey.IsStruct()) ErrorWrongType(sStructName, "a struct");
if( !m_oStruct.HasKey( sStructName ) ) ErrorMissKey( sStructName );
const CVAStructValue& oKey = m_oStruct[ sStructName ];
if( !oKey.IsStruct() ) ErrorWrongType( sStructName, "a struct" );
return oKey;
}
......@@ -144,11 +148,12 @@ public:
// Info: If no key exists, an empty struct is returned
inline const CVAStruct& OptStruct( const std::string& sStructName ) const
{
if (m_oStruct.HasKey(sStructName)) {
const CVAStructValue& oValue = m_oStruct[sStructName];
if (!oValue.IsStruct()) ErrorWrongType(sStructName, "a struct");
if( m_oStruct.HasKey( sStructName ) ) {
const CVAStructValue& oValue = m_oStruct[ sStructName ];
if( !oValue.IsStruct() ) ErrorWrongType( sStructName, "a struct" );
return oValue;
} else {
}
else {
// Group does not exist => return empty struct
return g_oEmptyStruct;
}
......@@ -158,101 +163,103 @@ public:
inline void ReqBool( const std::string& sKey, bool& bValue, const CVALiterals<bool>* pLiterals = nullptr ) const
{
const CVAStructValue* pValue = m_oStruct.GetValue(sKey);
const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if (!pValue) ErrorMissKey(sKey);
if( !pValue ) ErrorMissKey( sKey );
if (pValue->IsBool()) {
if( pValue->IsBool() ) {
bValue = *pValue;
return;
}
if (pValue->IsString()) {
if( pValue->IsString() ) {
// Try to translate literals
if (pLiterals && pLiterals->Translate(*pValue, bValue)) return;
if( pLiterals && pLiterals->Translate( *pValue, bValue ) ) return;
// Try to convert implicitly
try {
bValue = *pValue;
return;
} catch (...) {}
}
catch( ... ) {}
}
ErrorWrongType(sKey, "boolean");
ErrorWrongType( sKey, "boolean" );
};
inline bool OptBool( const std::string& sKey, bool& bValue, bool bDefault, const CVALiterals<bool>* pLiterals = nullptr ) const
{
const CVAStructValue* pValue = m_oStruct.GetValue(sKey);
const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if (!pValue) {
if( !pValue ) {
bValue = bDefault;
return false;
}
if (pValue->IsBool()) {
if( pValue->IsBool() ) {
bValue = *pValue;
return true;
}
if (pValue->IsString()) {
if( pValue->IsString() ) {
// Try to translate literals
if (pLiterals && pLiterals->Translate(*pValue, bValue)) return true;
if( pLiterals && pLiterals->Translate( *pValue, bValue ) ) return true;
// Try to convert implicitly
try {
bValue = *pValue;
return true;
} catch (...) {
}
catch( ... ) {
}
}
ErrorWrongType(sKey, "boolean");
ErrorWrongType( sKey, "boolean" );
return false;
}
// --= Strings =--
// Gets a mandatory string value. An exception is thrown if it does not exist
inline void ReqString( const std::string& sKey, std::string& sValue ) const
{
const CVAStructValue* pValue = m_oStruct.GetValue(sKey);
if (!pValue) ErrorMissKey(sKey);
const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if( !pValue ) ErrorMissKey( sKey );
// Allows implicit type conversions
if (pValue->IsBool() || pValue->IsNumeric() || pValue->IsString()) {
if( pValue->IsBool() || pValue->IsNumeric() || pValue->IsString() ) {
sValue = *pValue;
return;
}
ErrorWrongType(sKey, "a string");
ErrorWrongType( sKey, "a string" );
}
// Gets an Optional string value. A default value set if it does not exist
// Return value: Key exists?
inline bool OptString( const std::string& sKey, std::string& sValue, const std::string& sDefault = "" ) const
{
const CVAStructValue* pValue = m_oStruct.GetValue(sKey);
if (!pValue) {
const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if( !pValue ) {
sValue = sDefault;
return false;
}
// Allows implicit type conversions
if (pValue->IsBool() || pValue->IsNumeric() || pValue->IsString()) {
if( pValue->IsBool() || pValue->IsNumeric() || pValue->IsString() ) {
sValue = *pValue;
return true;
}
ErrorWrongType(sKey, "a string");
ErrorWrongType( sKey, "a string" );
return false;
}
// Like ReqString(...), but checks that the string is non-empty
inline void ReqNonEmptyString( const std::string& sKey, std::string& sValue ) const
{
ReqString(sKey, sValue);
if (sValue.empty()) ErrorEmptyKey(sKey);
ReqString( sKey, sValue );
if( sValue.empty() ) ErrorEmptyKey( sKey );
}
// Like OptString(...), but checks that the string is non-empty
......@@ -268,34 +275,35 @@ public:
inline void ReqInteger( const std::string& sKey, int& iValue, const CVALiterals<int>* pLiterals = nullptr ) const
{
const CVAStructValue* pValue = m_oStruct.GetValue(sKey);
const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if (!pValue) ErrorMissKey(sKey);
if( !pValue ) ErrorMissKey( sKey );
if (pValue->IsInt()) {
if( pValue->IsInt() ) {
iValue = *pValue;
return;
}
if (pValue->IsString()) {
if( pValue->IsString() ) {
// Try to translate literals
if (pLiterals && pLiterals->Translate(*pValue, iValue)) return;
if( pLiterals && pLiterals->Translate( *pValue, iValue ) ) return;
// Try to convert implicitly
try {
iValue = *pValue;
return;
} catch (...) {}
}
catch( ... ) {}
}
ErrorWrongType(sKey, "an integer number");
ErrorWrongType( sKey, "an integer number" );
};
inline bool OptInteger( const std::string& sKey, int& iValue, int iDefault, const CVALiterals<int>* pLiterals = nullptr ) const
{
const CVAStructValue* pValue = m_oStruct.GetValue(sKey);
const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if (!pValue) {
if( !pValue ) {
iValue = iDefault;
return false;
}
......@@ -306,80 +314,83 @@ public:
return true;
}
if (pValue->IsInt()) {
if( pValue->IsInt() ) {
iValue = *pValue;
return true;
}
if (pValue->IsString()) {
if( pValue->IsString() ) {
// Try to translate literals
if (pLiterals && pLiterals->Translate(*pValue, iValue)) return true;
if( pLiterals && pLiterals->Translate( *pValue, iValue ) ) return true;
// Try to convert implicitly
try {
iValue = *pValue;
return true;
} catch (...) {}
}
catch( ... ) {}
}
ErrorWrongType(sKey, "an integer number");
ErrorWrongType( sKey, "an integer number" );
return false;
}
// --= Numbers (floating point) =--
inline void ReqNumber( const std::string& sKey, double& dValue, const CVALiterals<double>* pLiterals = nullptr ) const
{
const CVAStructValue* pValue = m_oStruct.GetValue(sKey);
const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if (!pValue) ErrorMissKey(sKey);
if( !pValue ) ErrorMissKey( sKey );
if (pValue->IsNumeric()) {
if( pValue->IsNumeric() ) {
dValue = *pValue;
return;
}
if (pValue->IsString()) {
if( pValue->IsString() ) {
// Try to translate literals
if (pLiterals && pLiterals->Translate(*pValue, dValue)) return;
if( pLiterals && pLiterals->Translate( *pValue, dValue ) ) return;
// Try to convert implicitly
try {
dValue = *pValue;
return;
} catch (...) {}
}
catch( ... ) {}
}
ErrorWrongType(sKey, "a number");
ErrorWrongType( sKey, "a number" );
}
inline bool OptNumber( const std::string& sKey, double& dValue, double dDefault, const CVALiterals<double>* pLiterals = nullptr ) const
{
const CVAStructValue* pValue = m_oStruct.GetValue(sKey);
const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if (!pValue) {
if( !pValue ) {
dValue = dDefault;
return false;
}
if (pValue->IsNumeric()) {
if( pValue->IsNumeric() ) {
dValue = *pValue;
return true;
}
if (pValue->IsString()) {
if( pValue->IsString() ) {
// Try to translate literals
if (pLiterals && pLiterals->Translate(*pValue, dValue)) return true;
if( pLiterals && pLiterals->Translate( *pValue, dValue ) ) return true;
// Try to convert implicitly
try {
dValue = *pValue;
return true;
} catch (...) {}
}
catch( ... ) {}
}
ErrorWrongType(sKey, "a number");
ErrorWrongType( sKey, "a number" );
return false;
}
......@@ -389,51 +400,51 @@ public:
// Gets a mandatory list of strings value. An exception is thrown if it does not exist
inline void ReqStringList( const std::string& sKey, std::vector< std::string >& vList, const std::string& sSeparator = "," ) const
{
const CVAStructValue* pValue = m_oStruct.GetValue(sKey);
const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if (!pValue) ErrorMissKey(sKey);
if( !pValue ) ErrorMissKey( sKey );
// Default case
if (pValue->IsString()) {
if( pValue->IsString() ) {
std::string sValue = *pValue;
vList = splitString(sValue, sSeparator);
vList = splitString( sValue, sSeparator );
return;
}
// Allows implicit type conversions
if (pValue->IsBool() || pValue->IsNumeric()) {
if( pValue->IsBool() || pValue->IsNumeric() ) {
std::string sValue = *pValue;
vList.clear();
vList.push_back(sValue);
vList.push_back( sValue );
return;
}
ErrorWrongType(sKey, "a string");
ErrorWrongType( sKey, "a string" );
}
// Gets a mandatory list of strings value. An exception is thrown if it does not exist
inline void ReqStringListRegex( const std::string& sKey, std::vector< std::string >& vList, const std::string& sRegex ) const
{
const CVAStructValue* pValue = m_oStruct.GetValue(sKey);
const CVAStructValue* pValue = m_oStruct.GetValue( sKey );
if (!pValue) ErrorMissKey(sKey);
if( !pValue ) ErrorMissKey( sKey );
// Default case
if (pValue->IsString()) {
if( pValue->IsString() ) {
std::string sValue = *pValue;
regexSplitString(sValue, vList, sRegex);
regexSplitString( sValue, vList, sRegex );
return;
}
// Allows implicit type conversions
if (pValue->IsBool() || pValue->IsNumeric()) {
if( pValue->IsBool() || pValue->IsNumeric() ) {
std::string sValue = *pValue;
vList.clear();
vList.push_back(sValue);
vList.push_back( sValue );
return;
}
ErrorWrongType(sKey, "a string");
ErrorWrongType( sKey, "a string" );
}
private:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment