typeinst.h

Go to the documentation of this file.
00001 /*
00002  * typeinst.h
00003  *
00004  * Copyright (C) 2008,2009  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  * Root header for generic types and instances.
00031  */
00032 
00033 #ifndef AESOP_TYPEINST_H__
00034 #define AESOP_TYPEINST_H__
00035 
00036 // includes --------------------------------------------------------------------
00037 #include "aesop-base/aesop-base.h"
00038 
00039 #include "datahash/datahash.h"
00040 #include "datahash/datahash_util.h"
00041 #include "geometry/placement.h"
00042 #include "story/story.h"
00043 
00044 
00045 namespace aesop {
00046 
00047 
00141 
00144 
00145 class ComponentData {
00146 public:
00147         // virtual destructor --------------------------------------------------
00148         virtual ~ComponentData(void) throw();
00149 
00150         // aesop::ComponentData class interface data ---------------------------
00151 
00153         virtual void dump(IN const char * txt) const throw();
00154 };
00155 
00156 
00157 
00173 class Instance {
00174 public:
00175         // virtual destructor --------------------------------------------------
00176         virtual ~Instance(void) throw();
00177 
00178         // aesop::Instance class interface methods -----------------------------
00179 
00181         virtual const char * getInstanceId(void) const throw() = 0;
00182 
00184         virtual const char * getTypeId(void) const throw() = 0;
00185         
00187         virtual placement_t& getPlacement(void) throw() = 0;
00188 
00191         virtual void setComponentData(IN const char * componentName,
00192                                 IN smart_ptr<ComponentData>& data) = 0;
00193 
00195         virtual smart_ptr<ComponentData> getComponentData(
00196                                 IN const char * componentName) = 0;
00197 
00199         virtual const Datahash * getTypeComponentData(
00200                                 IN const char * componentName) = 0;
00201 
00204         virtual void setInstanceData(IN const char * componentName,
00205                                 IN smart_ptr<Datahash>& data) = 0;
00206 
00211         virtual smart_ptr<Datahash> getInstanceData(
00212                                 IN const char * componentName) = 0;
00213 
00215         virtual void dump(IN const char * txt) throw() = 0;
00216 
00217         // static factory methods ----------------------------------------------
00218         static smart_ptr<Instance> parse(IO std::istream& stream);
00219         static smart_ptr<Instance> create(IN const char * instanceId,
00220                                 IN const char * typeId);
00221 };
00222 
00223 
00224 
00226 typedef std::vector<smart_ptr<Instance> > vec_instance_t;
00227 
00228 
00230 typedef void (*instance_iteration_fn)(IN smart_ptr<Instance>& instance,
00231                                 IN void * context);
00232 
00233 
00234 
00245 class TypeComponentLoader {
00246 public:
00247         // virtual destructor --------------------------------------------------
00248         virtual ~TypeComponentLoader(void) throw();
00249 
00250         // aesop::TypeComponentLoader class interface methods -----------------
00251 
00253         virtual const char * getComponentName(void) const throw() = 0;
00254 
00256         virtual const char * getLoaderName(void) const throw() = 0;
00257 
00259         virtual bool isMyFormat(IN const Datahash * componentData,
00260                                 IN const char * path) const = 0;
00261 
00263         virtual smart_ptr<ComponentData> loadTS(
00264                                 IN smart_ptr<Instance>& instance,
00265                                 IN const Datahash * componentData,
00266                                 IN const char * path) = 0;
00267 };
00268 
00269 
00271 void initializeTypeInstanceLibrary(IN smart_ptr<story::Story>& story);
00272 
00273 
00276 void registerTypeComponentLoader(IN smart_ptr<aesop::TypeComponentLoader>& tcl);
00277 
00278 
00279 
00281 void loadInstances(IO std::istream& stream,
00282                                 OUT vec_instance_t& instances);
00283 
00284 
00285 
00293 const char * getKeyWithOverrides(IN const char * keyName,
00294                                 IN const Datahash * instanceData,
00295                                 IN const Datahash * typeData,
00296                                 IN const Datahash * modelData,
00297                                 IN eDatahash_Flag flag);
00298 
00299 
00300 };      // aesop namespace
00301 
00302 #endif  // AESOP_TYPEINST_H__
00303