From 3a1bf865b6c1b6b7c096eaf6dab91a465319488a Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 4 Apr 2005 00:52:23 +0000 Subject: Added DataX --- src/datax.cpp | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 src/datax.cpp (limited to 'src/datax.cpp') 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(new std::string()); + break; + + case eInt: + m_data=static_cast(new int); + break; + + case eBool: + m_data=static_cast(new bool); + break; + } +} + + +// ------------------------------------------------------------ +// +DataX::~DataX() +{ + switch(m_type) + { + case eString: + delete static_cast(m_data); + break; + + case eInt: + delete static_cast(m_data); + break; + + case eBool: + delete static_cast(m_data); + break; + } +} + + +// ------------------------------------------------------------ +// +DataX::EType DataX::Type() +{ + return m_type; +} + + +// ------------------------------------------------------------ +// +void DataX::Set(int value) +{ + if (m_type==eInt) + { + *(static_cast(m_data))=value; + } +} + + +// ------------------------------------------------------------ +// +void DataX::Set(const std::string& value) +{ + if (m_type==eString) + { + *(static_cast(m_data))=value; + } +} + + +// ------------------------------------------------------------ +// +void DataX::Set(const char *value) +{ + if (m_type==eString) + { + *(static_cast(m_data))=value; + } +} + + +// ------------------------------------------------------------ +// +void DataX::Set(bool value) +{ + if (m_type==eBool) + { + *(static_cast(m_data))=value; + } +} + + +// ------------------------------------------------------------ +// +int DataX::Int() +{ + if (m_type==eInt) + { + return *(static_cast(m_data)); + } + else + { + return 0; + } +} + + +// ------------------------------------------------------------ +// +std::string DataX::Str() +{ + if (m_type==eString) + { + return *(static_cast(m_data)); + } + else + { + return std::string(); + } +} + + +// ------------------------------------------------------------ +// +bool DataX::Bool() +{ + if (m_type==eBool) + { + return *(static_cast(m_data)); + } + else + { + return false; + } +} + + +}; // namespace w32dlib + +// END OF FILE -- cgit v1.2.3