DiaDes  0.1
DIAgnosis of Discrete-Event System
Substring.hh
Go to the documentation of this file.
1 #ifndef __DIADES__UTILS__SUBSTRING__HH
2 #define __DIADES__UTILS__SUBSTRING__HH
3 #include <string>
4 #include<unordered_map>
5 
6 
7 using std::basic_string;
8 using std::unordered_map;
9 
10 namespace Diades
11 {
12 namespace Utils {
13 
27  template<class Ch> class basic_substring
28  {
29  public:
30  typedef typename std::basic_string<Ch>::size_type size_type;
31 
32 
33  basic_substring(std::basic_string<Ch> & s, size_type i, size_type nb):ps(&s),pos(i),n(nb) {}
34  basic_substring(std::basic_string<Ch> & s,const std::basic_string<Ch> & s2);
35  basic_substring(std::basic_string<Ch> & s,const Ch * p);
36 
37  basic_substring& operator=(const std::basic_string<Ch>&);
40 
41  operator std::basic_string<Ch>() const;
42  operator const Ch*() const;
43 
44  private:
45  std::basic_string<Ch> * ps;
46  size_type pos;
47  size_type n;
48  };
49 
51 
52 
53 
54  //template<class Ch>
55  //basic_substring<Ch>::basic_substring(std::basic_string<Ch> & s, size_type i, size_type nb)
56  // :ps(&s),pos(i),n(nb) {}
57  //
58 
59  template<class Ch>
60  basic_substring<Ch>::basic_substring(std::basic_string<Ch>& s, const std::basic_string<Ch>& s2)
61  :ps(&s),n(s2.length())
62  {
63  pos = s.find(s2);
64  }
65 
66 
67  template<class Ch>
68  basic_substring<Ch>::basic_substring(std::basic_string<Ch> & s,const Ch * p)
69  :ps(&s)
70  {
71  basic_string<Ch> s2(p);
72  n = s2.length();
73  pos = s.find(p);
74  }
75 
76  template<class Ch>
78  basic_substring<Ch>::operator=(const std::basic_string<Ch> & s)
79  {
80  ps->replace(pos,n,s);
81  return *this;
82  }
83 
84  template<class Ch>
87  {
88  if(this != &s)
89  {
90  ps = s.ps;
91  n = s.n;
92  pos = s.pos;
93  }
94  return *this;
95  }
96 
97  template<class Ch>
100  {
101  ps->replace(pos,n,c);
102  return *this;
103  }
104 
105  template<class Ch>
106  basic_substring<Ch>::operator std::basic_string<Ch>() const
107  {
108  return std::basic_string<Ch>(*ps,pos,n);
109  }
110 
111 
112 };
113 
114 };
115 
116 #endif
basic_substring< char > Substring
Definition: Substring.hh:50
basic_substring & operator=(const std::basic_string< Ch > &)
Definition: Substring.hh:78
basic_substring(std::basic_string< Ch > &s, size_type i, size_type nb)
Definition: Substring.hh:33
Namespace of the Diades project.
std::basic_string< Ch > * ps
Definition: Substring.hh:45
std::basic_string< Ch >::size_type size_type
Definition: Substring.hh:30