//=============================================== struct GDuration { int m_delayMs; }; //=============================================== void GTest::runPhilo(int _argc, char** _argv) { auto d = GDuration{}; d.m_delayMs = 1000; auto lTimeout = 1000; d.m_delayMs = lTimeout; } //===============================================
//=============================================== struct GDuration2 { std::chrono::milliseconds m_delayMs; }; //=============================================== void GTest::runPhilo(int _argc, char** _argv) { using namespace std::literals::chrono_literals; auto d = GDuration2{}; d.m_delayMs = 1000ms; auto lTimeout = 1s; d.m_delayMs = lTimeout; } //===============================================
//=============================================== struct GDuration2 { std::chrono::milliseconds m_delayMs; }; //=============================================== void GTest::runPhilo(int _argc, char** _argv) { using namespace std::literals::chrono_literals; auto lDuration = GDuration2{}; lDuration.m_delayMs = std::chrono::milliseconds(1000); auto lTimeout = std::chrono::seconds(1); lDuration.m_delayMs = lTimeout; } //===============================================
//=============================================== int GDot::countDot(const char* _str, std::size_t _size) { int count = 0; for (std::size_t i = 0; i < _size; ++i) { if(_str[i] == '.') count++; } return count; } //=============================================== void GTest::runPhilo(int _argc, char** _argv) { GDot lDot; const char* lMsg = "Bonjour.Tout.Le.Monde."; int lCount = lDot.countDot(lMsg, strlen(lMsg)); std::cout << lCount << "\n"; } //===============================================
//=============================================== int GDot2::countDot(const std::string_view& _str) { return std::count(std::begin(_str), std::end(_str), '.'); } //=============================================== void GTest::runPhilo(int _argc, char** _argv) { GDot2 lDot; int lCount = lDot.countDot("Bonjour.Tout.Le.Monde."); std::cout << lCount << "\n"; } //===============================================
//=============================================== std::ostream& operator<<(std::ostream& _stream, const GPerson& _person); //=============================================== std::ostream& operator<<(std::ostream& _stream, const GPerson& _person) { _stream << "id : " << _person.getId() << "\n"; _stream << "nom : " << _person.getName() << "\n"; return _stream; } //=============================================== void GTest::runOcp(int _argc, char** _argv) { GPerson lPerson; lPerson.setId(123); lPerson.setName("Gerard"); std::cout << lPerson; } //===============================================
//=============================================== class GPerson2 { public: GPerson2(); ~GPerson2(); void setId(int _id); void setName(const GString& _name); friend std::ostream& operator<<(std::ostream& _stream, const GPerson2& _person); private: int m_id; GString m_name; }; //=============================================== void GPerson2::setId(int _id) { m_id = _id; } //=============================================== void GPerson2::setName(const GString& _name) { m_name = _name; } //=============================================== std::ostream& operator<<(std::ostream& _stream, const GPerson2& _person) { _stream << "id : " << _person.m_id << "\n"; _stream << "nom : " << _person.m_name << "\n"; return _stream; } //=============================================== void GTest::runOcp(int _argc, char** _argv) { GPerson2 lPerson; lPerson.setId(123); lPerson.setName("Gerard"); std::cout << lPerson; } //===============================================
//=============================================== class GRectangle { public: GRectangle(); virtual ~GRectangle() = default; virtual double getArea() const; virtual void setWidth(double _width); virtual void setHeight(double _height); private: double m_width; double m_height; }; //=============================================== class GSquare : public GRectangle { public: GSquare(); double getArea() const override; void setWidth(double _width) override; void setHeight(double _height) override; }; //=============================================== double GRectangle::getArea() const { return m_width * m_height; } //=============================================== void GRectangle::setWidth(double _width) { m_width = _width; } //=============================================== void GRectangle::setHeight(double _height) { m_height = _height; } //=============================================== double GSquare::getArea() const { return GRectangle::getArea(); } //=============================================== void GSquare::setWidth(double _width) { GRectangle::setWidth(_width); GRectangle::setHeight(_width); } //=============================================== void GSquare::setHeight(double _height) { setWidth(_height); } //=============================================== void GTest::runLsp(int _argc, char** _argv) { GRectangle lRect; lRect.setWidth(4); lRect.setHeight(3); std::cout << "aire rectangle : " << lRect.getArea() << "\n"; GSquare lSquare; lSquare.setWidth(4); std::cout << "aire carré : " << lSquare.getArea() << "\n"; } //===============================================
//=============================================== class GFoodProcessorI { public: virtual ~GFoodProcessorI() = default; virtual void blend() = 0; }; //=============================================== class GBlend : public GFoodProcessorI { public: GBlend(); void blend() override; }; //=============================================== void GBlend::blend() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GTest::runIsp(int _argc, char** _argv) { GBlend lBlend; lBlend.blend(); } //===============================================
//=============================================== class GFoodProcessorI2 { public: virtual ~GFoodProcessorI2() = default; virtual void blend() = 0; virtual void slice() = 0; virtual void dice() = 0; }; //=============================================== class GFood : public GFoodProcessorI2 { public: GFood(); void blend() override; void slice() override; void dice() override; }; //=============================================== void GFood::blend() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GFood::slice() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GFood::dice() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GTest::runIsp(int _argc, char** _argv) { GFood lFood; lFood.blend(); lFood.slice(); lFood.dice(); } //===============================================
//=============================================== class GBlendI { public: virtual ~GBlendI() = default; virtual void blend() = 0; }; //=============================================== class GFoodI { public: virtual ~GFoodI() = default; virtual void slice() = 0; virtual void dice() = 0; }; //=============================================== class GBlend2 : public GBlendI { public: GBlend2(); void blend() override; }; //=============================================== class GFood2 : public GBlendI, public GFoodI { public: GFood2(); void blend() override; void slice() override; void dice() override; }; //=============================================== void GBlend2::blend() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GFood2::blend() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GFood2::slice() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GFood2::dice() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GTest::runIsp(int _argc, char** _argv) { GBlend2 lBlend; lBlend.blend(); GFood2 lFood; lFood.blend(); lFood.slice(); lFood.dice(); } //===============================================
//=============================================== class GBackend { public: GBackend(); void developBackend(); }; //=============================================== class GFrontend { public: GFrontend(); void developFrontend(); }; //=============================================== class GProject { public: GProject(); void deliver(); private: GBackend m_backend; GFrontend m_frontend; }; //=============================================== void GBackend::developBackend() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GFrontend::developFrontend() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GProject::deliver() { printf("%s...\n", __PRETTY_FUNCTION__); m_backend.developBackend(); m_frontend.developFrontend(); } //=============================================== void GTest::runDip(int _argc, char** _argv) { GProject lProject; lProject.deliver(); } //===============================================
//=============================================== class GDeveloper { public: virtual ~GDeveloper() = default; virtual void develop() = 0; }; //=============================================== class GBackend2 : public GDeveloper { public: GBackend2(); void develop() override; private: void developBackend(); }; //=============================================== class GFrontend2 : public GDeveloper { public: GFrontend2(); void develop() override; private: void developFrontend(); }; //=============================================== class GProject2 { public: using GDeveloperPtr = std::unique_ptr<GDeveloper>; using GDeveloperMap = std::vector<GDeveloperPtr>; public: GProject2(); void addDeveloper(GDeveloperPtr _developer); void deliver(); private: GDeveloperMap m_developers; }; //=============================================== void GFrontend2::develop() { printf("%s...\n", __PRETTY_FUNCTION__); developFrontend(); } //=============================================== void GFrontend2::developFrontend() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GBackend2::develop() { printf("%s...\n", __PRETTY_FUNCTION__); developBackend(); } //=============================================== void GBackend2::developBackend() { printf("%s...\n", __PRETTY_FUNCTION__); } //=============================================== void GProject2::addDeveloper(GDeveloperPtr _developer) { m_developers.push_back(std::move(_developer)); } //=============================================== void GProject2::deliver() { printf("%s...\n", __PRETTY_FUNCTION__); for (auto& lDeveloper : m_developers) { lDeveloper->develop(); } } //=============================================== void GTest::runDip(int _argc, char** _argv) { GProject2 lProject; GProject2::GDeveloperPtr lBackend = std::make_unique<GBackend2>(); GProject2::GDeveloperPtr lFrontend = std::make_unique<GFrontend2>(); lProject.addDeveloper(std::move(lBackend)); lProject.addDeveloper(std::move(lFrontend)); lProject.deliver(); } //===============================================