diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-07-07 04:23:05 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-07-07 04:23:05 +0000 |
commit | 81c84a38992ce8e38106d86ce85ac3e88ed91a31 (patch) | |
tree | 08fb5913e141b7e208737b799b45921d477d45cc /libdimensionxx/dimensionxx/scene.hpp | |
parent | d7b7b4b3391cf99ca63d8311eac3957df7a862ed (diff) | |
download | dimension-81c84a38992ce8e38106d86ce85ac3e88ed91a31.tar.xz |
Add shallow copy semantics to Camera's, Object's, and Scene's.
Diffstat (limited to 'libdimensionxx/dimensionxx/scene.hpp')
-rw-r--r-- | libdimensionxx/dimensionxx/scene.hpp | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/libdimensionxx/dimensionxx/scene.hpp b/libdimensionxx/dimensionxx/scene.hpp index 256de29..b5adde0 100644 --- a/libdimensionxx/dimensionxx/scene.hpp +++ b/libdimensionxx/dimensionxx/scene.hpp @@ -25,14 +25,20 @@ namespace Dimension { + // Iterator class for scene objects + class Scene_Iterator; + // Base scene class. Wraps a dmnsn_scene*. class Scene { public: - // Allocate a dmnsn_scene + typedef Scene_Iterator Iterator; + + // Allocate a dmnsn_scene* Scene(const Color& background, Camera& camera, Canvas& canvas); - // Wrap an existing scene - explicit Scene(dmnsn_scene* scene); + + // Scene(const Scene& scene); + // Delete the scene ~Scene(); @@ -43,7 +49,11 @@ namespace Dimension Canvas& canvas(); const Canvas& canvas() const; - // Add objects + // Object access + + Iterator begin(); + Iterator end(); + void push_object(Object& object); // Access the wrapped C object. @@ -51,13 +61,38 @@ namespace Dimension const dmnsn_scene* dmnsn() const; private: - // Copying prohibited - Scene(const Scene&); + // Copy-assignment prohibited Scene& operator=(const Scene&); - dmnsn_scene* m_scene; - Camera* m_camera; - Canvas* m_canvas; + std::tr1::shared_ptr<dmnsn_scene*> m_scene; + std::tr1::shared_ptr<Camera> m_camera; + std::tr1::shared_ptr<Canvas> m_canvas; + std::list<std::tr1::shared_ptr<Object> > m_objects; + }; + + class Scene_Iterator + { + public: + Scene_Iterator(std::list<std::tr1::shared_ptr<Object> >::iterator i) + : m_i(i) { } + // Scene_Iterator(const Scene_Iterator& i); + // ~Scene_Iterator(); + + // Scene_Iterator& operator=(const Scene_Iterator& i); + + Object& operator*() const { return **m_i; } + Object* operator->() const { return &**m_i; } + + bool operator==(Scene_Iterator i) const { return m_i == i.m_i; } + bool operator!=(Scene_Iterator i) const { return m_i != i.m_i; } + + Scene_Iterator& operator++() { ++m_i; return *this; } + Scene_Iterator operator++(int) { return Scene_Iterator(m_i++); } + Scene_Iterator& operator--() { --m_i; return *this; } + Scene_Iterator operator--(int) { return Scene_Iterator(m_i--); } + + private: + std::list<std::tr1::shared_ptr<Object> >::iterator m_i; }; } |