scene_object.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef RVE_RENDER_CLIENT_SCENE_OBJECT_H
00031 #define RVE_RENDER_CLIENT_SCENE_OBJECT_H
00032 
00033 #include "forwards.h"
00034 
00035 #include <rve_common/uuid.h>
00036 #include <rve_common/forwards.h>
00037 
00038 #include <vector>
00039 #include <string>
00040 
00041 namespace rve_render_client
00042 {
00043 
00044 class Scene;
00045 
00046 class SceneObject
00047 {
00048 protected:
00049   struct ContextInfo
00050   {
00051     Scene* scene;
00052     ClientContext* context;
00053     std::vector<InterfaceHandle> interfaces;
00054 
00055     bool operator==(const ContextInfo& rhs)
00056     {
00057       return scene == rhs.scene && context == rhs.context;
00058     }
00059   };
00060   typedef std::vector<ContextInfo> V_ContextInfo;
00061 
00062 public:
00063   void create(Scene* scene, ClientContext* context);
00064   void destroy(Scene* scene, ClientContext* context);
00065 
00066   virtual void doCreate(ContextInfo& context) = 0;
00067   virtual void doDestroy(ContextInfo& context) = 0;
00068 
00069   typedef std::vector<rve_common::UUID> V_UUID;
00070   virtual void getContextDependencies(V_UUID& deps) = 0;
00071 
00072   void removeFromAll();
00073 
00074   virtual bool addToRegistry( rve_common::RegistryPtr registry, rve_common::RegistrantWPtr registrant ) = 0;
00075   virtual bool removeFromRegistry( rve_common::RegistryPtr registry, rve_common::RegistrantWPtr registrant ) = 0;
00076 
00077 protected:
00078 
00079   const rve_common::UUID& getSceneID(Scene* scene);
00080 
00081   template<typename T>
00082   T* getProxy(const ContextInfo& info, uint32_t proxy_index)
00083   {
00084     return static_cast<T*>(getProxy(info, proxy_index));
00085   }
00086 
00087   V_ContextInfo& getContexts() { return contexts_; }
00088 
00089   uint32_t addProxy(const std::string& name);
00090 
00091   template<typename F>
00092   void forEachContext(F f)
00093   {
00094     V_ContextInfo::iterator it = contexts_.begin();
00095     V_ContextInfo::iterator end = contexts_.end();
00096     for (; it != end; ++it)
00097     {
00098       ContextInfo& info = *it;
00099       f(info);
00100     }
00101   }
00102 
00103   template<typename P, typename F>
00104   void multiplex(F f, uint32_t proxy_index)
00105   {
00106     V_ContextInfo::iterator it = contexts_.begin();
00107     V_ContextInfo::iterator end = contexts_.end();
00108     for (; it != end; ++it)
00109     {
00110       ContextInfo& info = *it;
00111       P* proxy = getProxy<P>(info, proxy_index);
00112       f(proxy, getSceneID(info.scene));
00113     }
00114   }
00115 
00116 private:
00117 
00118   void* getProxy(const ContextInfo& info, uint32_t proxy_index);
00119   void lookupProxy(ContextInfo& info, const std::string& name);
00120 
00121   V_ContextInfo contexts_;
00122   std::vector<std::string> proxies_;
00123 };
00124 
00125 void destroySceneObject(SceneObject* obj);
00126 
00127 }
00128 
00129 #endif // RVE_RENDER_CLIENT_SCENE_OBJECT_H


rve_render_client
Author(s): Josh Faust
autogenerated on Wed Dec 11 2013 14:31:32