Correct indent for printing

This commit is contained in:
trotFunky 2019-05-21 12:48:08 +02:00
parent 19f7a90a8c
commit 49b815a6db
7 changed files with 24 additions and 9 deletions

View file

@ -40,7 +40,6 @@ endif()
add_executable(compte_mots compte_mots.cpp) add_executable(compte_mots compte_mots.cpp)
add_library(polynomial SHARED Polynomial.cpp Polynomial.tpp) add_library(polynomial SHARED Polynomial.cpp Polynomial.tpp)
#target_link_libraries(polynomial -static)
if(GTest_FOUND) if(GTest_FOUND)
add_executable(polynomialTest gTestPolynomial.cpp) add_executable(polynomialTest gTestPolynomial.cpp)

View file

@ -42,9 +42,14 @@ namespace xmlParser
shape->setPosition(x-r,y-r); shape->setPosition(x-r,y-r);
} }
const std::string Circle::toString() const const std::string Circle::toString(int indent) const
{ {
std::stringstream string; std::stringstream string;
for(int i = 0;i<indent;i++)
{
string << "\t";
}
string << label << " at x:" << getX() << " y:" << getY() << " | r:" << getR(); string << label << " at x:" << getX() << " y:" << getY() << " | r:" << getR();
string << " color:" << getStringColor(); string << " color:" << getStringColor();
return(string.str()); return(string.str());

View file

@ -31,7 +31,7 @@ namespace xmlParser
float getR() const; float getR() const;
void setR(float newR); void setR(float newR);
const std::string toString() const override; const std::string toString(int indent) const override;
private: private:
float r; float r;
}; };

View file

@ -83,9 +83,14 @@ namespace xmlParser
color = strToColor(stringColor); color = strToColor(stringColor);
} }
const std::string DrawingElement::toString() const const std::string DrawingElement::toString(int indent) const
{ {
std::stringstream string; std::stringstream string;
for(int i = 0;i<indent;i++)
{
string << "\t";
}
string << label << " at x:" << getX() << " y:" << getY(); string << label << " at x:" << getX() << " y:" << getY();
string << " | color:" << getStringColor(); string << " | color:" << getStringColor();
return(string.str()); return(string.str());
@ -93,7 +98,7 @@ namespace xmlParser
std::ostream& operator<<(std::ostream& ostream, const DrawingElement& element) std::ostream& operator<<(std::ostream& ostream, const DrawingElement& element)
{ {
ostream << element.toString(); ostream << element.toString(0);
return(ostream); return(ostream);
} }
} }

View file

@ -20,6 +20,7 @@ namespace xmlParser
{ {
public: public:
// TODO : S'arranger pour n'avoir que des constructeurs sensés : pas de constructeur vide/résultat non évident
explicit DrawingElement(std::string label = "Test DrawingElement", float x = 0, float y = 1, explicit DrawingElement(std::string label = "Test DrawingElement", float x = 0, float y = 1,
const sf::Color& = sf::Color::Yellow); const sf::Color& = sf::Color::Yellow);
@ -41,7 +42,7 @@ namespace xmlParser
void setColor(const sf::Color& newColor); void setColor(const sf::Color& newColor);
void setColor(const std::string& stringColor); void setColor(const std::string& stringColor);
virtual const std::string toString() const; virtual const std::string toString(int indent) const;
friend std::ostream& operator<<(std::ostream&,const DrawingElement&); friend std::ostream& operator<<(std::ostream&,const DrawingElement&);

View file

@ -69,15 +69,20 @@ namespace xmlParser
} }
} }
const std::string Group::toString() const const std::string Group::toString(int indent) const
{ {
std::stringstream string; std::stringstream string;
for(int i = 0;i<indent;i++)
{
string << "\t";
}
string << label << " at x:" << getX() << " y:" << getY(); string << label << " at x:" << getX() << " y:" << getY();
string << " color:" << getStringColor() << std::endl; string << " color:" << getStringColor() << std::endl;
for(const auto& element : drawingElements) for(const auto& element : drawingElements)
{ {
string << "\t" << *(element.second) << std::endl; string << element.second->toString(indent+1) << std::endl;
} }
return(string.str()); return(string.str());
} }

View file

@ -34,7 +34,7 @@ namespace xmlParser
void draw(sf::RenderWindow&) override; void draw(sf::RenderWindow&) override;
const std::string toString() const override; const std::string toString(int indent) const override;
private: private:
std::map<std::string,DrawingElement*> drawingElements; std::map<std::string,DrawingElement*> drawingElements;
}; };