added some comments for class Char, and added some TODO's

This commit is contained in:
Kjistóf 2016-10-23 15:41:32 +02:00
parent 53efe34ed1
commit bc0fc06772
3 changed files with 7 additions and 3 deletions

View File

@ -10,11 +10,11 @@ Char& Char::operator=(char other)
{ {
auto data = new char[_string.size() + 2]; // space for new char & null-terminator auto data = new char[_string.size() + 2]; // space for new char & null-terminator
std::strcpy(data, _string.c_str()); std::strcpy(data, _string.c_str());
data[_index] = other; data[_index] = other; // set the desired char
_string._str->operator--(); _string._str->operator--(); // release old StringValue
_string._str = new StringValue(data); _string._str = new StringValue(data); // make a new one
return *this; return *this;
} }

3
Char.h
View File

@ -5,6 +5,9 @@ class StringValue;
// TODO: think about making ctors explict
/* This class provides a simple wrapper for a char primitive, and implements
* copy-on-write semantics for the non-const String::operator[] via some magic */
class Char class Char
{ {
private: private:

View File

@ -6,6 +6,7 @@ class Char;
// TODO: think about making ctors explict
/* Design decisions: /* Design decisions:
* - Everything related to ref-counting is the responsibility of the StringValue class * - Everything related to ref-counting is the responsibility of the StringValue class
* - Anything dynamically allocated is owned (and thus once deleted) by the StringValue class * - Anything dynamically allocated is owned (and thus once deleted) by the StringValue class