gvars_vector.h

00001 /*
00002 
00003     This file is part of the FAST-ER machine learning system.
00004     Copyright (C) 2008  Edward Rosten and Los Alamos National Laboratory
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License along
00017     with this program; if not, write to the Free Software Foundation, Inc.,
00018     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00019 */
00020 #ifndef INC_GVARS_VECTOR_H
00021 #define INC_GVARS_VECTOR_H
00022 #include <vector>
00023 #include <set>
00024 #include <gvars3/serialize.h>
00025 
00026 ///\cond never
00027 namespace GVars3{ namespace serialize {
00028         
00029     /**GVars serialization for containers. 
00030        @ingroup gUtility
00031     */
00032 
00033     template<class C>std::string to_string(const std::set<C>& s)
00034     {
00035         std::ostringstream o;
00036         typename std::set<C>::const_iterator i;
00037 
00038         for(i=s.begin();i != s.end(); i++)
00039         {
00040             if(i != s.begin())
00041                 o <<  " ";
00042             o << *i;
00043         }
00044 
00045         return o.str();
00046     }
00047 
00048     template<class C> int from_string(const std::string& s, std::set<C>& o)
00049     {
00050         std::istringstream i(s);
00051         using namespace tag;
00052         
00053         while(1)
00054         {   
00055             C c;
00056             i >> c;
00057 
00058             if(i) //No data lost: 
00059                 o.insert(o.end(), c);
00060             else //Stream finished for some reason (either bad or b0rked)
00061                 return check_stream(i);
00062         }
00063     }
00064 
00065     /**GVars serialization for containers. 
00066        @ingroup gUtility
00067     */
00068 
00069     template<class C>std::string to_string(const std::vector<C>& s)
00070     {
00071         std::ostringstream o;
00072         typename std::vector<C>::const_iterator i;
00073 
00074         for(i=s.begin();i != s.end(); i++)
00075         {
00076             if(i != s.begin())
00077                 o <<  " ";
00078             o << *i;
00079         }
00080 
00081         return o.str();
00082     }
00083 
00084     template<class C> int from_string(const std::string& s, std::vector<C>& o)
00085     {
00086         std::istringstream i(s);
00087         using namespace tag;
00088         
00089         while(1)
00090         {   
00091             C c;
00092             i >> c;
00093 
00094             if(i) //No data lost: 
00095                 o.insert(o.end(), c);
00096             else //Stream finished for some reason (either bad or b0rked)
00097                 return check_stream(i);
00098         }
00099     }
00100 }}
00101 ///\endcond
00102 #include <gvars3/instances.h>
00103 #endif
00104 

Generated on Mon Mar 2 12:47:12 2009 for FAST-ER by  doxygen 1.5.3