EvolvingObjects
|
00001 /* 00002 (c) Thales group, 2012 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Lesser General Public 00006 License as published by the Free Software Foundation; 00007 version 2 of the License. 00008 00009 This library 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 GNU 00012 Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this library; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 Contact: http://eodev.sourceforge.net 00018 00019 Authors: 00020 Benjamin Bouvier <benjamin.bouvier@gmail.com> 00021 */ 00022 # ifndef __EOSERIAL_STRING_H__ 00023 # define __EOSERIAL_STRING_H__ 00024 00025 # include <string> 00026 # include <sstream> 00027 # include <limits> 00028 00029 # include "Entity.h" 00030 00031 namespace eoserial 00032 { 00040 class String : public eoserial::Entity, public std::string 00041 { 00042 public: 00043 00048 String( const std::string& str ) : std::string( str ) {} 00049 00053 String( ) {} 00054 00058 virtual std::ostream& print( std::ostream& out ) const; 00059 00064 template<class T> 00065 inline void deserialize( T & value ); 00066 00067 protected: 00068 // Copy and reaffectation are forbidden 00069 explicit String( const String& _ ); 00070 String& operator=( const String& _ ); 00071 }; 00072 00082 template<class T> 00083 inline void String::deserialize( T & value ) 00084 { 00085 std::stringstream ss; 00086 ss.precision(std::numeric_limits<double>::digits10 + 1); 00087 ss << *this; 00088 ss >> value; 00089 } 00090 00095 template<> 00096 inline void String::deserialize( std::string & value ) 00097 { 00098 value = *this; 00099 } 00100 00101 } // namespace eoserial 00102 00103 # endif // __EOSERIAL_STRING_H__