ModErn Text Analysis
META Enumerates Textual Applications
binary.h
Go to the documentation of this file.
1 
11 #ifndef META_IO_BINARY_H_
12 #define META_IO_BINARY_H_
13 
14 #include <istream>
15 #include <ostream>
16 
17 namespace meta
18 {
19 namespace io
20 {
21 
27 template <class T>
28 void write_binary(std::ostream& out, const T& elem)
29 {
30  out.write(reinterpret_cast<const char*>(&elem), sizeof(T));
31 }
32 
38 inline void write_binary(std::ostream& out, const std::string& str)
39 {
40  out.write(str.c_str(), str.size() + 1);
41 }
42 
48 template <class T>
49 void read_binary(std::istream& in, T& elem)
50 {
51  in.read(reinterpret_cast<char*>(&elem), sizeof(T));
52 }
53 
59 inline void read_binary(std::istream& in, std::string& str)
60 {
61  std::getline(in, str, '\0');
62 }
63 }
64 }
65 
66 #endif
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
void read_binary(std::istream &in, T &elem)
Reads an object in binary from a stream.
Definition: binary.h:49
void write_binary(std::ostream &out, const T &elem)
Writes an object in binary format to a stream.
Definition: binary.h:28