/* * geometric_object-test.cc 2013-08-26 */ #include "Geometric_Object.h" #include "Serializeable.h" #include #include #include #include #include using namespace std; int main() { vector objects{ new Point{ 1.0, 1.0 }, new Line{ -1.0, -1.0, 1.0, 1.0 }, new Circle{ 3.0 }, new Circular_Cylinder{ 3.0, 10.0 }, new Rectangle{ 4.0, 5.0 }, new Rectangular_Parallelepiped{ 4.0, 5.0, 10.0 }, new Triangle{ 3.0, 4.0, 5.0 }, new Triangular_Prism{ 3, 4.0, 5.0, 10.0 }, new Triangle{ 1.0, 1.0, 1.414 } }; for (auto obj : objects) { Cloneable* copy{ obj->clone() }; if (copy != nullptr) { cout << endl << "Type......: " << typeid(*copy).name() << endl; Line* line{ dynamic_cast(copy) }; if (line) { cout << "Length....: " << line->get_length() << endl; } Plane* plane{ dynamic_cast(copy) }; if (plane) { cout << "Area......: " << plane->get_area() << endl; cout << "Profile...: " << plane->get_profile() << endl; } Solid* solid{ dynamic_cast(copy) }; if (solid) { cout << "Volyme....: " << solid->get_volume() << endl; } Serializeable* serializeable{ dynamic_cast(copy) }; if (serializeable != nullptr) { cout << "Serialized: " << serializeable->str() << endl; } delete copy; } } cout << endl; transform(begin(objects), end(objects), begin(objects), [](Geometric_Object* p){ delete p; return nullptr; }); for_each(begin(objects), end(objects), [](Geometric_Object*& p){ delete p; p = nullptr; }); return 0; }