FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
asset.h
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef FPLBASE_ASSET_H
16 #define FPLBASE_ASSET_H
17 
18 #include <assert.h>
19 
20 namespace fplbase {
21 
22 class AssetManager;
23 
24 /// @class Asset
25 /// @brief Base class of all assets that _may_ be managed by Assetmanager.
26 class Asset {
27  public:
28  Asset() : refcount_(1) {}
29  virtual ~Asset() {}
30 
31  /// @brief indicate there is an additional owner of this asset.
32  /// By default, when you call any of the UnLoad*() functions in the
33  /// AssetManager, that will directly delete the asset since they all start
34  /// out with a single reference count. Call this function to indicate
35  /// multiple owners will call Unload*() independently, and only have the
36  /// asset deleted by the last one.
37  void IncreaseRefCount() { refcount_++; }
38 
39  private:
40  // This is private, since only the AssetManager can delete assets.
41  friend class AssetManager;
42  int DecreaseRefCount() {
43  assert(refcount_ > 0);
44  return --refcount_;
45  };
46 
47  int refcount_;
48 };
49 
50 } // namespace fplbase
51 
52 #endif // FPLBASE_ASSET_H
void IncreaseRefCount()
indicate there is an additional owner of this asset. By default, when you call any of the UnLoad*() f...
Definition: asset.h:37
Central place to own game assets loaded from disk.
Definition: asset_manager.h:53
Base class of all assets that may be managed by Assetmanager.
Definition: asset.h:26