00001
00007 #ifndef __BOUNDEDSTRING_H__
00008 #define __BOUNDEDSTRING_H__
00009
00010 #include <string>
00011 using std::string;
00012
00013 namespace Bounded {
00014
00015
00016
00029 template <size_t N, class T=char>
00030 class BoundedString {
00031 public:
00032 BoundedString() {}
00033
00034 BoundedString(const basic_string<T>& o) { operator=(o); }
00035
00037 void operator= (const basic_string<T>& o)
00038 { data[o.copy(data,N)]=0; }
00039
00040 bool operator== (const char* o) const
00041 { return (string(*this)==string(o)); }
00042
00044 operator basic_string<T>() const
00045 { return basic_string<T>(data); }
00046
00049 const T* c_str() const { return &(data[0]); }
00050
00051 private:
00053 T data[N+1];
00054 };
00055
00056
00057
00059 template <size_t N, class T>
00060 std::ostream& operator<<(std::ostream &s, const BoundedString<N,T>& b)
00061 { return s << string(b); }
00062
00063
00064
00065 }
00066
00067 #endif