Snowman  0.1.0
snowboy-io.h
1 #pragma once
2 #include <fstream>
3 #include <snowboy-utils.h>
4 #include <vector>
5 
6 namespace snowboy {
7  extern std::string global_snowboy_offset_delimiter;
8  extern std::string global_snowboy_string_delimiter;
9 
10  void CheckToken(const char* token);
11  void EncryptToken(std::string* token);
12  void ExpectOneOrTwoTokens(bool binary, const std::string& token1, const std::string& token2, std::istream* is);
13  void ExpectToken(bool binary, const char* token, std::istream* is);
14  void ExpectToken(bool binary, const std::string& token, std::istream* is);
15  void ReadToken(bool binary, std::string* token, std::istream* is);
16  int PeekToken(bool binary, std::istream* is);
17  void WriteToken(bool binary, const char* token, std::ostream* os);
18  void WriteToken(bool binary, const std::string& token, std::ostream* os);
19  template <class T>
20  void ReadBasicType(bool binary, T* t, std::istream* is);
21  template <class T>
22  void WriteBasicType(bool binary, T t, std::ostream* os);
23  void ReadStringVector(bool binary, std::vector<std::string>* vector, std::istream* is);
24  void ReadStringVectorByLines(bool binary, std::vector<std::string>* vector, std::istream* is);
25  template <typename T>
26  void ReadIntegerVector(bool binary, std::vector<T>* data, std::istream* is);
27  template <typename T>
28  void WriteIntegerVector(bool binary, const std::vector<T>& data, std::ostream* os);
29  template <>
30  void WriteIntegerVector<int>(bool binary, const std::vector<int>& data, std::ostream* os);
31 
32  class Output {
33  std::ofstream m_stream;
34 
35  public:
36  Output(const std::string& filename, bool binary);
37  std::ostream* Stream();
38  ~Output();
39  };
40 
41  class Input {
42  std::ifstream m_stream;
43  bool m_is_binary;
44 
45  public:
46  Input(const std::string& filename);
47  std::istream* Stream();
48  ~Input();
49 
50  bool is_binary() const noexcept { return m_is_binary; }
51 
52  void ParseFilename(const std::string& filename, std::string* real_name, std::streampos* offset) const;
53  };
54 } // namespace snowboy
Definition: snowboy-io.h:41
Definition: snowboy-io.h:32