Merge "[apps] Rule of 5 (2)"

This commit is contained in:
Émilie Feral
2017-05-09 14:19:24 +02:00
committed by Gerrit
7 changed files with 43 additions and 11 deletions

View File

@@ -9,7 +9,7 @@ namespace Graph {
App::App(Container * container, Context * context) :
FunctionApp(container, &m_inputViewController, I18n::Message::FunctionApp, I18n::Message::FunctionAppCapital, ImageStore::GraphIcon),
m_functionStore(CartesianFunctionStore()),
m_functionStore(),
m_xContext(VariableContext('x', context)),
m_listController(ListController(&m_listFooter, &m_functionStore, &m_listHeader, &m_listFooter)),
m_listFooter(ButtonRowController(&m_listHeader, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey)),

View File

@@ -40,7 +40,7 @@ CartesianFunction * CartesianFunctionStore::addEmptyFunction() {
assert(m_numberOfFunctions < k_maxNumberOfFunctions);
const char * name = firstAvailableName();
KDColor color = firstAvailableColor();
CartesianFunction addedFunction = CartesianFunction(name, color);
CartesianFunction addedFunction(name, color);
m_functions[m_numberOfFunctions] = addedFunction;
CartesianFunction * result = &m_functions[m_numberOfFunctions];
m_numberOfFunctions++;
@@ -57,7 +57,8 @@ void CartesianFunctionStore::removeFunction(Shared::Function * f) {
for (int j = i; j<m_numberOfFunctions; j++) {
m_functions[j] = m_functions[j+1];
}
m_functions[m_numberOfFunctions] = CartesianFunction("", KDColorBlack);
CartesianFunction emptyFunction("", KDColorBlack);
m_functions[m_numberOfFunctions] = emptyFunction;
}
int CartesianFunctionStore::maxNumberOfFunctions() {
@@ -102,7 +103,8 @@ const KDColor CartesianFunctionStore::firstAvailableColor() {
void CartesianFunctionStore::removeAll() {
for (int i = 0; i < m_numberOfFunctions; i++) {
m_functions[i] = CartesianFunction("", KDColorBlack);
CartesianFunction emptyFunction("", KDColorBlack);
m_functions[i] = emptyFunction;
}
m_numberOfFunctions = 0;
addEmptyFunction();

View File

@@ -62,6 +62,17 @@ Sequence::~Sequence() {
}
}
Sequence& Sequence::operator=(const Sequence& other) {
// Self-assignment is benign
Function::operator=(other);
setType(other.m_type);
setFirstInitialConditionContent(other.m_firstInitialConditionText);
setSecondInitialConditionContent(other.m_secondInitialConditionText);
m_indexBuffer[0] = other.m_indexBuffer[0];
m_indexBuffer[1] = other.m_indexBuffer[1];
return *this;
}
const char * Sequence::firstInitialConditionText() {
return m_firstInitialConditionText;
}

View File

@@ -14,6 +14,10 @@ public:
};
Sequence(const char * text = nullptr, KDColor color = KDColorBlack);
~Sequence();
Sequence& operator=(const Sequence& other);
Sequence& operator=(Sequence&& other) = delete;
Sequence(const Sequence& other) = delete;
Sequence(Sequence&& other) = delete;
Type type();
void setType(Type type);
const char * firstInitialConditionText();

View File

@@ -33,7 +33,7 @@ Sequence * SequenceStore::addEmptyFunction() {
assert(m_numberOfFunctions < k_maxNumberOfSequences);
const char * name = firstAvailableName();
KDColor color = firstAvailableColor();
Sequence addedSequence = Sequence(name, color);
Sequence addedSequence(name, color);
m_sequences[m_numberOfFunctions] = addedSequence;
Sequence * result = &m_sequences[m_numberOfFunctions];
m_numberOfFunctions++;
@@ -50,7 +50,8 @@ void SequenceStore::removeFunction(Shared::Function * f) {
for (int j = i; j<m_numberOfFunctions; j++) {
m_sequences[j] = m_sequences[j+1];
}
m_sequences[m_numberOfFunctions] = Sequence("", KDColorBlack);
Sequence emptySequence("", KDColorBlack);
m_sequences[m_numberOfFunctions] = emptySequence;
}
int SequenceStore::maxNumberOfFunctions() {
@@ -95,7 +96,8 @@ const KDColor SequenceStore::firstAvailableColor() {
void SequenceStore::removeAll() {
for (int i = 0; i < m_numberOfFunctions; i++) {
m_sequences[i] = Sequence("", KDColorBlack);
Sequence emptySequence("", KDColorBlack);
m_sequences[i] = emptySequence;
}
m_numberOfFunctions = 0;
}

View File

@@ -6,16 +6,25 @@ using namespace Poincare;
namespace Shared {
Function::Function(const char * text, KDColor color) :
Function::Function(const char * name, KDColor color) :
m_expression(nullptr),
m_text{0},
m_name(text),
m_name(name),
m_color(color),
m_layout(nullptr),
m_active(true)
{
}
Function& Function::operator=(const Function& other) {
// Self-assignment is benign
m_color = other.m_color;
m_name = other.m_name;
m_active = other.m_active;
setContent(other.m_text);
return *this;
}
void Function::setContent(const char * c) {
strlcpy(m_text, c, sizeof(m_text));
if (m_expression != nullptr) {

View File

@@ -9,8 +9,12 @@ namespace Shared {
class Function {
public:
Function(const char * text = nullptr, KDColor color = KDColorBlack);
~Function(); // Delete expression and layout, if needed
Function(const char * name = nullptr, KDColor color = KDColorBlack);
virtual ~Function(); // Delete expression and layout, if needed
Function& operator=(const Function& other);
Function& operator=(Function&& other) = delete;
Function(const Function& other) = delete;
Function(Function&& other) = delete;
const char * text();
const char * name();
KDColor color() const { return m_color; }