00001 00008 /***************************************************************************** 00009 ** Ifdefs 00010 *****************************************************************************/ 00011 00012 #ifndef ECL_DEVICES_BUFFER_HPP_ 00013 #define ECL_DEVICES_BUFFER_HPP_ 00014 00015 /***************************************************************************** 00016 ** Includes 00017 *****************************************************************************/ 00018 00019 #include <cstring> 00020 00021 /***************************************************************************** 00022 ** Namespaces 00023 *****************************************************************************/ 00024 00025 namespace ecl { 00026 namespace devices { 00027 00028 /***************************************************************************** 00029 ** Interface [CharBuffer] 00030 *****************************************************************************/ 00039 class CharBuffer { 00040 public: 00041 /********************* 00042 ** Static Variables 00043 **********************/ 00044 static const unsigned int buffer_size = 4096; 00045 00046 /********************* 00047 ** C&D 00048 **********************/ 00049 CharBuffer() : fill_point_marker(0) {} 00050 virtual ~CharBuffer() {} 00051 00052 unsigned int remaining() { return ( buffer_size - fill_point_marker); } 00053 unsigned int size() const { return fill_point_marker; } 00054 bool full() const; 00055 long append(const char &c); 00056 long append(const char* s, unsigned long n); 00057 void clear(); 00058 char* c_ptr() { return contents; } 00059 00060 private: 00061 /********************* 00062 ** Variables 00063 **********************/ 00064 unsigned int fill_point_marker; // Index pointing to where you would write the next char 00065 char contents[buffer_size]; 00066 }; 00067 00068 /***************************************************************************** 00069 ** Interface [CharStringBuffer] 00070 *****************************************************************************/ 00079 class CharStringBuffer { 00080 public: 00081 /********************* 00082 ** Static Variables 00083 **********************/ 00084 static const unsigned int buffer_size = 4095; // Array is actually this + 1 00085 00086 /********************* 00087 ** C&D 00088 **********************/ 00089 CharStringBuffer() : fill_point_marker(0) { 00090 contents[buffer_size] = '\0'; 00091 } 00092 00093 virtual ~CharStringBuffer() {} 00094 00095 unsigned int remaining() { return ( buffer_size - fill_point_marker); } 00096 bool full() const; 00097 long append(const char &c); 00098 long append(const char* s, unsigned long n); 00099 const char* c_str(); 00100 void clear(); 00101 00102 private: 00103 /********************* 00104 ** Variables 00105 **********************/ 00106 unsigned int fill_point_marker; // Index pointing to where you would write the next char 00107 char contents[buffer_size+1]; 00108 }; 00109 00110 } // namespace devices 00111 } // namespace ecl 00112 00113 00114 #endif /* ECL_DEVICES_BUFFER_HPP_ */