Atlas-C++
Bach.h
Go to the documentation of this file.
1 // This file may be redistributed and modified under the terms of the
2 // GNU Lesser General Public License (See COPYING for details).
3 // Copyright (C) 2000-2001 Michael Day, Stefanus Du Toit
4 
5 // $Id$
6 
7 #ifndef ATLAS_CODECS_BACH_H
8 #define ATLAS_CODECS_BACH_H
9 
10 #include <Atlas/Codec.h>
11 
12 #include <iosfwd>
13 #include <stack>
14 
15 namespace Atlas { namespace Codecs {
16 
21 class Bach : public Codec
22 {
23  public:
24 
25  Bach(std::istream& in, std::ostream& out, Atlas::Bridge & b);
26 
27  void poll(bool can_read) override;
28 
29  void streamBegin() override;
30  void streamMessage() override;
31  void streamEnd() override;
32 
33  void mapMapItem(std::string name) override;
34  void mapListItem(std::string name) override;
35  void mapIntItem(std::string name, long) override;
36  void mapFloatItem(std::string name, double) override;
37  void mapStringItem(std::string name, std::string) override;
38  void mapEnd() override;
39 
40  void listMapItem() override;
41  void listListItem() override;
42  void listIntItem(long) override;
43  void listFloatItem(double) override;
44  void listStringItem(std::string) override;
45  void listEnd() override;
46 
47  unsigned linenum() const {return m_linenum;}
48 
49  protected:
50 
51  std::istream& m_istream;
52  std::ostream& m_ostream;
53  Bridge & m_bridge;
54  bool m_comma;
55  unsigned m_linenum;
56 
57  enum State
58  {
59  PARSE_INIT,
60  PARSE_STREAM,
61  PARSE_MAP,
62  PARSE_LIST,
63  PARSE_NAME,
64  PARSE_DATA,
65  PARSE_INT,
66  PARSE_FLOAT,
67  PARSE_STRING,
68  PARSE_LITERAL, // for literal character escaped with backslash
69  PARSE_COMMENT // for when we're in the middle of a comment field
70  };
71 
72  bool stringmode() const;
73 
74  std::string m_name, m_data;
75  std::stack<State> m_state;
76 
77  inline void parseInit(char);
78  inline void parseStream(char);
79  inline void parseMap(char);
80  inline void parseList(char);
81  inline void parseData(char);
82  inline void parseInt(char);
83  inline void parseFloat(char);
84  inline void parseString(char);
85  inline void parseLiteral(char);
86  inline void parseName(char);
87  inline void parseComment(char);
88 
89  inline std::string encodeString(std::string);
90  inline std::string decodeString(std::string);
91 
92  void writeIntItem(const std::string &,long);
93  void writeFloatItem(const std::string &,double);
94  void writeStringItem(const std::string &,std::string);
95  void writeLine(const std::string &,bool=true,bool=false);
96 };
97 
98 } } // namespace Atlas::Codecs
99 
100 #endif // ATLAS_CODECS_BACH_H
void listFloatItem(double) override
Adds a float to the currently streamed list.
void listEnd() override
Ends the currently streamed list.
void listStringItem(std::string) override
Adds a string to the currently streamed list.
void listMapItem() override
Starts a map object in the currently streamed list.
Atlas stream bridge.
Definition: Bridge.h:35
void streamEnd() override
Ends the Atlas stream.
void streamMessage() override
Start a message in an Atlas stream.
Definition: Bach.h:21
void streamBegin() override
Begin an Atlas stream.
The Atlas namespace.
Definition: Bridge.h:20
void mapListItem(std::string name) override
Starts a list object to the currently streamed map.
Atlas stream codec.
Definition: Codec.h:27
void mapFloatItem(std::string name, double) override
Adds a float to the currently streamed map.
void mapStringItem(std::string name, std::string) override
Adds a string to the currently streamed map.
void mapMapItem(std::string name) override
Starts a map object to the currently streamed map.
void mapIntItem(std::string name, long) override
Adds an integer to the currently streames map.
void listIntItem(long) override
Adds an integer to the currently streames list.
void listListItem() override
Starts a list object in the currently streamed list.
void mapEnd() override
Ends the currently streamed map.

Copyright 2000-2004 the respective authors.

This document can be licensed under the terms of the GNU Free Documentation License or the GNU General Public License and may be freely distributed under the terms given by one of these licenses.