summaryrefslogtreecommitdiff
path: root/code/core/interface.h
diff options
context:
space:
mode:
Diffstat (limited to 'code/core/interface.h')
-rw-r--r--code/core/interface.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/code/core/interface.h b/code/core/interface.h
new file mode 100644
index 0000000..b53b741
--- /dev/null
+++ b/code/core/interface.h
@@ -0,0 +1,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