VR-Exchange 2.1 API Documentation
tenaBroker/translatorFactory.h
Go to the documentation of this file.
1 /*********************************************************************
2  ** Copyright (c) 2005 MaK Technologies, Inc.
3  ** All rights reserved.
4  *********************************************************************/
5 /*********************************************************************
6  ** $RCSfile: translatorFactory.h,v $ $Revision: 1.6 $ $State: Exp $
7  *********************************************************************/
8 #ifndef translatorFactory_H_
9 #define translatorFactory_H_
10 
13 
14 #include "objectTrans.h"
15 #include "interactionTrans.h"
16 
17 #include <map>
18 #include <vlutil/vlPrint.h>
19 #include <vlutil/vlString.h>
20 
21 namespace MAKVrExchange { namespace DtTenaBroker {
22 
23 class DtTenaBroker;
24 
25 // \brief A factory class for Translators.
26 //
27 // DtTranslatorFactory takes on template parameter, which is the type of
28 // the class produced by the creator functions.
29 template <typename ProducedType>
31 {
32 public:
33 
34  typedef ProducedType* (*DtObjectTranslatorCreatorFunction)(DtTenaBroker *);
35  typedef ProducedType* (*DtGenericObjectTranslatorCreatorFunction)(DtTenaBroker *, const DtString &className);
36 
37 public:
38 
39  // Default CTOR
41 
42  // Default DTOR - destroys factory, not instances created by the factory.
43  virtual ~DtTranslatorFactory();
44 
45 private:
46 
47  // Copy CTOR not implemented - do not copy
49 
50  // Assignment Operator not implemented - do not copy
52 
53 
54 public:
55 
56 
57  // Creates a generic translator using the className and broker provided.
58  ProducedType *createGenericInstance(
59  const DtString &className, DtTenaBroker *broker);
60 
61  // Creats an translator instance and returns it as a pointer of type ProducedType. The
62  // translator is created using transName and the CTOR is passed the broker pointer.
63  ProducedType *createInstance(const DtString &transName, DtTenaBroker *broker) const;
64 
65 
66  // Removes the translator for class T using T::translatorName(). If there is no translator
67  // found, no action is taken.
68  template<typename T>
69  void removeCreator();
70 
71  // removes the translator creator for translatorName if one is found. If not
72  // no action is taken.
73  void removeCreator(const DtString& translatorName);
74 
75  // Sets T as the class to create when a generic Translator is requested. The default instanceFactory
76  // is used as the creator function.
77  template<typename T>
78  void addGenericCreator();
79 
80  // Adds a creator for class T using the default instanceFactory Method. The creator is
81  // locked to the name in T::translatorName. If there is already a function assigned to
82  // that name, the new function replaces the old function.
83  template<typename T>
84  void addCreator();
85 
86  // For translator translatorName a creator function fn is used. If there is already a
87  // function assigned to that name, the new function replaces the old function.
88  template<typename T>
89  void addCreator(const DtString& translatorName, DtObjectTranslatorCreatorFunction fn);
90 
92  std::set<DtString> creatorNames() const;
93 
94 protected:
95 
96  // A static function which can be used to create instances of type T.
97  template <typename T>
98  static ProducedType *instanceFactory(DtTenaBroker *broker);
99 
100  // A static function which can be used to create instances of type T, where T takes
101  // a className in the CTOR.
102  template <typename T>
103  static ProducedType *genericInstanceFactory(DtTenaBroker *broker, const DtString& className);
104 
105 protected:
106 
107  typedef std::map<DtString, DtObjectTranslatorCreatorFunction> StringOtcMap;
108 
109 protected:
110 
113 
114 };
115 
116 // A factory for object Translators
118 
119 // A Factory from Interaction Translators
121 
122 }}
123 
124 #define translatorFactory_INL_
125 #include "translatorFactory.inl"
126 #undef translatorFactory_INL_
127 
128 #endif //end #ifndef translatorFactory_H_

Document ID: Generated on Tue Aug 7 22:07:13 EDT 2012 from SVN revision 117874
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)