Lightmetrica  0.0.1.50dbee3 (yosakoi)
 All Classes Functions Variables Typedefs Enumerations Enumerator
asset.h
1 /*
2  Lightmetrica : A research-oriented renderer
3 
4  Copyright (c) 2014 Hisanari Otsu
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 #ifndef LIB_LIGHTMETRICA_ASSET_H
22 #define LIB_LIGHTMETRICA_ASSET_H
23 
24 #include "component.h"
25 
26 LM_NAMESPACE_BEGIN
27 
28 class Assets;
29 class ConfigNode;
30 
35 class Asset : public Component
36 {
37 public:
38 
39  Asset() {}
40  virtual ~Asset() {}
41 
42 private:
43 
44  LM_DISABLE_COPY_AND_MOVE(Asset);
45 
46 public:
47 
58  virtual bool Load(const ConfigNode& node, const Assets& assets) = 0;
59 
64  LM_PUBLIC_API std::string ID() const;
65 
66 public:
67 
73  LM_HIDDEN_API void SetID(const std::string& id);
74 
75 private:
76 
77  std::string id;
78 
79 };
80 
81 LM_NAMESPACE_END
82 
83 #define LM_ASSET_INTERFACE_DEF(Name, GroupName) \
84  LM_COMPONENT_INTERFACE_DEF(Name); \
85  static const char* InterfaceGroupName() { return GroupName; }
86 
87 #define LM_ASSET_DEPENDENCIES(...) \
88  static const char** GetAssetDependencies(size_t& n) \
89  { \
90  static const char* deps[] = { __VA_ARGS__ }; \
91  n = sizeof(deps) / sizeof(deps[0]); \
92  return deps; \
93  }
94 
95 #define LM_ASSET_NO_DEPENDENCIES() \
96  static const char** GetAssetDependencies(size_t& n) \
97  { \
98  n = 0; \
99  return nullptr; \
100  }
101 
102 LM_NAMESPACE_BEGIN
103 LM_COMPONENT_CREATE_HAS_MEMBER_FUNCTION(GetAssetDependencies, const char** (*)(size_t&));
104 LM_COMPONENT_CREATE_HAS_MEMBER_FUNCTION(InterfaceGroupName, const char* (*)());
105 LM_NAMESPACE_END
106 
107 #define LM_ASSET_CHECK_IS_VALID_INTERFACE(AssetInterfaceType) \
108  LM_COMPONENT_CHECK_IS_DERIVED_CLASS(AssetInterfaceType, Asset); \
109  LM_COMPONENT_CHECK_HAS_MEMBER_FUNCTION(AssetInterfaceType, GetAssetDependencies); \
110  LM_COMPONENT_CHECK_HAS_MEMBER_FUNCTION(AssetInterfaceType, InterfaceGroupName);
111 
112 #endif // LIB_LIGHTMETRICA_ASSET_H
Definition: component.h:45
LM_PUBLIC_API std::string ID() const
Definition: asset.cpp:27
LM_HIDDEN_API void SetID(const std::string &id)
Definition: asset.cpp:32
Definition: assets.h:39
virtual bool Load(const ConfigNode &node, const Assets &assets)=0
Definition: asset.h:35
Definition: confignode.h:37