-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRepresentationPointer.h
More file actions
47 lines (36 loc) · 1.2 KB
/
RepresentationPointer.h
File metadata and controls
47 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* RepresentationPointer.h
*
* Created on: Jan 18, 2016
* Author: sabeyruw
*/
#ifndef REPRESENTATIONPOINTER_H_
#define REPRESENTATIONPOINTER_H_
#include "Controller.h"
template<const char* (*getModuleName)(), const char* (*getRepresentationName)(), typename T>
class RepresentationPointer
{
protected:
T* theInstance;
public:
RepresentationPointer() : theInstance(0) { }
virtual ~RepresentationPointer() { }
protected:
inline T* getRepresentation()
{
if (!theInstance)
theInstance = (T*) Controller::getInstance().getRepresentation(getModuleName(), getRepresentationName());
return theInstance;
}
inline T* getRepresentation() const
{
if (!theInstance)
return theInstance;
return (T*) Controller::getInstance().getRepresentation(getModuleName(), getRepresentationName()); //<< SLOW for CONST ACCESS
}
public:
virtual bool isNull() { return (this->getRepresentation() == 0); }
virtual bool operator==(const T* other) { return this->getRepresentation() == other; }
virtual bool operator!=(const T* other) { return !(this->getRepresentation() == other); }
};
#endif /* REPRESENTATIONPOINTER_H_ */