Cafu Engine
1 /*
2 Cafu Engine,
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
10 #include <map>
11 #include <string>
14 class CafuModelT;
17 /// This class is used for managing model instances.
18 ///
19 /// Without this class, when several users each create their own model instance from the same filename,
20 /// the model is physically instantiated multiple times. Each instance consumes resources (such as the
21 /// allocated memory), but is exactly identical to the others.
22 /// However, once a model has been created, it is \emph{immutable} (const), because all its variable
23 /// state is extrinsic, i.e. seperately kept in \c AnimPoseT instances.
24 ///
25 /// Therefore, very much as in the Flyweight pattern, model instances can be shared among users:
26 /// It suffices to physically instantiate each model only once and to point users to that instance.
27 ///
28 /// In summary, the purpose of this class is to share model instances among users in order to avoid
29 /// resource duplication. It also calls the proper loaders according to the requested model filename,
30 /// and gracefully handles errors by substituting a dummy model instead of propagating an exception.
32 {
33  public:
35  ModelManagerT();
36  ~ModelManagerT();
38  /// Returns (a pointer to) a model instance for the given filename.
39  /// The returned model instance is possibly shared with other users, and must not be deleted.
40  ///
41  /// If there was an error loading the model, a "dummy model" instance is returned
42  /// (no exception is thrown and the return value is a valid pointer to the dummy model).
43  /// When this is the first attempt to load the model, an error message is returned as well;
44  /// further requests to the same model will just return the dummy model but not the message.
45  ///
46  /// @param FileName The filename to load the model from.
47  /// @param ErrorMsg Is set to the error message if there was an error loading the model,
48  /// or the empty string \c "" when the model was successfully loaded.
49  const CafuModelT* GetModel(const std::string& FileName, std::string* ErrorMsg=NULL) const;
52  private:
54  ModelManagerT(const ModelManagerT&); ///< Use of the Copy Constructor is not allowed.
55  void operator = (const ModelManagerT&); ///< Use of the Assignment Operator is not allowed.
57  mutable std::map<std::string, CafuModelT*> m_Models;
58 };
60 #endif
This class represents a native Cafu model.
Definition: Model_cmdl.hpp:45
const CafuModelT * GetModel(const std::string &FileName, std::string *ErrorMsg=NULL) const
Returns (a pointer to) a model instance for the given filename.
Definition: ModelManager.cpp:33
This class is used for managing model instances.
Definition: ModelManager.hpp:31