root/juggler/branches/1.0/Config/vjChunkFactory.h

Revision 8789, 4.4 kB (checked in by patrickh, 7 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998, 1999, 2000, 2001, 2002
4  *   by Iowa State University
5  *
6  * Original Authors:
7  *   Allen Bierbaum, Christopher Just,
8  *   Patrick Hartling, Kevin Meinert,
9  *   Carolina Cruz-Neira, Albert Baker
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *
26  * -----------------------------------------------------------------
27  * File:          $RCSfile$
28  * Date modified: $Date$
29  * Version:       $Revision$
30  * -----------------------------------------------------------------
31  *
32  *************** <auto-copyright.pl END do not edit this line> ***************/
33
34
35
36 #ifndef _VJ_CHUNKFACTORY_H_
37 #define _VJ_CHUNKFACTORY_H_
38
39 #include <vjConfig.h>
40 #include <Config/vjConfigChunk.h>
41 #include <Config/vjChunkDescDB.h>
42 #include <Kernel/vjDebug.h>
43 #include <Sync/vjMutex.h>
44 #include <Utils/vjSingleton.h>
45
46
47
48 //------------------------------------------------------------------
49 //: Generator of ConfigChunks...  (singleton)
50 //
51 //        The notion of embedded chunks complicated the configuration
52 //        system - suddenly a chunk needs to be able to find an
53 //        arbitrary vjChunkDesc in order to instantiate embedded chunks,
54 //        which may themselves embed chunks.
55 //        We needed a simpler way to generate vjConfigChunks on-the-fly
56 //        inside Juggler apps.  The singleton vjChunkFactory is a way to
57 //        do that.  Note that it relies on the notion that there will be
58 //        only one vjChunkDescDB in the Juggler app, and that it gets
59 //        told what it is.
60 //
61 // @author  Christopher Just
62 // February 1999
63 //------------------------------------------------------------------
64
65 class vjChunkFactory {
66
67 public:
68
69     //: Adds descriptions in _descdb to the factory
70     void addDescs (vjChunkDescDB* _descdb) {
71         descdb.insert (_descdb);
72     }
73
74
75     //: Adds descriptions in file 'filename' to the factory
76     void loadDescs (const std::string& filename) {
77         descdb.load(filename.c_str());
78     }
79
80
81     // we actually do need this so that the EM can send the descdb to the gui...
82     vjChunkDescDB* getChunkDescDB () {
83          return &descdb;
84     }
85
86     vjChunkDesc* getChunkDesc (const std::string& token) {
87         return descdb.getChunkDesc (token);
88     }
89
90     //: Creates a Chunk using the named description
91     //! RETURNS: chunk - a vjConfigChunk based on a vjChunkDesc
92     //+          whose token matches the argument.  If no such
93     //+          vjChunkDesc is found, an "empty" vjChunkDesc,
94     //+          containing only a Name vjPropertyDesc, is used.
95     vjConfigChunk* createChunk (const std::string& desctoken) {
96         return createChunk (descdb.getChunkDesc (desctoken));
97     }
98
99     //: Creates a Chunk using the given description
100     vjConfigChunk* createChunk (vjChunkDesc* d);
101
102
103 protected:
104
105     //: Setup the intial environment needed for creating chunks.
106     //  This just means that we load VJ_BASE_DIR/VJ_SHARE_DIR/Data/chunksDesc.
107     void setupInitialEnvironment();
108
109
110 private:
111
112     //: Constructor.  Calls setupInitialEnvironment.
113     vjChunkFactory() {
114         setupInitialEnvironment();
115     }
116
117
118     vjChunkDescDB descdb;
119
120
121     vjSingletonHeader(vjChunkFactory);
122
123 /*
124 public:
125    //: Get instance of singleton object
126    static vjChunkFactory* instance()
127    {
128       if(_instance == NULL)                     // First check
129       {
130          vjGuard<vjMutex> guard(_inst_lock);    // Serial critical section
131          if (_instance == NULL)                 // Second check
132             _instance = new vjChunkFactory;
133       }
134       vjASSERT(_instance != NULL && "vjChunkFactory has NULL _instance");
135       return _instance;
136    }
137
138 private:
139    static vjChunkFactory* _instance;   //: The instance
140    static vjMutex _inst_lock;
141    */
142 };
143
144 #endif
Note: See TracBrowser for help on using the browser.