// 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(int value) : m_type(eInt) { m_data=static_cast(new int); Set(value); } // ------------------------------------------------------------ // DataX::DataX(const char *value) : m_type(eString) { m_data=static_cast(new std::string()); Set(value); } // ------------------------------------------------------------ // DataX::DataX(bool value) : m_type(eBool) { m_data=static_cast(new bool); Set(value); } // ------------------------------------------------------------ // 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