MCPcopy Create free account
hub / github.com/devosoft/avida / cString

Class cString

avida-core/source/tools/cString.h:43–558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41 **/
42
43class cString
44{
45protected:
46 inline void CopyOnWrite();
47
48 // -- Contained Classes --
49private:
50 // Declarations (only needed)
51 class cStringData;
52
53 // cCharProxy -- To detect rvalue vs lvalue ---------------------
54 class cCharProxy
55 {
56 private:
57 cString& string;
58 int index;
59
60 public:
61 cCharProxy(cString& _string, int _index) : string(_string), index(_index) { ; }
62
63 inline cCharProxy& operator=(char c); // lvalue
64 inline cCharProxy& operator+=(char c); // lvalue
65 inline cCharProxy& operator-=(char c); // lvalue
66 inline cCharProxy& operator++(); // lvalue (prefix)
67 inline char operator++(int dummy); // lvalue (postfix)
68 inline cCharProxy& operator--(); // lvalue (prefix)
69 inline char operator--(int dummy); // lvalue (postfix)
70 inline operator char () const; // rvalue
71 };
72 friend class cCharProxy; // Telling rvalue vs lvalue ....
73
74 // cStringData -- Holds the actual data and is reference count --
75 class cStringData : public Apto::RefCountObject<Apto::ThreadSafe>
76 {
77 // NOTE: Terminating NULL is always there (you can't assign!!)
78 private:
79 int m_size; // size of data (NOT INCLUDING TRAILING NULL)
80 char* m_data;
81
82 cStringData(); // @not_implemented
83
84 public:
85 explicit cStringData(int in_size);
86 cStringData(int in_size, const char* in);
87 cStringData(const cStringData& in);
88
89 ~cStringData()
90 {
91 delete [] m_data;
92 }
93
94 cStringData& operator=(const cStringData& in)
95 {
96 delete [] m_data;
97 m_size = in.GetSize();
98 m_data = new char [m_size + 1];
99 assert(m_data != NULL); // Memory Allocation Error: Out of Memory
100 for(int i = 0; i < m_size; ++i) m_data[i] = in[i];

Callers 4

operator+Method · 0.70
StringfMethod · 0.70
loadFileMethod · 0.70
processCommandMethod · 0.70

Calls 2

GetDataMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected