Commit 44d84fb6 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding VAStruct char* bracket operator support for direct access with text fields, and style

parent 946545dc
......@@ -116,10 +116,12 @@ public:
CVAStructValue* GetValue(const std::string& sPath, char cPathSeparator=DEFAULT_PATH_SEPARATOR);
//! Read-only data access
const CVAStructValue& operator[](const std::string& sKey) const;
const CVAStructValue& operator[](const char* pcKey) const;
inline const CVAStructValue& operator[](const std::string& sKey) const { return (*this)[sKey.c_str()]; };
//! Read/write data access
CVAStructValue& operator[](const std::string& sKey);
CVAStructValue& operator[](const char* pcKey);
inline CVAStructValue& operator[](const std::string& sKey) { return (*this)[sKey.c_str()]; };
//! Assignment
CVAStruct& operator=(const CVAStruct& rhs);
......@@ -224,11 +226,12 @@ public:
//! Read-only data access
// Note: Is applicable only for struct keys
const CVAStructValue& operator[](const std::string& sKey) const;
const CVAStructValue& operator[](const char* pcKey) const;
//! Read/write data access
// Note: Is applicable only for struct keys
CVAStructValue& operator[](const std::string& sKey);
CVAStructValue& operator[](const char* pcKey);
inline CVAStructValue& operator[](const std::string& sKey) { return (*this)[sKey.c_str()]; };
//! Cast to bool operator (required for assignments of the form 'bool = CVAStructKey')
operator bool() const;
......
/*
*
* VVV VVV A
* VVV VVV AAA Virtual Acoustics
* VVV VVV AAA Real-time auralisation for virtual reality
* VVV VVV AAA
* VVVVVV AAA (c) Copyright Institute of Technical Acoustics (ITA)
* VVVV AAA RWTH Aachen University (http://www.akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*
* File: VABaseDefinitions.cpp
*
* Purspose: Global definitions and declarations
*
* Author(s): Frank Wefers (Frank.Wefers@akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*/
// $Id: $
#include <VABaseDefinitions.h>
#include <iostream>
#include <iomanip>
std::ostream& operator<<(std::ostream& os, const VAVec3& oVec) {
std::ostream& operator<<(std::ostream& os, const VAVec3& oVec)
{
return os << std::fixed << std::setprecision(3)
<< "< " << oVec.x << ", " << oVec.y << ", " << oVec.z << " >";
<< "< " << oVec.x << ", " << oVec.y << ", " << oVec.z << " >";
}
std::ostream& operator<<(std::ostream& os, const VAOrientYPR& oOrient) {
std::ostream& operator<<(std::ostream& os, const VAOrientYPR& oOrient)
{
return os << std::fixed << std::setprecision(2)
<< "< " << oOrient.yaw << ", " << oOrient.pitch << ", " << oOrient.roll << " >";
}
/*
*
* VVV VVV A
* VVV VVV AAA Virtual Acoustics
* VVV VVV AAA Real-time auralisation for virtual reality
* VVV VVV AAA
* VVVVVV AAA (c) Copyright Institut fr Technische Akustik (ITA)
* VVVV AAA RWTH Aachen (http://www.akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*
* Datei: VACoreEvent.cpp
*
* Zweck: Basisklasse fr Kern-Nachrichten
*
* Autor(en): Frank Wefers (Frank.Wefers@akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*/
// $Id: VACoreEvent.cpp 4147 2015-08-03 15:45:06Z fwefers $
#include <VACoreEvent.h>
#include <VACore.h>
......
......@@ -2,7 +2,8 @@
#include <sstream>
std::string CVACoreVersionInfo::ToString() const {
std::string CVACoreVersionInfo::ToString() const
{
// Ausgabeformat: "VACore 1.24 [FLAGS] (COMMENT)"
std::stringstream ss;
ss << "VACore " << sVersion;
......
/*
*
* VVV VVV A
* VVV VVV AAA Virtual Acoustics
* VVV VVV AAA Real-time auralisation for virtual reality
* VVV VVV AAA
* VVVVVV AAA (c) Copyright Institut fr Technische Akustik (ITA)
* VVVV AAA RWTH Aachen (http://www.akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*
* Datei: VAEventHandlerGlobalLock.cpp
*
* Zweck: Global synchronization token for event handler operations
*
* Autor(en): Frank Wefers (Frank.Wefers@akustik.rwth-aachen.de
*
* ---------------------------------------------------------------------------------
*/
// $Id: VABaseDefinitions.h 1717 2011-04-04 21:01:04Z fwefers $
#include <VAEventHandlerGlobalLock.h>
// @todo: remove dependency and replace by c++11 std::mutex
#include <VistaInterProcComm/Concurrency/VistaMutex.h>
// Implementation class
class CVAEventHandlerGlobalLockImpl : public IVAEventHandlerGlobalLock {
class CVAEventHandlerGlobalLockImpl : public IVAEventHandlerGlobalLock
{
public:
mutable VistaMutex m_oLock;
void Lock() const { m_oLock.Lock(); }
void Unlock() const { m_oLock.Unlock(); }
inline void Lock() const
{
m_oLock.Lock();
};
inline void Unlock() const
{
m_oLock.Unlock();
};
CVAEventHandlerGlobalLockImpl() {};
~CVAEventHandlerGlobalLockImpl() {};
inline CVAEventHandlerGlobalLockImpl() {};
inline ~CVAEventHandlerGlobalLockImpl() {};
};
// Singleton instance
CVAEventHandlerGlobalLockImpl g_oEventHandlerGlobalLock;
IVAEventHandlerGlobalLock& IVAEventHandlerGlobalLock::GetInstance() {
IVAEventHandlerGlobalLock& IVAEventHandlerGlobalLock::GetInstance()
{
return g_oEventHandlerGlobalLock;
}
......@@ -2,14 +2,14 @@
*
* VVV VVV A
* VVV VVV AAA Virtual Acoustics
* VVV VVV AAA Real-time auralisation for virtual reality
* VVV VVV AAA Real-time auralisation for virtual reality
* VVV VVV AAA
* VVVVVV AAA (c) Copyright Institut fr Technische Akustik (ITA)
* VVVV AAA RWTH Aachen (http://www.akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*
* File: CVAStruct.cpp
* File: CVAStruct.cpp
*
* Purpose: Associative container class
*
......@@ -17,8 +17,8 @@
*
* ---------------------------------------------------------------------------------
*/
// $Id: $
// $Id: $
#include <VAStruct.h>
......@@ -41,7 +41,7 @@ CVAStruct::~CVAStruct() {}
int CVAStruct::Size() const
{
return (int) m_mData.size();
return (int)m_mData.size();
}
bool CVAStruct::IsEmpty() const {
......@@ -69,21 +69,22 @@ CVAStructValue* CVAStruct::Traverse(const std::string& sPath, size_t iPathCursor
// Find next path element
size_t n;
n = sPath.find(cPathSeparator, iPathCursor);
if (n==std::string::npos) {
if (n == std::string::npos) {
// Last element on path
Map::iterator it = m_mData.find(sPath.substr(iPathCursor, sPath.length()-iPathCursor));
Map::iterator it = m_mData.find(sPath.substr(iPathCursor, sPath.length() - iPathCursor));
return (it != m_mData.end() ? &(it->second) : nullptr);
} else {
}
else {
// Next element on path (at least one more follows)
std::string t = sPath.substr(iPathCursor, n-iPathCursor);
std::string t = sPath.substr(iPathCursor, n - iPathCursor);
Map::iterator it = m_mData.find(t);
if (it == m_mData.end()) return nullptr; // Error: Path not found
CVAStructValue& oNode = it->second;
if (!oNode.IsStruct()) return nullptr; // Error: Node is a leaf, paths goes further...
// Traverse into subtree
return oNode.GetStruct().Traverse(sPath, n+1, cPathSeparator);
return oNode.GetStruct().Traverse(sPath, n + 1, cPathSeparator);
}
}
......@@ -91,13 +92,14 @@ const CVAStructValue* CVAStruct::Traverse(const std::string& sPath, size_t iPath
// Find next path element
size_t n;
n = sPath.find(cPathSeparator, iPathCursor);
if (n==std::string::npos) {
if (n == std::string::npos) {
// Last element on path
Map::const_iterator it = m_mData.find(sPath.substr(iPathCursor, sPath.length()-iPathCursor));
Map::const_iterator it = m_mData.find(sPath.substr(iPathCursor, sPath.length() - iPathCursor));
return (it != m_mData.end() ? &(it->second) : nullptr);
} else {
}
else {
// Next element on path (at least one more follows)
std::string t = sPath.substr(iPathCursor, n-iPathCursor);
std::string t = sPath.substr(iPathCursor, n - iPathCursor);
Map::const_iterator it = m_mData.find(t);
if (it == m_mData.end()) return nullptr; // Error: Path not found
......@@ -105,7 +107,7 @@ const CVAStructValue* CVAStruct::Traverse(const std::string& sPath, size_t iPath
if (!oNode.IsStruct()) return nullptr; // Error: Node is a leaf, paths goes further...
// Traverse into subtree
return oNode.GetStruct().Traverse(sPath, n+1, cPathSeparator);
return oNode.GetStruct().Traverse(sPath, n + 1, cPathSeparator);
}
}
......@@ -119,26 +121,27 @@ CVAStructValue* CVAStruct::GetValue(const std::string& sPath, char cPathSeparato
return Traverse(sPath, 0, cPathSeparator);
}
const CVAStructValue& CVAStruct::operator[](const std::string& sKey) const {
const CVAStructValue& CVAStruct::operator[](const char* pcKey) const {
// Check if the key exists
Map::const_iterator cit = m_mData.find(sKey);
Map::const_iterator cit = m_mData.find(pcKey);
if (cit != m_mData.end())
return cit->second;
// Key does not exist
assert( false );
assert(false);
return m_kDummyKey;
// TODO: How to handle this
}
CVAStructValue& CVAStruct::operator[]( const std::string& sKey )
CVAStructValue& CVAStruct::operator[](const char* pcKey)
{
// Check if the key exists
Map::iterator it = m_mData.find(sKey);
Map::iterator it = m_mData.find(pcKey);
if( it != m_mData.end() )
if (it != m_mData.end())
{
// If the key already exists return this
return it->second;
......@@ -146,7 +149,7 @@ CVAStructValue& CVAStruct::operator[]( const std::string& sKey )
else
{
// Otherwise: create an unassigned key with the given name
it = m_mData.insert( m_mData.begin(), std::pair<std::string, CVAStructValue>(sKey, CVAStructValue()) );
it = m_mData.insert(m_mData.begin(), std::pair<std::string, CVAStructValue>(pcKey, CVAStructValue()));
it->second.psKey = &it->first;
return it->second;
}
......@@ -156,7 +159,7 @@ CVAStruct& CVAStruct::operator=(const CVAStruct& rhs) {
m_mData.clear();
// Autonome Kopien aller Schlssel einfgen
for (Map::const_iterator cit=rhs.Begin(); cit!=rhs.End(); ++cit) {
for (Map::const_iterator cit = rhs.Begin(); cit != rhs.End(); ++cit) {
CVAStructValue& oKey = m_mData[cit->first];
oKey.psKey = &cit->first;
oKey = cit->second;
......@@ -171,10 +174,10 @@ CVAStruct::iterator CVAStruct::End() { return m_mData.end(); }
CVAStruct::const_iterator CVAStruct::End() const { return m_mData.end(); }
void CVAStruct::Merge(const CVAStruct& rhs, bool bUnique) {
for (CVAStruct::const_iterator cit=rhs.Begin(); cit!=rhs.End(); ++cit) {
for (CVAStruct::const_iterator cit = rhs.Begin(); cit != rhs.End(); ++cit) {
MapIt it = m_mData.find(cit->first);
if (bUnique && it!=m_mData.end())
if (bUnique && it != m_mData.end())
VA_EXCEPT1("Failed to merge structs. Keys not disjoint.");
m_mData[cit->first] = cit->second;
......@@ -185,7 +188,7 @@ std::string CVAStruct::ToString(int iIndent) const {
std::stringstream ss;
std::string margin(iIndent, ' ');
for (Map::const_iterator cit=m_mData.begin(); cit!=m_mData.end(); ++cit) {
for (Map::const_iterator cit = m_mData.begin(); cit != m_mData.end(); ++cit) {
const CVAStructValue& k = cit->second;
switch (k.iDatatype) {
case CVAStructValue::BOOL:
......@@ -205,21 +208,21 @@ std::string CVAStruct::ToString(int iIndent) const {
break;
case CVAStructValue::STRUCT:
{
const CVAStruct& oKey = cit->second;
ss << margin << cit->first << " = [struct] { " << std::endl
<< margin << oKey.ToString(iIndent+4)
<< margin << "}" << std::endl;
}
break;
{
const CVAStruct& oKey = cit->second;
ss << margin << cit->first << " = [struct] { " << std::endl
<< margin << oKey.ToString(iIndent + 4)
<< margin << "}" << std::endl;
}
break;
case CVAStructValue::DATA:
ss << margin << cit->first << " = [data: " << cit->second.GetDataSize() << " bytes]" << std::endl;
case CVAStructValue::SAMPLEBUFFER:
{
ss << margin << cit->first << " = [samplebuffer: " << cit->second.ToString() << " samples]" << std::endl;
}
break;
{
ss << margin << cit->first << " = [samplebuffer: " << cit->second.ToString() << " samples]" << std::endl;
}
break;
}
}
......@@ -237,7 +240,7 @@ CVAStructValue::CVAStructValue(const char* value) : iDatatype(STRING), sValue(va
CVAStructValue::CVAStructValue(const std::string& value) : iDatatype(STRING), sValue(value), xValue(NULL), pData(NULL) {};
CVAStructValue::CVAStructValue(const CVAStruct& value) : iDatatype(STRUCT), xValue(new CVAStruct(value)), pData(NULL) {};
CVAStructValue::CVAStructValue( void* pData, int iBytes)
CVAStructValue::CVAStructValue(void* pData, int iBytes)
: iDatatype(DATA)
, pData(NULL)
, xValue(NULL)
......@@ -245,9 +248,9 @@ CVAStructValue::CVAStructValue( void* pData, int iBytes)
SetData(pData, iBytes);
}
CVAStructValue::CVAStructValue( const CVASampleBuffer& oSampleBuffer )
: iDatatype( SAMPLEBUFFER)
, sbValue( oSampleBuffer )
CVAStructValue::CVAStructValue(const CVASampleBuffer& oSampleBuffer)
: iDatatype(SAMPLEBUFFER)
, sbValue(oSampleBuffer)
{}
CVAStructValue::CVAStructValue(const CVAStructValue& rhs) : iDatatype(UNASSIGNED), xValue(NULL), pData(NULL)
......@@ -280,13 +283,14 @@ void* CVAStructValue::GetData() {
}
void CVAStructValue::SetData(void* pData, int iBytes) {
assert( iDatatype == DATA );
assert(iDatatype == DATA);
if (iDatatype != DATA) return;
if (pData == NULL) {
assert( iBytes == 0 );
} else {
assert( iBytes > 0 );
assert(iBytes == 0);
}
else {
assert(iBytes > 0);
}
// Free previous data
......@@ -303,13 +307,13 @@ void CVAStructValue::SetData(void* pData, int iBytes) {
const CVAStruct& CVAStructValue::GetStruct() const {
if (iDatatype != STRUCT) VA_EXCEPT1("Key value is not a structure");
assert( xValue );
assert(xValue);
return *xValue;
}
CVAStruct& CVAStructValue::GetStruct() {
if (iDatatype != STRUCT) VA_EXCEPT1("Key value is not a structure");
assert( xValue );
assert(xValue);
return *xValue;
}
......@@ -347,7 +351,7 @@ bool CVAStructValue::IsData() const {
bool CVAStructValue::IsSampleBuffer() const
{
return ( iDatatype == SAMPLEBUFFER );
return (iDatatype == SAMPLEBUFFER);
}
CVAStructValue& CVAStructValue::operator=(const CVAStructValue& rhs) {
......@@ -358,7 +362,7 @@ CVAStructValue& CVAStructValue::operator=(const CVAStructValue& rhs) {
delete[] pData;
delete xValue;
iDataSize = 0;
// Fast assignment. Copy only what is necessary ...
iDatatype = rhs.iDatatype;
switch (iDatatype) {
......@@ -426,21 +430,25 @@ CVAStructValue& CVAStructValue::operator=(const std::string& rhs) {
return *this;
}
CVAStructValue& CVAStructValue::operator=( const CVASampleBuffer& rhs )
CVAStructValue& CVAStructValue::operator=(const CVASampleBuffer& rhs)
{
iDatatype = SAMPLEBUFFER;
sbValue = rhs;
return *this;
}
const CVAStructValue& CVAStructValue::operator[](const std::string& sKey) const {
if (!IsStruct()) VA_EXCEPT1("Key is not a structure");
return (*xValue)[sKey];
const CVAStructValue& CVAStructValue::operator[](const char* pcKey) const
{
if (!IsStruct())
VA_EXCEPT1("Key is not a structure");
return (*xValue)[pcKey];
}
CVAStructValue& CVAStructValue::operator[](const std::string& sKey) {
if (!IsStruct()) VA_EXCEPT1("Key is not a structure");
return (*xValue)[sKey];
CVAStructValue& CVAStructValue::operator[](const char* pcKey)
{
if (!IsStruct())
VA_EXCEPT1("Key is not a structure");
return (*xValue)[pcKey];
}
CVAStructValue::operator bool() const {
......@@ -459,17 +467,17 @@ CVAStructValue::operator bool() const {
case STRING:
// bool = Key[string] may be possible.
{
std::string s(sValue);
std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) ::toupper);
if ((s == "no") || (s == "false")) return false;
if ((s == "yes") || (s == "true")) return true;
}
{
std::string s(sValue);
std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) ::toupper);
if ((s == "no") || (s == "false")) return false;
if ((s == "yes") || (s == "true")) return true;
}
VA_EXCEPT1(std::string("Key \"") + (*psKey) + std::string("\" cannot be interpreted as an logical value"));
VA_EXCEPT1(std::string("Key \"") + (*psKey) + std::string("\" cannot be interpreted as an logical value"));
case SAMPLEBUFFER:
return ( sbValue.GetNumSamples() > 0 );
return (sbValue.GetNumSamples() > 0);
case STRUCT:
// bool = Key[struct] is not possible.
VA_EXCEPT1("Types cannot be converted");
......@@ -497,18 +505,18 @@ CVAStructValue::operator int() const {
case DOUBLE:
// int = Key[double] is dangerous (loss of precision) and but not forbidden.
return (int) dValue;
return (int)dValue;
case STRING:
// int = Key[string] may be possible.
{
std::istringstream ss(sValue);
int i;
if (!(ss >> i).fail())
return i;
else
VA_EXCEPT1(std::string("Key \"") + (*psKey) + std::string("\" cannot be interpreted as an integer number"));
}
{
std::istringstream ss(sValue);
int i;
if (!(ss >> i).fail())
return i;
else
VA_EXCEPT1(std::string("Key \"") + (*psKey) + std::string("\" cannot be interpreted as an integer number"));
}
case STRUCT:
// int = Key[struct] is not possible.
......@@ -533,7 +541,7 @@ CVAStructValue::operator double() const {
case INT:
// double = Key[int] is valid.
return (double) iValue;
return (double)iValue;
case DOUBLE:
// double = Key[double] obligatory.
......@@ -542,14 +550,14 @@ CVAStructValue::operator double() const {
case STRING:
// double = Key[string] may be possible.
// int = Key[string] may be possible.
{
std::istringstream ss(sValue);
double d;
if (!(ss >> d).fail())
return d;
else
VA_EXCEPT1(std::string("Key \"") + (*psKey) + std::string("\" cannot be interpreted as a number"));
}
{
std::istringstream ss(sValue);
double d;
if (!(ss >> d).fail())
return d;
else
VA_EXCEPT1(std::string("Key \"") + (*psKey) + std::string("\" cannot be interpreted as a number"));
}
case STRUCT:
// double = Key[struct] is not possible.
......@@ -571,23 +579,23 @@ CVAStructValue::operator std::string() const {
switch (iDatatype) {
case BOOL:
// std::string = Key[bool] allowed. Implicit conversion.
return ( bValue ? "true" : "false" );
return (bValue ? "true" : "false");
case INT:
{
// std::string = Key[int] allowed. Implicit conversion.
std::stringstream ss;
ss << iValue;
return ss.str();
}
{
// std::string = Key[int] allowed. Implicit conversion.
std::stringstream ss;
ss << iValue;
return ss.str();
}
case DOUBLE:
{
// std::string = Key[double] allowed. Implicit conversion.
std::stringstream ss;
ss << dValue;
return ss.str();
}
{
// std::string = Key[double] allowed. Implicit conversion.
std::stringstream ss;
ss << dValue;
return ss.str();
}
case STRING:
// std::string = Key[string] obligatory.
......@@ -595,7 +603,7 @@ CVAStructValue::operator std::string() const {
case STRUCT:
// std::string = Key[struct] is not possible.
VA_EXCEPT1( "Types cannot be converted" );
VA_EXCEPT1("Types cannot be converted");
case UNASSIGNED:
// Key is unassigned
......@@ -625,22 +633,22 @@ CVAStructValue::operator void*() const {
CVAStructValue::operator const CVASampleBuffer&() const
{
if( iDatatype == UNASSIGNED )
VA_EXCEPT1( std::string( "Key \"" ) + ( *psKey ) + std::string( "\" does not exist" ) );
if (iDatatype == UNASSIGNED)
VA_EXCEPT1(std::string("Key \"") + (*psKey) + std::string("\" does not exist"));
if( iDatatype != SAMPLEBUFFER )
VA_EXCEPT1( "Types cannot be converted");
if (iDatatype != SAMPLEBUFFER)
VA_EXCEPT1("Types cannot be converted");
return sbValue;
}
CVAStructValue::operator CVASampleBuffer&()
{
if( iDatatype == UNASSIGNED )
VA_EXCEPT1( std::string( "Key \"" ) + ( *psKey ) + std::string( "\" does not exist" ) );
if (iDatatype == UNASSIGNED)