summaryrefslogtreecommitdiff
path: root/code/core/interface.h
blob: b53b741882e6139e9bef57c5b742c064d0aa1084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef INTERFACE_H
#define INTERFACE_H

#include <string>
#include <set>
#include <boost/lexical_cast.hpp>

#include "math.h"

// filters to select which objects/variables (not) to select
typedef std::set<int> IfObjectFilter;
typedef std::set<std::string> IfElementFilter;

// interface-class .. holds long-time stuff for reflecting on a per class (template), per file (instance) and per direction (class) basis 
template<class T>
class InputInterface {
public:
  // A. the methods you want to call
  // creation
  InputInterface<T>(int fd, bool binary, IfObjectFilter ifo, IfElementFilter ife);
  bool readEntireFile();
  bool readFileUntil(double time);
  double peekNextTime(); // read a line ahead (if possible) and check at what time it occurs

  // B. internal state
  bool binary;  
  int fd;
  std::string buf;
  size_t rpos, npos, wpos;
  static const size_t buf_size = 32768;
  bool eof;
  IfObjectFilter ifo;
  IfElementFilter ife;

  // C. internal functions
  bool garantueeBuf(size_t size); // returns only after wpos - rpos >= size, but reads as much as possible without blocking
  bool garantueeLine();

  template<class Tval> bool bufRead(Tval &val, bool proccedRPos);
};

template<class T>
class OutputInterface {
public:
  OutputInterface<T>(int fd, bool binary, IfObjectFilter *ifo, IfElementFilter *ife);

  bool pushObject(T *o); // serialize one object
  bool pushClass(); // serialize the entire class (selective by filter)
  bool isContained(typename T::id_type id);

  // internal state
  int fd;
  std::string buf;
  bool binary;
  IfObjectFilter *ifo;
  IfElementFilter *ife;

  // internal functions
  template<class Tval> bool bufWrite(Tval &val);
};

#endif // INTERFACE_H
contact: Jan Huwald // Impressum