From bc0fc06772edda17bee21f3a90f5e6e100a2ae13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sun, 23 Oct 2016 15:41:32 +0200 Subject: [PATCH] added some comments for class Char, and added some TODO's --- Char.cpp | 6 +++--- Char.h | 3 +++ String.h | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Char.cpp b/Char.cpp index e610e01..ec18d74 100644 --- a/Char.cpp +++ b/Char.cpp @@ -10,11 +10,11 @@ Char& Char::operator=(char other) { auto data = new char[_string.size() + 2]; // space for new char & null-terminator std::strcpy(data, _string.c_str()); - data[_index] = other; + data[_index] = other; // set the desired char - _string._str->operator--(); - _string._str = new StringValue(data); + _string._str->operator--(); // release old StringValue + _string._str = new StringValue(data); // make a new one return *this; } \ No newline at end of file diff --git a/Char.h b/Char.h index fb5cdc4..970a9fc 100644 --- a/Char.h +++ b/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 { private: diff --git a/String.h b/String.h index 75eab5f..582b868 100644 --- a/String.h +++ b/String.h @@ -6,6 +6,7 @@ class Char; +// TODO: think about making ctors explict /* Design decisions: * - 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