ISIS Core Library 0.7.2 (api 3.0.0)
|
00001 /* 00002 Copyright (C) 2010 reimer@cbs.mpg.de 00003 00004 This program is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 */ 00018 00019 00020 #ifndef SELECTION_HPP_INCLUDED 00021 #define SELECTION_HPP_INCLUDED 00022 #include <map> 00023 #include "common.hpp" 00024 #include "istring.hpp" 00025 #include <boost/foreach.hpp> 00026 00027 namespace isis 00028 { 00029 namespace util 00030 { 00031 00039 class Selection 00040 { 00041 typedef std::map<util::istring, unsigned short> MapType; 00042 MapType ent_map; 00043 int m_set; 00044 public: 00052 Selection( const char *entries, const char *init_val = "" ); 00058 template<typename T> Selection( const std::map<T, std::string> &map ); 00060 Selection(); 00067 bool set( const char *entry ); 00068 bool set( unsigned short entry ); 00074 operator int()const; 00079 operator std::string()const; 00084 operator util::istring()const; 00089 bool operator==( const Selection &ref )const; 00094 bool operator==( const char ref[] )const; 00099 bool operator==( const int ref )const; 00101 std::list<util::istring> getEntries()const; 00102 }; 00103 00104 template<typename T> Selection::Selection( const std::map< T, std::string >& map ): m_set( 0 ) 00105 { 00106 for( typename std::map< T, std::string >::const_iterator i = map.begin(); i != map.end(); i++ ) { 00107 const MapType::value_type pair( 00108 util::istring( i->second.begin(), i->second.end() ), 00109 i->first 00110 ); 00111 assert( pair.second != 0 ); // 0 is reserved for <<NOT_SET>> 00112 00113 if( !ent_map.insert( pair ).second ) { 00114 LOG( Debug, error ) << "Entry " << util::MSubject( pair ) << " could not be inserted"; 00115 } 00116 } 00117 } 00118 00119 } 00120 } 00121 00122 namespace std 00123 { 00125 template<typename charT, typename traits> 00126 basic_ostream<charT, traits> &operator<<( basic_ostream<charT, traits> &out, const isis::util::Selection &s ) 00127 { 00128 return out << ( std::string )s; 00129 } 00130 } 00131 00132 #endif //SELECTION_HPP_INCLUDED