tobicore  7.0.0
 All Classes Functions Variables Typedefs Enumerator Friends Groups Pages
TPStreamer.hpp
1 /*
2  Copyright (C) 2009-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
3  Michele Tavella <michele.tavella@epfl.ch>
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  TPStreamer.hpp/.cpp is part of libcnbicore
19 */
20 
21 #ifndef TPSTREAMER_HPP
22 #define TPSTREAMER_HPP
23 
24 #include "TPMutex.hpp"
25 #include <string>
26 
27 typedef unsigned int TPStreamerDirection;
28 
38 class TPStreamer {
39  public:
41  TPStreamer(void);
42 
44  virtual ~TPStreamer(void);
45 
50  virtual void Append(std::string buffer);
51 
56  virtual void Append(const char* buffer, size_t bsize);
57 
70  virtual bool Extract(std::string* buffer, std::string hdr,
71  std::string trl, TPStreamerDirection direction = TPStreamer::Forward);
72 
83  virtual bool Has(std::string hdr, std::string trl,
84  TPStreamerDirection direction = TPStreamer::Forward);
85 
91  virtual int Count(std::string hdr);
92 
95  virtual void Dump(void);
96 
100  virtual int Size(void);
101 
104  virtual void Clear(void);
105  private:
115  virtual bool ImplHas(std::string hdr, std::string trl,
116  TPStreamerDirection direction);
117 
118  private:
120  std::string _stream;
121 
123  TPMutex _mtxstream;
124 
125  public:
127  static const TPStreamerDirection Forward = 0;
128 
130  static const TPStreamerDirection Reverse = 1;
131 };
132 
133 #endif