summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2015-05-01 18:19:32 +0200
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2015-05-01 18:19:32 +0200
commit01b25accba1a5329e220aa647255d2c2b284c16e (patch)
tree85fe233359934295830ee7b109d0cbb908a7d66a
parent40d48a2d4f477beec0e387114f4335ab1aab1ab6 (diff)
Add operator overload squeleton
-rw-r--r--src/Model/CMakeLists.txt2
-rw-r--r--src/Model/Cell.hpp30
-rw-r--r--src/Model/Elements/StringElement.cpp25
-rw-r--r--src/Model/Elements/StringElement.hpp3
-rw-r--r--src/main.cpp15
5 files changed, 66 insertions, 9 deletions
diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt
index 284be94..80ea875 100644
--- a/src/Model/CMakeLists.txt
+++ b/src/Model/CMakeLists.txt
@@ -1,5 +1,5 @@
#Make Model lib
-add_library(Model Grid.cpp Game.cpp)
+add_library(Model Grid.cpp Game.cpp )
target_link_libraries(Model Elements)
diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp
index 7638c4e..cb4bc21 100644
--- a/src/Model/Cell.hpp
+++ b/src/Model/Cell.hpp
@@ -24,35 +24,51 @@ template<class T> class Cell
m_Element->setValue(value);
}
+
//Destructor
~Cell()
{
delete m_Element;
}
-
+ //Test if the cell is empty
bool isEmpty()
{
return true;
}
- std::string getElementValue()
- {
- return m_Element->getValue();
+ T getElement(){
+ return this->m_Element;
}
- bool equals(Cell *otherCell)
- {
+ bool equals(Cell<T> *cell){
+ /*if(cell->getElement() == this->m_Element){
+ return true;
+ }*/
return true;
}
+ //Return the element value
+ std::string getElementValue()
+ {
+ return m_Element->getValue();
+ }
+
+
// Description
std::string description()
{
return m_Element->description();
}
-
+
};
+
+
+template<class T>
+bool operator==(Cell<T> a, Cell<T> b){
+ return true;
+}
+
#endif
diff --git a/src/Model/Elements/StringElement.cpp b/src/Model/Elements/StringElement.cpp
index f93fe3b..fbf57c1 100644
--- a/src/Model/Elements/StringElement.cpp
+++ b/src/Model/Elements/StringElement.cpp
@@ -2,7 +2,7 @@
StringElement::StringElement(){
- this->m_value=".";
+ this->m_value="";
}
StringElement::~StringElement(){
@@ -20,5 +20,28 @@ void StringElement::setValue(std::string value){
}
std::string StringElement::description(){
+ if(this->m_value==""){
+ return " ";
+ }
return this->m_value;
}
+
+bool StringElement::isEmpty(){
+ if(this->m_value==""){
+ return true;
+ }
+
+ return false;
+}
+bool StringElement::equals(StringElement const& element) const{
+ if(this->m_value.compare(element.m_value) == 0){
+ return true;
+ }
+
+ return true;
+}
+
+bool operator==(StringElement const& a, StringElement const& b){
+ return a.equals(b);
+}
+
diff --git a/src/Model/Elements/StringElement.hpp b/src/Model/Elements/StringElement.hpp
index db40f58..16946a8 100644
--- a/src/Model/Elements/StringElement.hpp
+++ b/src/Model/Elements/StringElement.hpp
@@ -20,7 +20,10 @@ class StringElement
std::string getValue();
void setValue(std::string value);
+ bool isEmpty();
+ bool equals(StringElement const& element) const;
std::string description();
+
};
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 26062a9..217fe81 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -10,11 +10,26 @@
#include "./Controllers/ConsoleController/ConsoleController.hpp"
//-----------------------------
+#include "./Model/Cell.hpp"
+//#include "./Model/Elements/StringElement.hpp"
//----- Start -----
+
+
int main()
{
+ Cell<StringElement> cell1("loic");
+ Cell<StringElement> cell2("loic");
+
+
+ if(cell1==cell2){
+ std::cout << "Egale" << std::endl;
+ }
+ else{
+ std::cout << "Différent" << std::endl;
+ }
+
//Init random
srand(time(NULL));