00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef delphin_output_lib_utils_h
00019 #define delphin_output_lib_utils_h
00020
00021 #include <string>
00022 #include <vector>
00023 #include <iostream>
00024 #include <utility>
00025 #include <stdexcept>
00026
00027 #include "delphin_output_lib_types.h"
00028
00029 namespace DELPHIN {
00030
00032 void read_string(std::istream& in, std::string& str);
00033
00035 void write_string(std::ostream& out, const std::string& str);
00036
00037 template<typename T>
00038 void read_vector(std::istream& in, std::vector<T>& vec) {
00039 unsigned int len;
00040 in.read(reinterpret_cast<char *>(&len), sizeof(unsigned int));
00041 if (len > 100000)
00042 throw std::runtime_error("[read_vector] Currupt binary data!");
00043 vec.resize(len);
00044 in.read(reinterpret_cast<char *>(&vec[0]), sizeof(T)*len);
00045 }
00046
00047 template<typename T>
00048 void write_vector(std::ostream& out, const std::vector<T>& vec) {
00049 unsigned int len = static_cast<unsigned int>(vec.size());
00050 out.write(reinterpret_cast<char *>(&len), sizeof(unsigned int));
00051 out.write(reinterpret_cast<const char *>(&vec[0]), sizeof(T)*len);
00052 }
00053
00054 }
00055
00056 #endif // delphin_output_lib_utils_h
00057
00058