added some comments for class Char, and added some TODO's
This commit is contained in:
parent
53efe34ed1
commit
bc0fc06772
6
Char.cpp
6
Char.cpp
@ -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
3
Char.h
@ -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:
|
||||||
|
1
String.h
1
String.h
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user