formatting to Google style
							parent
							
								
									327cbc515f
								
							
						
					
					
						commit
						a4737d4706
					
				|  | @ -43,46 +43,44 @@ | |||
| namespace gtsam { | ||||
| 
 | ||||
| // Serialization directly to strings in compressed format
 | ||||
| template<class T> | ||||
| void serialize(const T& input, std::ostream & out_archive_stream) { | ||||
| template <class T> | ||||
| void serialize(const T& input, std::ostream& out_archive_stream) { | ||||
|   boost::archive::text_oarchive out_archive(out_archive_stream); | ||||
|   out_archive << input; | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| void deserialize(std::istream & in_archive_stream, T& output) { | ||||
| template <class T> | ||||
| void deserialize(std::istream& in_archive_stream, T& output) { | ||||
|   boost::archive::text_iarchive in_archive(in_archive_stream); | ||||
|   in_archive >> output; | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| template <class T> | ||||
| std::string serialize(const T& input) { | ||||
|   std::ostringstream out_archive_stream; | ||||
|   serialize(input, out_archive_stream); | ||||
|   return out_archive_stream.str(); | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| template <class T> | ||||
| void deserialize(const std::string& serialized, T& output) { | ||||
|   std::istringstream in_archive_stream(serialized); | ||||
|   deserialize(in_archive_stream, output); | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| template <class T> | ||||
| bool serializeToFile(const T& input, const std::string& filename) { | ||||
|   std::ofstream out_archive_stream(filename.c_str()); | ||||
|   if (!out_archive_stream.is_open()) | ||||
|     return false; | ||||
|   if (!out_archive_stream.is_open()) return false; | ||||
|   serialize(input, out_archive_stream); | ||||
|   out_archive_stream.close(); | ||||
|   return true; | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| template <class T> | ||||
| bool deserializeFromFile(const std::string& filename, T& output) { | ||||
|   std::ifstream in_archive_stream(filename.c_str()); | ||||
|   if (!in_archive_stream.is_open()) | ||||
|     return false; | ||||
|   if (!in_archive_stream.is_open()) return false; | ||||
|   deserialize(in_archive_stream, output); | ||||
|   in_archive_stream.close(); | ||||
|   return true; | ||||
|  | @ -103,34 +101,36 @@ void deserializeXML(std::istream& in_archive_stream, T& output, | |||
|   in_archive >> boost::serialization::make_nvp(name.c_str(), output); | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| std::string serializeXML(const T& input, const std::string& name="data") { | ||||
| template <class T> | ||||
| std::string serializeXML(const T& input, | ||||
|                          const std::string& name = "data") { | ||||
|   std::ostringstream out_archive_stream; | ||||
|   serializeXML(input, out_archive_stream, name); | ||||
|   return out_archive_stream.str(); | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| void deserializeXML(const std::string& serialized, T& output, const std::string& name="data") { | ||||
| template <class T> | ||||
| void deserializeXML(const std::string& serialized, T& output, | ||||
|                     const std::string& name = "data") { | ||||
|   std::istringstream in_archive_stream(serialized); | ||||
|   deserializeXML(in_archive_stream, output, name); | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| bool serializeToXMLFile(const T& input, const std::string& filename, const std::string& name="data") { | ||||
| template <class T> | ||||
| bool serializeToXMLFile(const T& input, const std::string& filename, | ||||
|                         const std::string& name = "data") { | ||||
|   std::ofstream out_archive_stream(filename.c_str()); | ||||
|   if (!out_archive_stream.is_open()) | ||||
|     return false; | ||||
|   if (!out_archive_stream.is_open()) return false; | ||||
|   serializeXML(input, out_archive_stream, name); | ||||
|   out_archive_stream.close(); | ||||
|   return true; | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| bool deserializeFromXMLFile(const std::string& filename, T& output, const std::string& name="data") { | ||||
| template <class T> | ||||
| bool deserializeFromXMLFile(const std::string& filename, T& output, | ||||
|                             const std::string& name = "data") { | ||||
|   std::ifstream in_archive_stream(filename.c_str()); | ||||
|   if (!in_archive_stream.is_open()) | ||||
|     return false; | ||||
|   if (!in_archive_stream.is_open()) return false; | ||||
|   deserializeXML(in_archive_stream, output, name); | ||||
|   in_archive_stream.close(); | ||||
|   return true; | ||||
|  | @ -139,7 +139,7 @@ bool deserializeFromXMLFile(const std::string& filename, T& output, const std::s | |||
| // Serialization to binary format with named structures
 | ||||
| template <class T> | ||||
| void serializeBinary(const T& input, std::ostream& out_archive_stream, | ||||
|                             const std::string& name = "data") { | ||||
|                      const std::string& name = "data") { | ||||
|   boost::archive::binary_oarchive out_archive(out_archive_stream); | ||||
|   out_archive << boost::serialization::make_nvp(name.c_str(), input); | ||||
| } | ||||
|  | @ -152,37 +152,39 @@ void deserializeBinary(std::istream& in_archive_stream, T& output, | |||
| } | ||||
| 
 | ||||
| // Serialization to binary format with named structures
 | ||||
| template<class T> | ||||
| std::string serializeBinary(const T& input, const std::string& name="data") { | ||||
| template <class T> | ||||
| std::string serializeBinary(const T& input, | ||||
|                             const std::string& name = "data") { | ||||
|   std::ostringstream out_archive_stream; | ||||
|   serializeBinary(input, out_archive_stream, name); | ||||
|   return out_archive_stream.str(); | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| void deserializeBinary(const std::string& serialized, T& output, const std::string& name="data") { | ||||
| template <class T> | ||||
| void deserializeBinary(const std::string& serialized, T& output, | ||||
|                        const std::string& name = "data") { | ||||
|   std::istringstream in_archive_stream(serialized); | ||||
|   deserializeBinary(in_archive_stream, output, name); | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| bool serializeToBinaryFile(const T& input, const std::string& filename, const std::string& name="data") { | ||||
| template <class T> | ||||
| bool serializeToBinaryFile(const T& input, const std::string& filename, | ||||
|                            const std::string& name = "data") { | ||||
|   std::ofstream out_archive_stream(filename.c_str()); | ||||
|   if (!out_archive_stream.is_open()) | ||||
|     return false; | ||||
|   if (!out_archive_stream.is_open()) return false; | ||||
|   serializeBinary(input, out_archive_stream, name); | ||||
|   out_archive_stream.close(); | ||||
|   return true; | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| bool deserializeFromBinaryFile(const std::string& filename, T& output, const std::string& name="data") { | ||||
| template <class T> | ||||
| bool deserializeFromBinaryFile(const std::string& filename, T& output, | ||||
|                                const std::string& name = "data") { | ||||
|   std::ifstream in_archive_stream(filename.c_str()); | ||||
|   if (!in_archive_stream.is_open()) | ||||
|     return false; | ||||
|   if (!in_archive_stream.is_open()) return false; | ||||
|   deserializeBinary(in_archive_stream, output, name); | ||||
|   in_archive_stream.close(); | ||||
|   return true; | ||||
| } | ||||
| 
 | ||||
| } // \namespace gtsam
 | ||||
| }  // namespace gtsam
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue