context_object_collection.cpp
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 #include <rve_render_client/context_object_collection.h>
00031 #include <rve_render_client/client_context.h>
00032 
00033 namespace rve_render_client
00034 {
00035 
00036 void destroyContextObjectCollection(ContextObjectCollection* coll)
00037 {
00038   while (!coll->contexts_.empty())
00039   {
00040     ClientContext* context = *coll->contexts_.begin();
00041     context->removeObject(coll);
00042   }
00043 
00044   delete coll;
00045 }
00046 
00047 ContextObjectCollectionPtr createContextObjectCollection()
00048 {
00049   ContextObjectCollectionPtr coll(new ContextObjectCollection, destroyContextObjectCollection);
00050   return coll;
00051 }
00052 
00053 ContextObjectCollection::ContextObjectCollection()
00054 : id_(rve_common::UUID::generate())
00055 {
00056 }
00057 
00058 void ContextObjectCollection::create(ClientContext* context)
00059 {
00060   contexts_.insert(context);
00061   S_ContextObject::iterator it = objects_.begin();
00062   S_ContextObject::iterator end = objects_.end();
00063   for (; it != end; ++it)
00064   {
00065     const ContextObjectPtr& obj = *it;
00066     obj->create(context);
00067   }
00068 }
00069 
00070 void ContextObjectCollection::destroy(ClientContext* context)
00071 {
00072   S_ContextObject::iterator it = objects_.begin();
00073   S_ContextObject::iterator end = objects_.end();
00074   for (; it != end; ++it)
00075   {
00076     const ContextObjectPtr& obj = *it;
00077     obj->destroy(context);
00078   }
00079 
00080   contexts_.erase(context);
00081 }
00082 
00083 void ContextObjectCollection::addObject(const ContextObjectPtr& obj)
00084 {
00085   objects_.insert(obj);
00086 
00087   S_Context::iterator it = contexts_.begin();
00088   S_Context::iterator end = contexts_.end();
00089   for (; it != end; ++it)
00090   {
00091     ClientContext* context = *it;
00092     obj->create(context);
00093   }
00094 }
00095 
00096 void ContextObjectCollection::removeObject(const ContextObjectPtr& obj)
00097 {
00098   S_Context::iterator it = contexts_.begin();
00099   S_Context::iterator end = contexts_.end();
00100   for (; it != end; ++it)
00101   {
00102     ClientContext* context = *it;
00103     obj->destroy(context);
00104   }
00105 
00106   objects_.erase(obj);
00107 }
00108 
00109 void ContextObjectCollection::getDependencies(V_UUID& deps)
00110 {
00111   S_ContextObject::iterator it = objects_.begin();
00112   S_ContextObject::iterator end = objects_.end();
00113   for (; it != end; ++it)
00114   {
00115     const ContextObjectPtr& obj = *it;
00116     obj->getDependencies(deps);
00117   }
00118 }
00119 
00120 }


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