diff options
Diffstat (limited to 'src/datax.cpp')
-rw-r--r-- | src/datax.cpp | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/src/datax.cpp b/src/datax.cpp new file mode 100644 index 0000000..e1e3f5f --- /dev/null +++ b/src/datax.cpp @@ -0,0 +1,168 @@ +// w32dlib - Win32 DataX Helpers +// +// Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk) +// +// This program 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 2 of the License, or +// (at your option) any later version. +// +// This program 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 for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// ------------------------------------------------------------------------- +// +#include "w32dlib/datax.h" + + +namespace W32DLib +{ + +// ------------------------------------------------------------ +// +DataX::DataX(DataX::EType type) : m_type(type) +{ + switch(m_type) + { + case eString: + m_data=static_cast<void*>(new std::string()); + break; + + case eInt: + m_data=static_cast<void*>(new int); + break; + + case eBool: + m_data=static_cast<void*>(new bool); + break; + } +} + + +// ------------------------------------------------------------ +// +DataX::~DataX() +{ + switch(m_type) + { + case eString: + delete static_cast<std::string*>(m_data); + break; + + case eInt: + delete static_cast<int*>(m_data); + break; + + case eBool: + delete static_cast<bool*>(m_data); + break; + } +} + + +// ------------------------------------------------------------ +// +DataX::EType DataX::Type() +{ + return m_type; +} + + +// ------------------------------------------------------------ +// +void DataX::Set(int value) +{ + if (m_type==eInt) + { + *(static_cast<int*>(m_data))=value; + } +} + + +// ------------------------------------------------------------ +// +void DataX::Set(const std::string& value) +{ + if (m_type==eString) + { + *(static_cast<std::string*>(m_data))=value; + } +} + + +// ------------------------------------------------------------ +// +void DataX::Set(const char *value) +{ + if (m_type==eString) + { + *(static_cast<std::string*>(m_data))=value; + } +} + + +// ------------------------------------------------------------ +// +void DataX::Set(bool value) +{ + if (m_type==eBool) + { + *(static_cast<bool*>(m_data))=value; + } +} + + +// ------------------------------------------------------------ +// +int DataX::Int() +{ + if (m_type==eInt) + { + return *(static_cast<int*>(m_data)); + } + else + { + return 0; + } +} + + +// ------------------------------------------------------------ +// +std::string DataX::Str() +{ + if (m_type==eString) + { + return *(static_cast<std::string*>(m_data)); + } + else + { + return std::string(); + } +} + + +// ------------------------------------------------------------ +// +bool DataX::Bool() +{ + if (m_type==eBool) + { + return *(static_cast<bool*>(m_data)); + } + else + { + return false; + } +} + + +}; // namespace w32dlib + +// END OF FILE |