map.hpp

См. документацию.
00001 /*
00002 
00003 oess_1: Object Entity Serialization & Stability
00004 Yauheni A. Akhotnikau (C) 2002-2006
00005 eao197@yahoo.com
00006 -------------------------------------------------
00007 
00008 Permission is granted to anyone to use this software for any purpose on any
00009 computer system, and to redistribute it freely, subject to the following
00010 restrictions:
00011 
00012 1. This software is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00015 
00016 2. The origin of this software must not be misrepresented, either by
00017    explicit claim or by omission.
00018 
00019 3. Altered versions must be plainly marked as such, and must not be
00020    misrepresented as being the original software.
00021 
00022 -------------------------------------------------
00023 
00024 */
00025 
00032 #if !defined( OESS_1__IO__CUSTOM__STL__MAP_HPP )
00033 #define OESS_1__IO__CUSTOM__STL__MAP_HPP
00034 
00035 #include <map>
00036 
00037 #include <oess_1/defs/h/quantity.hpp>
00038 
00039 #include <oess_1/io/h/stream.hpp>
00040 
00041 namespace oess_1
00042 {
00043 
00044 namespace io
00045 {
00046 
00051 template< class K, class T >
00052 oess_1::io::istream_t &
00053 operator>>( oess_1::io::istream_t & s, std::map< K, T > & o )
00054   {
00055     typedef typename std::map< K, T >::value_type value_type;
00056 
00057     oess_1::defs::quantity_t q;
00058     s >> q;
00059     std::map< K, T > tmp;
00060     for( oess_1::uint_t c = q.value(); c; --c )
00061       {
00062         K k;
00063         T next;
00064         s >> k >> next;
00065         tmp.insert( value_type( k, next ) );
00066       }
00067 
00068     tmp.swap( o );
00069 
00070     return s;
00071   }
00072 
00077 template< class K, class T >
00078 oess_1::io::istream_t &
00079 operator>>( oess_1::io::istream_t & s, std::multimap< K, T > & o )
00080   {
00081     typedef typename std::multimap< K, T >::value_type value_type;
00082 
00083     oess_1::defs::quantity_t q;
00084     s >> q;
00085     std::multimap< K, T > tmp;
00086     for( oess_1::uint_t c = q.value(); c; --c )
00087       {
00088         K key;
00089         T next;
00090         s >> key >> next;
00091         tmp.insert( value_type( key, next ) );
00092       }
00093 
00094     tmp.swap( o );
00095 
00096     return s;
00097   }
00098 
00103 template< class K, class T >
00104 oess_1::io::ostream_t &
00105 operator<<( oess_1::io::ostream_t & s, const std::map< K, T > & o )
00106   {
00107     oess_1::defs::quantity_t q( o.size() );
00108     s << q;
00109     for( typename std::map< K, T >::const_iterator i = o.begin(), end = o.end();
00110         i != end; ++i )
00111       {
00112         s << i->first << i->second;
00113       }
00114     return s;
00115   }
00116 
00121 template< class K, class T >
00122 oess_1::io::ostream_t &
00123 operator<<( oess_1::io::ostream_t & s, const std::multimap< K, T > & o )
00124   {
00125     oess_1::defs::quantity_t q( o.size() );
00126     s << q;
00127     for( typename std::multimap< K, T >::const_iterator i = o.begin(), end = o.end();
00128         i != end; ++i )
00129       {
00130         s << i->first << i->second;
00131       }
00132     return s;
00133   }
00134 
00135 } /* namespace io */
00136 
00137 } /* namespace oess_1 */
00138 
00139 #endif
00140 

Документация по ObjESSty. Последние изменения: Fri Oct 13 18:35:36 2006. Создано системой  doxygen 1.4.7
Hosted by uCoz