Forums  +  C++ and Sockets  +  C++ and SQL: MySQL, sqlite, ODBC  +  Miscellaneous Projects
Logo
~Database~
~ C++ ~
~Contact~

enum_t.cpp

Go to the documentation of this file.
00001 /*
00002 enum_t.cpp
00003 
00004 Copyright (C) 2004  Anders Hedstrom
00005 
00006 This program is made available under the terms of the GNU GPL.
00007 
00008 If you would like to use this program in a closed-source application,
00009 a separate license agreement is available. For information about 
00010 the closed-source license agreement for this program, please
00011 visit http://www.alhem.net/sqlwrapped/license.html and/or
00012 email license@alhem.net.
00013 
00014 This program is free software; you can redistribute it and/or
00015 modify it under the terms of the GNU General Public License
00016 as published by the Free Software Foundation; either version 2
00017 of the License, or (at your option) any later version.
00018 
00019 This program is distributed in the hope that it will be useful,
00020 but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License
00025 along with this program; if not, write to the Free Software
00026 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 */
00028 #ifdef _WIN32
00029 #pragma warning(disable:4786)
00030 #endif
00031 
00032 #include "enum_t.h"
00033 
00034 
00035 #ifdef MYSQLW_NAMESPACE
00036 namespace MYSQLW_NAMESPACE {
00037 #endif
00038 
00039 
00040 enum_t::enum_t(std::map<std::string, uint64_t>& ref) : m_mmap(ref), m_value(0)
00041 {
00042         for (std::map<std::string, uint64_t>::iterator it = ref.begin(); it != ref.end(); it++)
00043         {
00044                 std::string str = (*it).first;
00045                 uint64_t value = (*it).second;
00046                 m_vmap[value] = str;
00047         }
00048 }
00049 
00050 
00051 void enum_t::operator=(const std::string& str)
00052 {
00053         m_value = m_mmap[str];
00054 }
00055 
00056 
00057 void enum_t::operator=(unsigned short s)
00058 {
00059         m_value = s;
00060 }
00061 
00062 
00063 const std::string& enum_t::String()
00064 {
00065         if (m_vmap.size() != m_mmap.size())
00066         {
00067                 for (std::map<std::string, uint64_t>::iterator it = m_mmap.begin(); it != m_mmap.end(); it++)
00068                 {
00069                         std::string str = (*it).first;
00070                         uint64_t value = (*it).second;
00071                         m_vmap[value] = str;
00072                 }
00073         }
00074         return m_vmap[m_value];
00075 }
00076 
00077 
00078 unsigned short enum_t::Value()
00079 {
00080         return m_value;
00081 }
00082 
00083 
00084 bool enum_t::operator==(const std::string& str)
00085 {
00086         if (!strcasecmp(c_str(), str.c_str()))
00087                 return true;
00088         return false;
00089 }
00090 
00091 
00092 bool enum_t::operator==(unsigned short s)
00093 {
00094         return m_value == s;
00095 }
00096 
00097 
00098 const char *enum_t::c_str()
00099 {
00100         return String().c_str();
00101 }
00102 
00103 
00104 bool enum_t::operator!=(const std::string& str)
00105 {
00106         if (!strcasecmp(c_str(), str.c_str()))
00107                 return !true;
00108         return !false;
00109 }
00110 
00111 
00112 #ifdef MYSQLW_NAMESPACE
00113 } // namespace MYSQLW_NAMESPACE {
00114 #endif
00115 
Page, code, and content Copyright (C) 2006 by Anders Hedström