Compare commits
2 commits
f51d403b8e
...
5567a9910b
Author | SHA1 | Date | |
---|---|---|---|
5567a9910b | |||
004142f85a |
5 changed files with 36 additions and 23 deletions
|
@ -39,7 +39,7 @@ endif()
|
|||
|
||||
add_executable(compte_mots compte_mots.cpp)
|
||||
|
||||
add_executable(parseXML xmlParser.cpp xmlParser.h Circle.h)
|
||||
add_executable(parseXML xmlParser.cpp xmlParser.h Circle.h Circle.cpp)
|
||||
|
||||
find_path(PugiXML_INCLUDE_DIR pugixml.hpp)
|
||||
target_link_libraries(parseXML pugixml)
|
||||
|
@ -48,7 +48,7 @@ target_link_directories(parseXML PRIVATE ${PugiXML_INCLUDE_DIR})
|
|||
|
||||
|
||||
if(GTest_FOUND)
|
||||
add_executable(xmlTest gTestXMLParser.cpp Circle.h xmlParser.h xmlParser.cpp)
|
||||
add_executable(xmlTest gTestXMLParser.cpp Circle.h xmlParser.h xmlParser.cpp Circle.cpp)
|
||||
|
||||
target_include_directories(xmlTest PRIVATE ${PugiXML_INCLUDE_DIR})
|
||||
target_link_directories(xmlTest PRIVATE ${PugiXML_INCLUDE_DIR})
|
||||
|
|
15
snippets/Circle.cpp
Normal file
15
snippets/Circle.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// Created by trotfunky on 14/05/19.
|
||||
//
|
||||
|
||||
#include "Circle.h"
|
||||
|
||||
namespace xmlParser
|
||||
{
|
||||
Circle::Circle() : x(0), y(1), r(2), label("Test circle")
|
||||
{}
|
||||
|
||||
Circle::Circle(pugi::xml_node& node) : x(node.attribute("x").as_int(0)), y(node.attribute("y").as_int(1)),
|
||||
r(node.attribute("r").as_int(2)), label(node.attribute("label").as_string("Test circle"))
|
||||
{}
|
||||
}
|
|
@ -10,22 +10,17 @@
|
|||
|
||||
namespace xmlParser
|
||||
{
|
||||
typedef struct Circle
|
||||
class Circle
|
||||
{
|
||||
public:
|
||||
Circle();
|
||||
explicit Circle(pugi::xml_node&);
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int r;
|
||||
|
||||
std::string label;
|
||||
|
||||
void initCirle() { x = 0; y = 1; r = 2; label = "Test circle";}
|
||||
void initCircle(pugi::xml_node node)
|
||||
{
|
||||
x = node.attribute("x").as_int(0);
|
||||
y = node.attribute("y").as_int(1);
|
||||
r = node.attribute("r").as_int(2);
|
||||
label = node.attribute("label").as_string("Test circle");
|
||||
}
|
||||
} Circle;
|
||||
};
|
||||
}
|
||||
#endif //SNIPPETS_CIRCLE_H
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
bool equals(const Polynomial<T1>&) const;
|
||||
|
||||
template <typename T1>
|
||||
auto add(const Polynomial<T1>& operand) const -> Polynomial<decltype(static_cast<T>(0) + operand[0])>;
|
||||
auto add(const Polynomial<T1>& operand) const -> Polynomial<decltype(T{} + T1{})>;
|
||||
|
||||
template <typename T1>
|
||||
friend std::ostream& operator<<(std::ostream&, const Polynomial<T1>&);
|
||||
|
@ -62,6 +62,7 @@ private:
|
|||
template<typename T>
|
||||
Polynomial<T>::Polynomial()
|
||||
{
|
||||
// Not bad, but could be better with C++20. Not that useful either
|
||||
static_assert(std::is_arithmetic<T>::value,"Polynomial must be of an arithmetic type!");
|
||||
factors = {0};
|
||||
}
|
||||
|
@ -197,7 +198,7 @@ bool Polynomial<T>::equals(const Polynomial<T1>& operand) const
|
|||
|
||||
template<typename T>
|
||||
template<typename T1>
|
||||
auto Polynomial<T>::add(const Polynomial<T1>& operand) const -> Polynomial<decltype(static_cast<T>(0) + operand[0])>
|
||||
auto Polynomial<T>::add(const Polynomial<T1>& operand) const -> Polynomial<decltype(T{} + T1{})>
|
||||
{
|
||||
bool isLargest = true;
|
||||
|
||||
|
@ -212,7 +213,7 @@ auto Polynomial<T>::add(const Polynomial<T1>& operand) const -> Polynomial<declt
|
|||
largestSize = operand.factors.size();
|
||||
}
|
||||
|
||||
std::vector<decltype(static_cast<T>(0)+operand[0])> resultPolynomial = {};
|
||||
std::vector<decltype(T{} + T1{})> resultPolynomial = {};
|
||||
resultPolynomial.reserve(largestSize);
|
||||
|
||||
for(int i = 0;i<smallestSize;i++)
|
||||
|
@ -225,7 +226,7 @@ auto Polynomial<T>::add(const Polynomial<T1>& operand) const -> Polynomial<declt
|
|||
resultPolynomial.push_back((isLargest ? factors[i] : operand[i]));
|
||||
}
|
||||
|
||||
return Polynomial<decltype(static_cast<T>(0)+operand[0])>(resultPolynomial);
|
||||
return Polynomial<decltype(T{} + T1{})>(resultPolynomial);
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
|
||||
TEST(readXML,initEmptyCircle)
|
||||
{
|
||||
xmlParser::Circle cercle;
|
||||
cercle.initCirle();
|
||||
xmlParser::Circle cercle = xmlParser::Circle();
|
||||
|
||||
ASSERT_EQ(cercle.x,0);
|
||||
ASSERT_EQ(cercle.y,1);
|
||||
|
@ -20,9 +19,8 @@ TEST(readXML,initEmptyCircle)
|
|||
|
||||
TEST(readXML,initEmptyCirclePugiXML)
|
||||
{
|
||||
xmlParser::Circle cercle;
|
||||
xmlParser::Circle cercle = xmlParser::Circle();
|
||||
pugi::xml_node node;
|
||||
cercle.initCircle(node);
|
||||
|
||||
ASSERT_EQ(cercle.x,0);
|
||||
ASSERT_EQ(cercle.y,1);
|
||||
|
@ -39,9 +37,13 @@ TEST(readXML,parseXMLCircle)
|
|||
pugi::xml_parse_result result = doc.load_string(xml.c_str());
|
||||
EXPECT_NE(0,result);
|
||||
|
||||
xmlParser::Circle cercle;
|
||||
pugi::xml_node node = doc.child("Circle");
|
||||
xmlParser::Circle cercle = xmlParser::Circle(node);
|
||||
|
||||
cercle.initCircle(doc.child("Circle"));
|
||||
ASSERT_EQ(cercle.x,0);
|
||||
ASSERT_EQ(cercle.y,1);
|
||||
ASSERT_EQ(cercle.r,2);
|
||||
ASSERT_EQ(cercle.label,"testCircle");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue