diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-17 14:16:33 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-21 16:15:35 +0100 |
commit | c3c692d26e2d6976afa226a3f49e1745e94712e7 (patch) | |
tree | 2ecb64587c5a2250b9c3f6f95cff1f068c2e0970 /examples/samplebinding/truck.h | |
parent | ec7ad296f48f3f1856c3eb7cc3685249a096d6b8 (diff) |
Polish the samplebinding example
- Use a std::shared_ptr for internal storage.
- Simplify copy and assignment.
- Fix constness of the flavor accessor
- Add ostream operator to IceCream
Pick-to: 6.2
Change-Id: I814fa14095cbb96ab5642735e16b8b50101d4771
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'examples/samplebinding/truck.h')
-rw-r--r-- | examples/samplebinding/truck.h | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/examples/samplebinding/truck.h b/examples/samplebinding/truck.h index 742b232eb..e59b365a4 100644 --- a/examples/samplebinding/truck.h +++ b/examples/samplebinding/truck.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt for Python examples of the Qt Toolkit. @@ -51,14 +51,16 @@ #ifndef TRUCK_H #define TRUCK_H -#include <vector> - #include "icecream.h" #include "macros.h" -class BINDINGS_API Truck { +#include <memory> +#include <vector> + +class BINDINGS_API Truck +{ public: - Truck(bool leaveOnDestruction = false); + explicit Truck(bool leaveOnDestruction = false); Truck(const Truck &other); Truck& operator=(const Truck &other); Truck(Truck &&other); @@ -79,11 +81,13 @@ public: std::string getArrivalMessage() const; private: - void clearFlavors(); + using IcecreamPtr = std::shared_ptr<Icecream>; + + void assign(const Truck &other); bool m_leaveOnDestruction = false; std::string m_arrivalMessage = "A new icecream truck has arrived!\n"; - std::vector<Icecream *> m_flavors; + std::vector<IcecreamPtr> m_flavors; }; #endif // TRUCK_H |