00001 //===-- TreeStream.h --------------------------------------------*- C++ -*-===// 00002 // 00003 // The KLEE Symbolic Virtual Machine 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef __UTIL_TREESTREAM_H__ 00011 #define __UTIL_TREESTREAM_H__ 00012 00013 #include <string> 00014 #include <iostream> 00015 #include <vector> 00016 00017 namespace klee { 00018 00019 typedef unsigned TreeStreamID; 00020 class TreeOStream; 00021 00022 class TreeStreamWriter { 00023 static const unsigned bufferSize = 4*4096; 00024 00025 friend class TreeOStream; 00026 00027 private: 00028 char buffer[bufferSize]; 00029 unsigned lastID, bufferCount; 00030 00031 std::string path; 00032 std::ofstream *output; 00033 unsigned ids; 00034 00035 void write(TreeOStream &os, const char *s, unsigned size); 00036 void flushBuffer(); 00037 00038 public: 00039 TreeStreamWriter(const std::string &_path); 00040 ~TreeStreamWriter(); 00041 00042 bool good(); 00043 00044 TreeOStream open(); 00045 TreeOStream open(const TreeOStream &node); 00046 00047 void flush(); 00048 00049 // hack, to be replace by proper stream capabilities 00050 void readStream(TreeStreamID id, 00051 std::vector<unsigned char> &out); 00052 }; 00053 00054 class TreeOStream { 00055 friend class TreeStreamWriter; 00056 00057 private: 00058 TreeStreamWriter *writer; 00059 unsigned id; 00060 00061 TreeOStream(TreeStreamWriter &_writer, unsigned _id); 00062 00063 public: 00064 TreeOStream(); 00065 ~TreeOStream(); 00066 00067 unsigned getID() const; 00068 00069 void write(const char *buffer, unsigned size); 00070 00071 TreeOStream &operator<<(const std::string &s); 00072 00073 void flush(); 00074 }; 00075 } 00076 00077 #endif
1.5.8