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

set_t.cpp

Go to the documentation of this file.
00001 /*
00002 set_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 "set_t.h"
00033 
00034 
00035 #ifdef MYSQLW_NAMESPACE
00036 namespace MYSQLW_NAMESPACE {
00037 #endif
00038 
00039 
00040 set_t::set_t(std::map<std::string, uint64_t>& ref) : m_mmap(ref), m_value(0)
00041 {
00042 }
00043 
00044 
00045 void set_t::operator=(const std::string& str)
00046 {
00047         size_t x = 0;
00048         size_t i;
00049         m_value = 0;
00050         for (i = 0; i < str.size(); i++)
00051         {
00052                 if (str[i] == ',')
00053                 {
00054                         m_value |= m_mmap[str.substr(x,i - x)];
00055                         x = i + 1;
00056                 }
00057         }
00058         m_value |= m_mmap[str.substr(x,i - x)];
00059 }
00060 
00061 
00062 void set_t::operator=(uint64_t s)
00063 {
00064         m_value = s;
00065 }
00066 
00067 
00068 void set_t::operator|=(uint64_t s)
00069 {
00070         m_value |= s;
00071 }
00072 
00073 
00074 void set_t::operator&=(uint64_t s)
00075 {
00076         m_value &= s;
00077 }
00078 
00079 
00080 const std::string& set_t::String()
00081 {
00082         std::string str;
00083         for (std::map<std::string, uint64_t>::iterator it = m_mmap.begin(); it != m_mmap.end(); it++)
00084         {
00085                 std::string tmp = (*it).first;
00086                 uint64_t bit = (*it).second;
00087                 if (m_value & bit)
00088                 {
00089                         if (str.size())
00090                                 str += ",";
00091                         str += tmp;
00092                 }
00093         }
00094         m_strvalue = str;
00095         return m_strvalue;
00096 }
00097 
00098 
00099 uint64_t set_t::Value()
00100 {
00101         return m_value;
00102 }
00103 
00104 
00105 bool set_t::in_set(const std::string& str)
00106 {
00107         if (m_value & m_mmap[str])
00108                 return true;
00109         return false;
00110 }
00111 
00112 
00113 const char *set_t::c_str()
00114 {
00115         return String().c_str();
00116 }
00117 
00118 
00119 void set_t::operator+=(const std::string& str)
00120 {
00121         size_t x = 0;
00122         size_t i;
00123         for (i = 0; i < str.size(); i++)
00124         {
00125                 if (str[i] == ',')
00126                 {
00127                         m_value |= m_mmap[str.substr(x,i - x)];
00128                         x = i + 1;
00129                 }
00130         }
00131         m_value |= m_mmap[str.substr(x,i - x)];
00132 }
00133 
00134 
00135 void set_t::operator-=(const std::string& str)
00136 {
00137         size_t x = 0;
00138         size_t i;
00139         for (i = 0; i < str.size(); i++)
00140         {
00141                 if (str[i] == ',')
00142                 {
00143                         m_value &= ~m_mmap[str.substr(x,i - x)];
00144                         x = i + 1;
00145                 }
00146         }
00147         m_value &= ~m_mmap[str.substr(x,i - x)];
00148 }
00149 
00150 
00151 #ifdef MYSQLW_NAMESPACE
00152 } // namespace MYSQLW_NAMESPACE {
00153 #endif
00154 
Page, code, and content Copyright (C) 2006 by Anders Hedström