LocARNA-1.9.2
src/LocARNA/string1.hh
00001 #ifndef LOCARNA_STRING1_HH
00002 #define LOCARNA_STRING1_HH
00003 
00004 #ifdef HAVE_CONFIG_H
00005 #include <config.h>
00006 #endif
00007 
00008 #include <string>
00009 #include <algorithm>
00010 
00011 namespace LocARNA {
00021     class string1 {
00022         std::string s_;
00023 
00024     public:
00030         explicit string1(const std::string &s) : s_(s) {}
00031 
00037         string1(const string1 &s) : s_(s.s_) {}
00038 
00044         const std::string &
00045         str() const {
00046             return s_;
00047         }
00048 
00054         std::string &
00055         str() {
00056             return s_;
00057         }
00058 
00067         const char &operator[](size_t i) const {
00068             assert(i >= 1);
00069             assert(i <= s_.length());
00070             return s_[i - 1];
00071         }
00072 
00081         char &operator[](size_t i) {
00082             assert(i >= 1);
00083             assert(i <= s_.length());
00084             return s_[i - 1];
00085         }
00086 
00092         size_t
00093         length() const {
00094             return s_.length();
00095         }
00096 
00105         string1 &
00106         operator=(const string1 &s) {
00107             s_ = s.s_;
00108             return *this;
00109         }
00110 
00115         void
00116         reverse() {
00117             std::reverse(s_.begin(), s_.end());
00118         }
00119 
00125         void
00126         push_back(char c) {
00127             s_.push_back(c);
00128         }
00129 
00138         string1
00139         substr(size_t pos, size_t len) const {
00140             assert(pos >= 1);
00141             assert(pos <= s_.length());
00142             return string1(s_.substr(pos - 1, len));
00143         }
00144     };
00145 
00146 } // end namespace LocARNA
00147 
00148 #endif // LOCARNA_STRING1_HH
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends