Cornell Cocos
Cornell Extensions to Cocos2d
All Classes Functions Variables Enumerations Enumerator Friends
CUAsset.h
1 //
2 // CUAsset.h
3 // Cornell Extensions to Cocos2D
4 //
5 // This module provides an abstract class for generic assets. It is to help with any asset (such
6 // (such as a model file or level layout) not explicitly included in the existing asset classes.
7 // It has methods for loading and unloading from a file, which any subclass should implement.
8 //
9 // IMPORTANT: In order to work properly, the subclass must have the static constructors create()
10 // and create(file) defined. As with most classes in Cocos2d, you should not allow direct
11 // access to the constructors.
12 //
13 // Author: Walker White
14 // Version: 1/19/16
15 //
16 #ifndef __CU_ASSET_H__
17 #define __CU_ASSET_H__
18 #include <base/CCRef.h>
19 #include <platform/CCFileUtils.h>
20 
21 NS_CC_BEGIN
22 
23 #pragma mark -
24 #pragma mark Generic Asset
25 
39 class CC_DLL Asset : public Ref {
40 protected:
42  std::string _file;
43 
44 public:
50  std::string getFile() const { return _file; }
51 
60  void setFile(std::string file) { _file = file; }
61 
76  virtual bool load() = 0;
77 
89  virtual void unload() {}
90 
91 
92 CC_CONSTRUCTOR_ACCESS:
93 #pragma mark Initializers
94 
97  Asset() : Ref() { _file = ""; }
98 
102  virtual ~Asset() { unload(); }
103 
112  bool init() { _file = ""; return true; }
113 
122  bool init(std::string file) {
123  _file = FileUtils::getInstance()->fullPathForFilename(file);
124  return _file != "";
125  }
126 };
127 
128 NS_CC_END
129 
130 #endif /* __CU_ASSET_H__ */
std::string getFile() const
Definition: CUAsset.h:50
bool init(std::string file)
Definition: CUAsset.h:122
virtual void unload()
Definition: CUAsset.h:89
virtual ~Asset()
Definition: CUAsset.h:102
bool init()
Definition: CUAsset.h:112
void setFile(std::string file)
Definition: CUAsset.h:60
std::string _file
Definition: CUAsset.h:42
Definition: CUAsset.h:39