mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Integrated visualization modules to changelist 20202
p4#: 20204
This commit is contained in:
@@ -34,6 +34,8 @@ cvfMatrix4.inl
|
||||
cvfObject.h
|
||||
cvfObject.inl
|
||||
cvfPlane.h
|
||||
cvfPropertySet.h
|
||||
cvfPropertySetCollection.h
|
||||
cvfQuat.h
|
||||
cvfQuat.inl
|
||||
cvfRect.h
|
||||
@@ -44,6 +46,7 @@ cvfTBBControl.h
|
||||
cvfTimer.h
|
||||
cvfTrace.h
|
||||
cvfValueArray.h
|
||||
cvfVariant.h
|
||||
cvfVector2.h
|
||||
cvfVector2.inl
|
||||
cvfVector3.h
|
||||
@@ -64,11 +67,14 @@ cvfLogger.cpp
|
||||
cvfMath.cpp
|
||||
cvfObject.cpp
|
||||
cvfPlane.cpp
|
||||
cvfPropertySet.cpp
|
||||
cvfPropertySetCollection.cpp
|
||||
cvfString.cpp
|
||||
cvfSystem.cpp
|
||||
cvfTimer.cpp
|
||||
cvfTBBControl.cpp
|
||||
cvfTrace.cpp
|
||||
cvfVariant.cpp
|
||||
cvfVector2.cpp
|
||||
cvfVector3.cpp
|
||||
cvfVector4.cpp
|
||||
|
||||
@@ -95,7 +95,11 @@ Assert::FailAction AssertHandlerConsole::handleAssert(const char* fileName, int
|
||||
// Does the job on both Windows and Linux (creates a console on Windows if one doesn't exist)
|
||||
reportToConsole(fileName, lineNumber, expr, msg);
|
||||
|
||||
#ifdef WIN32
|
||||
__debugbreak();
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
|
||||
// Shouldn't really matter since we always abort
|
||||
return Assert::CONTINUE;
|
||||
|
||||
@@ -388,6 +388,7 @@ Color3ub::Color3ub(ColorIdent colorIdent)
|
||||
case SKY_BLUE: set(135, 206, 235); break;
|
||||
case VIOLET: set(238, 130, 238); break;
|
||||
case YELLOW_GREEN: set(154, 205, 50); break;
|
||||
case CEETRON: set( 81, 134, 148); break;
|
||||
|
||||
default: CVF_FAIL_MSG("Unknown ColorIdent");
|
||||
}
|
||||
|
||||
@@ -73,7 +73,9 @@ public:
|
||||
SEA_GREEN, ///< Sea green (46, 139, 87)
|
||||
SKY_BLUE, ///< Sky blue (135, 206, 235)
|
||||
VIOLET, ///< Violet (238, 130, 238)
|
||||
YELLOW_GREEN ///< Yellow green (154, 205, 50)
|
||||
YELLOW_GREEN, ///< Yellow green (154, 205, 50)
|
||||
|
||||
CEETRON ///< Ceetron Color (81, 134, 148)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
161
VisualizationModules/LibCore/cvfPropertySet.cpp
Normal file
161
VisualizationModules/LibCore/cvfPropertySet.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPropertySet.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class cvf::PropertySet
|
||||
/// \ingroup Core
|
||||
///
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySet::PropertySet(const String& classType)
|
||||
: m_classType(classType)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySet::~PropertySet()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PropertySet::operator==(const PropertySet& rhs) const
|
||||
{
|
||||
if (m_classType == rhs.m_classType)
|
||||
{
|
||||
return (m_propMap == rhs.m_propMap);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
String PropertySet::classType() const
|
||||
{
|
||||
return m_classType;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PropertySet::isEmpty() const
|
||||
{
|
||||
return m_propMap.empty();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant PropertySet::value(const String& key) const
|
||||
{
|
||||
std::map<String, Variant>::const_iterator it = m_propMap.find(key);
|
||||
if (it != m_propMap.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Variant();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PropertySet::setValue(const String& key, const Variant& data)
|
||||
{
|
||||
m_propMap[key] = data;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PropertySet::contains(const String& key) const
|
||||
{
|
||||
if (m_propMap.find(key) != m_propMap.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<String> PropertySet::allKeys() const
|
||||
{
|
||||
std::vector<String> all;
|
||||
std::map<String, Variant>::const_iterator it;
|
||||
for (it = m_propMap.begin(); it != m_propMap.end(); ++it)
|
||||
{
|
||||
all.push_back(it->first);
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<Variant> PropertySet::allValues() const
|
||||
{
|
||||
std::vector<Variant> all;
|
||||
std::map<String, Variant>::const_iterator it;
|
||||
for (it = m_propMap.begin(); it != m_propMap.end(); ++it)
|
||||
{
|
||||
all.push_back(it->second);
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace gc
|
||||
60
VisualizationModules/LibCore/cvfPropertySet.h
Normal file
60
VisualizationModules/LibCore/cvfPropertySet.h
Normal file
@@ -0,0 +1,60 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfObject.h"
|
||||
#include "cvfVariant.h"
|
||||
#include "cvfString.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class PropertySet : public Object
|
||||
{
|
||||
public:
|
||||
PropertySet(const String& classType);
|
||||
~PropertySet();
|
||||
|
||||
bool operator==(const PropertySet& rhs) const;
|
||||
|
||||
String classType() const;
|
||||
bool isEmpty() const;
|
||||
|
||||
Variant value(const String& key) const;
|
||||
void setValue(const String& key, const Variant& data);
|
||||
bool contains(const String& key) const;
|
||||
|
||||
std::vector<String> allKeys() const;
|
||||
std::vector<Variant> allValues() const;
|
||||
|
||||
private:
|
||||
String m_classType;
|
||||
std::map<String, Variant> m_propMap;
|
||||
};
|
||||
|
||||
|
||||
} // namespace cvf
|
||||
157
VisualizationModules/LibCore/cvfPropertySetCollection.cpp
Normal file
157
VisualizationModules/LibCore/cvfPropertySetCollection.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPropertySetCollection.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class cvf::PropertySetCollection
|
||||
/// \ingroup Core
|
||||
///
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySetCollection::PropertySetCollection()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySetCollection::~PropertySetCollection()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t PropertySetCollection::count() const
|
||||
{
|
||||
return m_propertySets.size();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySet* PropertySetCollection::propertySet(size_t index)
|
||||
{
|
||||
CVF_ASSERT(index < m_propertySets.size());
|
||||
return m_propertySets.at(index);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const PropertySet* PropertySetCollection::propertySet(size_t index) const
|
||||
{
|
||||
CVF_ASSERT(index < m_propertySets.size());
|
||||
return m_propertySets.at(index);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PropertySetCollection::addPropertySet(PropertySet* propertySet)
|
||||
{
|
||||
CVF_ASSERT(propertySet);
|
||||
m_propertySets.push_back(propertySet);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t PropertySetCollection::countOfType(const String& classType) const
|
||||
{
|
||||
size_t classCount = 0;
|
||||
const size_t totNumSets = m_propertySets.size();
|
||||
for (size_t i = 0; i < totNumSets; i++)
|
||||
{
|
||||
const PropertySet* ps = m_propertySets.at(i);
|
||||
if (ps->classType() == classType)
|
||||
{
|
||||
classCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return classCount;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySet* PropertySetCollection::propertySetOfType(const String& classType, size_t index)
|
||||
{
|
||||
size_t classCount = 0;
|
||||
const size_t totNumSets = m_propertySets.size();
|
||||
for (size_t i = 0; i < totNumSets; i++)
|
||||
{
|
||||
PropertySet* ps = m_propertySets.at(i);
|
||||
if (ps->classType() == classType)
|
||||
{
|
||||
if (classCount == index)
|
||||
{
|
||||
return ps;
|
||||
}
|
||||
|
||||
classCount++;
|
||||
}
|
||||
}
|
||||
|
||||
CVF_FAIL_MSG("Specified index is of of range");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySet* PropertySetCollection::firstPropertySetOfType(const String& classType)
|
||||
{
|
||||
const size_t totNumSets = m_propertySets.size();
|
||||
for (size_t i = 0; i < totNumSets; i++)
|
||||
{
|
||||
PropertySet* ps = m_propertySets.at(i);
|
||||
if (ps->classType() == classType)
|
||||
{
|
||||
return ps;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
} // namespace gc
|
||||
56
VisualizationModules/LibCore/cvfPropertySetCollection.h
Normal file
56
VisualizationModules/LibCore/cvfPropertySetCollection.h
Normal file
@@ -0,0 +1,56 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfObject.h"
|
||||
#include "cvfPropertySet.h"
|
||||
#include "cvfCollection.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class PropertySetCollection : public Object
|
||||
{
|
||||
public:
|
||||
PropertySetCollection();
|
||||
~PropertySetCollection();
|
||||
|
||||
size_t count() const;
|
||||
PropertySet* propertySet(size_t index);
|
||||
const PropertySet* propertySet(size_t index) const;
|
||||
void addPropertySet(PropertySet* propertySet);
|
||||
|
||||
size_t countOfType(const String& classType) const;
|
||||
PropertySet* propertySetOfType(const String& classType, size_t index);
|
||||
PropertySet* firstPropertySetOfType(const String& classType);
|
||||
|
||||
private:
|
||||
Collection<PropertySet> m_propertySets;
|
||||
};
|
||||
|
||||
|
||||
} // namespace cvf
|
||||
@@ -23,11 +23,12 @@
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
#include <limits>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace cvf {
|
||||
|
||||
@@ -682,28 +683,14 @@ String String::fromUtf8(const char* utfStr)
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// Returns a null-terminated sequence of wchar_t characters
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const wchar_t* String::ptr() const
|
||||
const wchar_t* String::c_str() const
|
||||
{
|
||||
return m_string.c_str();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
wchar_t* String::ptr()
|
||||
{
|
||||
if (m_string.size() < 1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &(m_string[0]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Convert the given number to a string with the specified format
|
||||
///
|
||||
@@ -738,16 +725,25 @@ String String::number(float n, char format, int precision)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double String::toDouble(bool* ok) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
double val = 0;
|
||||
std::wstringstream stream(m_string);
|
||||
stream >> val;
|
||||
|
||||
double val = wcstod(ptr(), &endPtr);
|
||||
bool convertOk = !stream.fail();
|
||||
|
||||
if (ok)
|
||||
{
|
||||
*ok = (endPtr != ptr());
|
||||
*ok = convertOk;
|
||||
}
|
||||
|
||||
return val;
|
||||
if (convertOk)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -761,16 +757,16 @@ double String::toDouble(bool* ok) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double String::toDouble(double defaultValue) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
|
||||
double val = wcstod(ptr(), &endPtr);
|
||||
|
||||
if (endPtr == ptr())
|
||||
bool ok = false;
|
||||
double val = toDouble(&ok);
|
||||
if (ok)
|
||||
{
|
||||
val = defaultValue;
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
@@ -783,16 +779,25 @@ double String::toDouble(double defaultValue) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
float String::toFloat(bool* ok) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
float val = 0;
|
||||
std::wstringstream stream(m_string);
|
||||
stream >> val;
|
||||
|
||||
double val = wcstod(ptr(), &endPtr);
|
||||
bool convertOk = !stream.fail();
|
||||
|
||||
if (ok)
|
||||
{
|
||||
*ok = (endPtr != ptr());
|
||||
*ok = convertOk;
|
||||
}
|
||||
|
||||
return static_cast<float>(val);
|
||||
if (convertOk)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -806,16 +811,16 @@ float String::toFloat(bool* ok) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
float String::toFloat(float defaultValue) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
|
||||
double val = wcstod(ptr(), &endPtr);
|
||||
|
||||
if (endPtr == ptr())
|
||||
bool ok = false;
|
||||
float val = toFloat(&ok);
|
||||
if (ok)
|
||||
{
|
||||
val = defaultValue;
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return static_cast<float>(val);
|
||||
}
|
||||
|
||||
|
||||
@@ -828,16 +833,25 @@ float String::toFloat(float defaultValue) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int String::toInt(bool* ok) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
int val = 0;
|
||||
std::wstringstream stream(m_string);
|
||||
stream >> val;
|
||||
|
||||
long val = wcstol(ptr(), &endPtr, 10);
|
||||
bool convertOk = !stream.fail();
|
||||
|
||||
if (ok)
|
||||
{
|
||||
*ok = (endPtr != ptr());
|
||||
*ok = convertOk;
|
||||
}
|
||||
|
||||
return static_cast<int>(val);
|
||||
if (convertOk)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -851,16 +865,121 @@ int String::toInt(bool* ok) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int String::toInt(int defaultValue) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
|
||||
long val = wcstol(ptr(), &endPtr, 10);
|
||||
|
||||
if (endPtr == ptr())
|
||||
bool ok = false;
|
||||
int val = toInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
val = static_cast<long>(defaultValue);
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Convert the contents of the string to an unsigned integer value
|
||||
///
|
||||
/// \param ok If not NULL, this will be set to true if conversion is ok, or to false if not
|
||||
///
|
||||
/// \return Returns the unsigned integer value found at the start of the string. 0 if an error occurred.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
uint String::toUInt(bool* ok) const
|
||||
{
|
||||
// The functions in the standard library does not honor unsignedness but gladly converts a negative integer
|
||||
// to an unsigned integer, so use our int64 implementation instead
|
||||
bool convertOk = false;
|
||||
int64 val = toInt64(&convertOk);
|
||||
if (convertOk)
|
||||
{
|
||||
if (val > std::numeric_limits<uint>::max() || val < 0)
|
||||
{
|
||||
convertOk = false;
|
||||
}
|
||||
}
|
||||
|
||||
return static_cast<int>(val);
|
||||
if (ok)
|
||||
{
|
||||
*ok = convertOk;
|
||||
}
|
||||
|
||||
if (convertOk)
|
||||
{
|
||||
return static_cast<uint>(val);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Convert the contents of the string to an unsigned integer value
|
||||
///
|
||||
/// \param defaultValue The value returned if the conversion failed.
|
||||
///
|
||||
/// \return Returns the value found at the start of the string or defaultValue if the
|
||||
/// conversion was not possible.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
uint String::toUInt(uint defaultValue) const
|
||||
{
|
||||
bool ok = false;
|
||||
uint val = toUInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int64 String::toInt64(bool* ok) const
|
||||
{
|
||||
int64 val = 0;
|
||||
std::wstringstream stream(m_string);
|
||||
stream >> val;
|
||||
|
||||
bool convertOk = !stream.fail();
|
||||
|
||||
if (ok)
|
||||
{
|
||||
*ok = convertOk;
|
||||
}
|
||||
|
||||
if (convertOk)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int64 String::toInt64(int64 defaultValue) const
|
||||
{
|
||||
bool ok = false;
|
||||
int64 val = toInt64(&ok);
|
||||
if (ok)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1012,7 +1131,7 @@ struct ArgInfo
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static ArgInfo findSmallestArgs(const String &s)
|
||||
{
|
||||
const wchar_t* strBegin = s.ptr();
|
||||
const wchar_t* strBegin = s.c_str();
|
||||
const wchar_t* strEnd = strBegin + s.size();
|
||||
|
||||
ArgInfo argInfo;
|
||||
@@ -1083,17 +1202,16 @@ static ArgInfo findSmallestArgs(const String &s)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static String replaceArgs(const String &s, const ArgInfo& info, int fieldWidth, const String& arg, const wchar_t& fillChar)
|
||||
{
|
||||
const wchar_t* strBegin = s.ptr();
|
||||
const wchar_t* strBegin = s.c_str();
|
||||
const wchar_t* strEnd = strBegin + s.size();
|
||||
|
||||
unsigned int absFieldWidth = static_cast<unsigned int>(Math::abs(fieldWidth));
|
||||
size_t resultLength = s.size() - info.totalArgLength + info.smallestArgCount*CVF_MAX(absFieldWidth, arg.size());
|
||||
|
||||
String result;
|
||||
result.resize(resultLength);
|
||||
|
||||
wchar_t* resultBuffer = result.ptr();
|
||||
wchar_t* rc = resultBuffer;
|
||||
std::wstring resultString;
|
||||
resultString.resize(resultLength);
|
||||
wchar_t* resultBuffer = &resultString[0];
|
||||
wchar_t* rc = resultBuffer;
|
||||
const wchar_t* c = strBegin;
|
||||
int repl_cnt = 0;
|
||||
|
||||
@@ -1143,7 +1261,7 @@ static String replaceArgs(const String &s, const ArgInfo& info, int fieldWidth,
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(rc, arg.ptr(), arg.size()*sizeof(wchar_t));
|
||||
memcpy(rc, arg.c_str(), arg.size()*sizeof(wchar_t));
|
||||
rc += arg.size();
|
||||
|
||||
if (fieldWidth < 0)
|
||||
@@ -1168,7 +1286,7 @@ static String replaceArgs(const String &s, const ArgInfo& info, int fieldWidth,
|
||||
|
||||
CVF_ASSERT(rc == resultBuffer + resultLength);
|
||||
|
||||
return result;
|
||||
return String(resultString);
|
||||
}
|
||||
|
||||
|
||||
@@ -1389,5 +1507,6 @@ void String::swap(String& other)
|
||||
m_string.swap(other.m_string);
|
||||
}
|
||||
|
||||
|
||||
} // namespace cvf
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
String subString(size_t start, size_t length = npos) const;
|
||||
void replace(const String& before, const String& after);
|
||||
|
||||
const wchar_t* c_str() const;
|
||||
CharArray toAscii() const; // Useful when you need a const char* pointer.
|
||||
std::string toStdString() const;
|
||||
std::wstring toStdWString() const;
|
||||
@@ -83,9 +84,6 @@ public:
|
||||
size_t size() const;
|
||||
void resize(size_t size);
|
||||
|
||||
const wchar_t* ptr() const;
|
||||
wchar_t* ptr();
|
||||
|
||||
static String number(float n, char format = 'g', int precision = -1);
|
||||
static String number(double n, char format = 'g', int precision = -1);
|
||||
|
||||
@@ -95,6 +93,10 @@ public:
|
||||
float toFloat(float defaultValue) const;
|
||||
int toInt(bool* ok = NULL) const;
|
||||
int toInt(int defaultValue) const;
|
||||
uint toUInt(bool* ok = NULL) const;
|
||||
uint toUInt(uint defaultValue) const;
|
||||
int64 toInt64(bool* ok = NULL) const;
|
||||
int64 toInt64(int64 defaultValue) const;
|
||||
|
||||
String arg(const String& a, int fieldWidth = 0, const wchar_t& fillChar = ' ') const;
|
||||
String arg(char a, int fieldWidth = 0, const wchar_t& fillChar = ' ') const;
|
||||
|
||||
@@ -40,7 +40,10 @@ private:
|
||||
static void showTraceOutput(String text, bool addNewLine);
|
||||
};
|
||||
|
||||
#define CVF_TRACE_FILELINE Trace::showFileLineNumber(__FILE__, __LINE__, "");
|
||||
#define CVF_TRACE_FILELINE_MSG(message) Trace::showFileLineNumber(__FILE__, __LINE__, message);
|
||||
|
||||
}
|
||||
}// namespace cvf
|
||||
|
||||
|
||||
#define CVF_TRACE_FILELINE cvf::Trace::showFileLineNumber(__FILE__, __LINE__, "");
|
||||
#define CVF_TRACE_FILELINE_MSG(message) cvf::Trace::showFileLineNumber(__FILE__, __LINE__, message);
|
||||
|
||||
|
||||
434
VisualizationModules/LibCore/cvfVariant.cpp
Normal file
434
VisualizationModules/LibCore/cvfVariant.cpp
Normal file
@@ -0,0 +1,434 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfVariant.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class cvf::Variant
|
||||
/// \ingroup Core
|
||||
///
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant()
|
||||
: m_type(INVALID)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const Variant& other)
|
||||
: m_type(other.m_type),
|
||||
m_data(other.m_data),
|
||||
m_arrayData(other.m_arrayData)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::~Variant()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant& Variant::operator=(Variant rhs)
|
||||
{
|
||||
// Copy-and-swap (copy already done since parameter is passed by value)
|
||||
rhs.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Compares two variants and returns true if they are equal
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool Variant::operator==(const Variant& rhs) const
|
||||
{
|
||||
if (m_type != rhs.m_type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case INVALID: return true;
|
||||
case INT: return getInt() == rhs.getInt();
|
||||
case UINT: return getUInt() == rhs.getUInt();
|
||||
case DOUBLE: return getDouble() == rhs.getDouble();
|
||||
case FLOAT: return getFloat() == rhs.getFloat();
|
||||
case BOOL: return getBool() == rhs.getBool();
|
||||
case VEC3D: return getVec3d() == rhs.getVec3d();
|
||||
case COLOR3F: return getColor3f() == rhs.getColor3f();
|
||||
case STRING: return getString() == rhs.getString();
|
||||
case ARRAY: return getArray() == rhs.getArray();
|
||||
}
|
||||
|
||||
CVF_FAIL_MSG("Unhandled variant type");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Type Variant::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool Variant::isValid() const
|
||||
{
|
||||
return (m_type != INVALID);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(int val)
|
||||
: m_type(INT)
|
||||
{
|
||||
assignData(&val, sizeof(val));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int Variant::getInt() const
|
||||
{
|
||||
CVF_ASSERT(m_type == INT);
|
||||
CVF_ASSERT(m_data.size() == sizeof(int));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const int* valPtr = reinterpret_cast<const int*>(rawPtr);
|
||||
return *valPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(uint val)
|
||||
: m_type(UINT)
|
||||
{
|
||||
assignData(&val, sizeof(val));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
uint Variant::getUInt() const
|
||||
{
|
||||
CVF_ASSERT(m_type == UINT);
|
||||
CVF_ASSERT(m_data.size() == sizeof(uint));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const uint* valPtr = reinterpret_cast<const uint*>(rawPtr);
|
||||
return *valPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(double val)
|
||||
: m_type(DOUBLE)
|
||||
{
|
||||
assignData(&val, sizeof(val));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double Variant::getDouble() const
|
||||
{
|
||||
CVF_ASSERT(m_type == DOUBLE);
|
||||
CVF_ASSERT(m_data.size() == sizeof(double));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const double* valPtr = reinterpret_cast<const double*>(rawPtr);
|
||||
return *valPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(float val)
|
||||
: m_type(FLOAT)
|
||||
{
|
||||
assignData(&val, sizeof(val));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
float Variant::getFloat() const
|
||||
{
|
||||
CVF_ASSERT(m_type == FLOAT);
|
||||
CVF_ASSERT(m_data.size() == sizeof(float));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const float* valPtr = reinterpret_cast<const float*>(rawPtr);
|
||||
return *valPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(bool val)
|
||||
: m_type(BOOL)
|
||||
{
|
||||
ubyte tmpVal = val ? 1u : 0;
|
||||
assignData(&tmpVal, 1);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool Variant::getBool() const
|
||||
{
|
||||
CVF_ASSERT(m_type == BOOL);
|
||||
CVF_ASSERT(m_data.size() == 1);
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
if (*rawPtr == 1u)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const Vec3d& val)
|
||||
: m_type(VEC3D)
|
||||
{
|
||||
assignData(val.ptr(), 3*sizeof(double));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Vec3d Variant::getVec3d() const
|
||||
{
|
||||
CVF_ASSERT(m_type == VEC3D);
|
||||
CVF_ASSERT(m_data.size() == 3*sizeof(double));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const double* valPtr = reinterpret_cast<const double*>(rawPtr);
|
||||
return Vec3d(valPtr[0], valPtr[1], valPtr[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Vec3d(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const Color3f& val)
|
||||
: m_type(COLOR3F)
|
||||
{
|
||||
assignData(val.ptr(), 3*sizeof(float));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Color3f Variant::getColor3f() const
|
||||
{
|
||||
CVF_ASSERT(m_type == COLOR3F);
|
||||
CVF_ASSERT(m_data.size() == 3*sizeof(float));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const float* valPtr = reinterpret_cast<const float*>(rawPtr);
|
||||
return Color3f(valPtr[0], valPtr[1], valPtr[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Color3f(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const String& val)
|
||||
: m_type(STRING)
|
||||
{
|
||||
size_t strSize = val.size();
|
||||
if (strSize > 0)
|
||||
{
|
||||
assignData(val.c_str(), strSize*sizeof(wchar_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const char* val)
|
||||
: m_type(STRING)
|
||||
{
|
||||
String strVal(val);
|
||||
size_t strSize = strVal.size();
|
||||
if (strSize > 0)
|
||||
{
|
||||
assignData(strVal.c_str(), strSize*sizeof(wchar_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const std::vector<Variant>& arr)
|
||||
: m_type(ARRAY),
|
||||
m_arrayData(arr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<Variant> Variant::getArray() const
|
||||
{
|
||||
CVF_ASSERT(m_type == ARRAY);
|
||||
return m_arrayData;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
String Variant::getString() const
|
||||
{
|
||||
CVF_ASSERT(m_type == STRING);
|
||||
|
||||
// Array must contain at least one wchar_t
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
const size_t numWideCars = m_data.size()/sizeof(wchar_t);
|
||||
if (rawPtr && numWideCars > 0)
|
||||
{
|
||||
const wchar_t* valPtr = reinterpret_cast<const wchar_t*>(rawPtr);
|
||||
std::wstring tmpWideString(valPtr, numWideCars);
|
||||
return String(tmpWideString);
|
||||
}
|
||||
else
|
||||
{
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Variant::swap(Variant& other)
|
||||
{
|
||||
std::swap(m_type, other.m_type);
|
||||
m_data.swap(other.m_data);
|
||||
m_arrayData.swap(other.m_arrayData);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Variant::assignData(const void* pointerToData, size_t dataSizeInBytes)
|
||||
{
|
||||
CVF_ASSERT(m_arrayData.size() == 0);
|
||||
|
||||
m_data.assign(reinterpret_cast<const ubyte*>(pointerToData), reinterpret_cast<const ubyte*>(pointerToData) + dataSizeInBytes);
|
||||
CVF_ASSERT(m_data.size() == dataSizeInBytes);
|
||||
}
|
||||
|
||||
|
||||
} // namespace gc
|
||||
98
VisualizationModules/LibCore/cvfVariant.h
Normal file
98
VisualizationModules/LibCore/cvfVariant.h
Normal file
@@ -0,0 +1,98 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfVector3.h"
|
||||
#include "cvfColor3.h"
|
||||
#include "cvfString.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class Variant
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
INVALID,
|
||||
INT,
|
||||
UINT,
|
||||
DOUBLE,
|
||||
FLOAT,
|
||||
BOOL,
|
||||
VEC3D,
|
||||
COLOR3F,
|
||||
STRING,
|
||||
ARRAY
|
||||
};
|
||||
|
||||
public:
|
||||
Variant();
|
||||
Variant(const Variant& other);
|
||||
~Variant();
|
||||
|
||||
Variant(int val);
|
||||
Variant(uint val);
|
||||
Variant(double val);
|
||||
Variant(float val);
|
||||
Variant(bool val);
|
||||
Variant(const Vec3d& val);
|
||||
Variant(const Color3f& val);
|
||||
Variant(const String& val);
|
||||
Variant(const char* val);
|
||||
Variant(const std::vector<Variant>& arr);
|
||||
|
||||
Variant& operator=(Variant rhs);
|
||||
|
||||
bool operator==(const Variant& rhs) const;
|
||||
|
||||
Type type() const;
|
||||
bool isValid() const;
|
||||
|
||||
int getInt() const;
|
||||
uint getUInt() const;
|
||||
double getDouble() const;
|
||||
float getFloat() const;
|
||||
bool getBool() const;
|
||||
Vec3d getVec3d() const;
|
||||
Color3f getColor3f() const;
|
||||
cvf::String getString() const;
|
||||
std::vector<Variant> getArray() const;
|
||||
|
||||
void swap(Variant& other);
|
||||
|
||||
private:
|
||||
void assignData(const void* pointerToData, size_t dataSizeInBytes);
|
||||
|
||||
private:
|
||||
Type m_type; // Type of for this variant
|
||||
std::vector<ubyte> m_data; // Data payload for single values
|
||||
std::vector<Variant> m_arrayData;// Data payload when storing an array (of variants)
|
||||
};
|
||||
|
||||
} // namespace cvf
|
||||
Reference in New Issue
Block a user