My Project
StlMapDouble.hh
00001 /*
00002 $Id: StlMapDouble.hh 2247 2011-04-27 05:20:41Z jisuzuki $
00003 */
00004 
00005 
00006 #ifndef STLMAPDOUBLE
00007 #define STLMAPDOUBLE
00008 
00009 #include <map>
00010 #include <algorithm>
00011 #include <boost/serialization/serialization.hpp>
00012 #include <boost/serialization/map.hpp>
00013 
00014 #include "Header.hh"
00015 
00016 class StlMapDouble{
00017 private:
00018   map< string, vector<Double> > M;
00019 
00020   const vector<Double>* PutPointer( const string &key ) const {
00021         return &ref(key);
00022   }
00024   // (pointed vector is treated as const; it is useful to used from const methods
00025 
00026   vector<Double>* PutPointer( const string &key ) {
00027         return const_cast<vector<Double>* >(
00028           static_cast<const StlMapDouble &>(*this).PutPointer( key )); };
00030 
00031   const vector<Double>* PutPointer( UInt4 index ) const;
00032   vector<Double>* PutPointer( UInt4 index ) {
00033         return const_cast<vector<Double>* >(
00034           static_cast<const StlMapDouble &>(*this).PutPointer( index )); };
00035 
00036   const vector<Double>* operator()( const string &key ) const { return PutPointer( key ); }
00037   const vector<Double>* operator()( UInt4 index ) const { return PutPointer( index ); }
00038 
00039   vector<Double>* operator()( const string &key ) { return PutPointer( key ); }
00040   vector<Double>* operator()( UInt4 index ) { return PutPointer( index ); }
00041   
00042 
00049   vector<Double> &ref(const string &key) { return M[key]; };
00050 
00057   const vector<Double> &ref(const string &key) const;
00058 
00059 
00060   friend class boost::serialization::access;
00064   template <class Archive>
00065   void serialize(Archive &ar, const unsigned int ver);
00066 
00067 protected:
00068 
00069 public:
00070   StlMapDouble();
00071  ~StlMapDouble();
00072   void clear(){ M.clear(); }
00073 
00074   StlMapDouble( const StlMapDouble &ob );
00075   StlMapDouble &operator=( const StlMapDouble &ob );
00076 
00077   void Append( const string &key, vector<Double> &value );
00078   void Add( const string &key, vector<Double> &value ){ Append( key, value ); }
00079 /*
00080   void AppendP( string key, vector<Double> *value );
00081   void AddP( string key, vector<Double> *value ){ AppendP( key, value ); }
00082 */
00083   vector<Double> &Put( const string &key );
00084   vector<Double> &Put( UInt4 index );
00085   
00086   void Erase( const string &key );
00087   void Delete( const string &key ){ Erase( key ); }
00088   void Replace( const string &key, vector<Double> &value );
00089   void Copy( const string &OldKey, const string &NewKey );
00090   UInt4 CheckKey( const string &key ){
00091     if( M.find( key ) == M.end() ) return 0; else return 1;
00092   };
00093 
00095   void Reverse() {
00096         for (std::map< string, vector<Double> >::iterator p=M.begin(),
00097                    end=M.end();p!=end;++p)
00098           std::reverse((*p).second.begin(), (*p).second.end());
00099   }
00100 
00102   UInt4 Size() const { return M.size(); }
00103 
00105   UInt4 Size(const string &key) const {
00106         map< string, vector<Double> >::const_iterator R = M.find( key );
00107         return R->second.size();}
00108 
00109   vector<string> PutKeyList();
00110   void DumpKeyList();
00111   
00112   Int8 PutIndexNumber( const string &Key );
00121   friend class ElementContainer;
00122 };
00123 template <class Archive>
00124 void StlMapDouble::
00125 serialize(Archive &ar, const unsigned int ver) {
00126   ar & boost::serialization::make_nvp("STLMapDouble", M);
00127 }
00128 
00129 
00130 /*
00131  *
00132  * StlMapDouble doesn't have NXwrite and NXread
00133  * because ElementContainer write and read map<string, vector<double> >
00134  * to/from NeXus file directly
00135  */
00136 #endif
 All Classes Functions Variables Friends