00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __LSHKIT_ARCHIVE__
00021 #define __LSHKIT_ARCHIVE__
00022
00023 #include <vector>
00024 #include <iostream>
00025
00049 namespace lshkit {
00050
00051 static inline std::ostream &operator & (std::ostream &os, unsigned i) {
00052 return os.write((const char *)&i, sizeof(i));
00053 }
00054
00055 static inline std::ostream &operator & (std::ostream &os, float i) {
00056 return os.write((const char *)&i, sizeof(i));
00057 }
00058
00059 static inline std::istream &operator & (std::istream &is, unsigned &i) {
00060 return is.read((char *)&i, sizeof(i));
00061 }
00062
00063 static inline std::istream &operator & (std::istream &is, float &i) {
00064 return is.read((char *)&i, sizeof(i));
00065 }
00066
00067 static inline std::ostream &operator & (std::ostream &os, std::vector<float> &v) {
00068 unsigned L = v.size();
00069 os & L;
00070 os.write((const char *)&v[0], v.size() * sizeof(float));
00071 return os;
00072 }
00073
00074 static inline std::istream &operator & (std::istream &is, std::vector<float> &v) {
00075 unsigned L;
00076 is & L;
00077 v.resize(L);
00078 is.read((char *)&v[0], v.size() * sizeof(float));
00079 return is;
00080 }
00081
00082 static inline std::ostream &operator & (std::ostream &os, std::vector<unsigned> &v) {
00083 unsigned L = v.size();
00084 os & L;
00085 os.write((const char *)&v[0], v.size() * sizeof(unsigned));
00086 return os;
00087 }
00088
00089 static inline std::istream &operator & (std::istream &is, std::vector<unsigned> &v) {
00090 unsigned L;
00091 is & L;
00092 v.resize(L);
00093 is.read((char *)&v[0], v.size() * sizeof(unsigned));
00094 return is;
00095 }
00096
00097 template <typename D>
00098 std::ostream &operator & (std::ostream &s, D &t) {
00099 t.serialize(s, 0);
00100 return s;
00101 }
00102
00103 template <typename D>
00104 std::istream &operator & (std::istream &s, D &t) {
00105 t.serialize(s, 0);
00106 return s;
00107 }
00108
00109 template <typename D>
00110 std::ostream &operator & (std::ostream &os, std::vector<D> &v) {
00111 unsigned L = v.size();
00112 os & L;
00113 for (unsigned i = 0; i < L; ++i) {
00114 os & v[i];
00115 }
00116 return os;
00117 }
00118
00119 template <typename D>
00120 std::istream &operator & (std::istream &is, std::vector<D> &v) {
00121 unsigned L;
00122 is & L;
00123 v.resize(L);
00124 for (unsigned i = 0; i < L; ++i) {
00125 is & v[i];
00126 }
00127 return is;
00128 }
00129
00130
00131 }
00132
00133 #endif