![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2005 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: derivedSRUserExt.h,v $ $Revision: 1.4 $ $State: Exp $ 00007 *******************************************************************************/ 00008 00009 #ifndef DerivedSRUserExtension_H_ 00010 #define DerivedSRUserExtension_H_ 00011 00012 #include "vrfobjparam/vrfSRUserExt.h" 00013 #include "vrfutil/rwString.h" 00014 00015 //class DerivedSRUserExtension: 00016 // 00017 //Instances of DerivedSRUserExtension are an example of an extension to 00018 //a base state repository class. It provides a way to extend an entity's state 00019 //information independent at a lower level in the state repository hierarchy. 00020 //All entities in VR-Forces have at a minimum a DtVrfObjectStateRepsitory, which 00021 //can be extended in this way. By extending a state repository through the 00022 //DtVrfStateRepostioryUserExtension class, you don't have to extend multiple 00023 //leaf-level state repository classes to add the same kind of extension 00024 //to different kinds of entities (e.g. ground vehicles and air entities, both 00025 //of which have different derived state repository classes). 00026 // 00027 //A state repository extension object (DtVrfStateRepositoryUserExtension) can be 00028 //initialized from a parameter database, and then saved/restored as part of an 00029 //entity's state in an order of battle file. 00030 // 00031 //This example of a user-defined state repository extensions class contains a 00032 //single new data member, myTag (a new kind of identifier). The myTag member 00033 //variable is a readable, writeable string (DtRwString). myTag is registered 00034 //with the name "my-tag" in this class' constructor. 00035 // 00036 //The class returns a new type string "my-state-repository-user-extension". 00037 //This is the key that gets registered with the factory so VR-Forces will 00038 //know how to create an instance of this class when it encounters it in 00039 //a parameter database file. The configuration of an instance of this type of 00040 //state repository extension in a parameter database file (an .ope file) would 00041 //look something like this: 00042 // 00043 //(state-repository-extension-type "my-state-repository-user-extension") 00044 //(user-extension 00045 // (my-tag "some-useful-info") 00046 //) 00047 // 00048 //At runtime, you can access the state repository extension through the 00049 //entity's state repository member, e.g. 00050 // 00051 //DtVrfObject* entity; 00052 //DerivedSRUserExtension* userSRExtension = 00053 //dynamic_cast<DerivedSRUserExtension*>(entity->vrfState()->userExtension()); 00054 00055 class DerivedSRUserExtension : public DtVrfStateRepositoryUserExtension 00056 { 00057 public: 00058 00059 //constructor 00060 DerivedSRUserExtension(DtVrfObjectStateRepository* stateRepository, 00061 const DtString& rwName = DtString::nullString(), 00062 DtReaderWriterRegistry* parentRegistry = 0); 00063 00064 //copy constructor 00065 DerivedSRUserExtension(DtVrfObjectStateRepository* stateRepository, 00066 const DerivedSRUserExtension& orig, 00067 const DtString& rwName = DtString::nullString(), 00068 DtReaderWriterRegistry* parentRegistry = 0); 00069 00070 //assignment 00071 const DerivedSRUserExtension& operator=( 00072 const DerivedSRUserExtension& orig); 00073 00074 //destructor 00075 virtual ~DerivedSRUserExtension(); 00076 00077 //Note you must implement the clone function in derived classes to ensure 00078 //that this data is initialized from the parameter database correctly. 00079 virtual DtVrfStateRepositoryUserExtension* clone( 00080 DtVrfObjectStateRepository* stateRepository, 00081 const DtString& name, 00082 DtReaderWriterRegistry* parentRegistry = NULL) const; 00083 00084 //Type of extension object to create. Existing type(s) are defined in 00085 //derivedSRUserExtTypes.h. Our new class returns the string 00086 //"my-state-repository-user-extension". This is the string that must be 00087 //registered with the factory that creates these objects, and specified in 00088 //in the parameter database file when we want one of these classes instantiated. 00089 virtual DtString type() const; 00090 00091 //Called after object has been created by the DtVrfObjectStateRepository class. 00092 virtual void init(); 00093 00094 //Specific user data extensions. In this case, its a readable writeable string 00095 //with the DtReaderWriter name 'my-tag'. 00096 virtual void setTag(const DtString& tag); 00097 virtual const DtString& tag() const; 00098 00099 //Returns newly created instance of this class. 00100 static DtVrfStateRepositoryUserExtension* create( 00101 DtVrfObjectStateRepository* stateRepository, 00102 const DtString& rwName = DtString::nullString(), 00103 DtReaderWriterRegistry* parentRegistry = 0); 00104 00105 protected: 00106 00107 DtRwString myTag; 00108 }; 00109 00110 #endif