My Project
INPLAcitvationFile.h
1 #pragma once
2 
3 namespace NPL
4 {
5  class INPLRuntimeState;
6 
7  /* c++ base activation file that is callable from scripting interface or NPL.
8  * @sa NPL_C_Func_ActivationFile and CNPLFile_Stats for example usage:
9  *
10  * Usage One: we can explicitly register a function by deriving from INPLActivationFile.
11  * Usage Two: or we can register automatically by defining static function with special name: NPL_activate_XXXX_cpp, such as :
12  *
13  * extern "C"{
14  * NPL::NPLReturnCode NPL_activate_script_helloworld_cpp(INPLRuntimeState* pState);
15  * }
16  * NPL.activate("script/helloworld.cpp", {}) or NPL.activate("script_helloworld.cpp", {}) will both activate it.
17  */
19  {
20  public:
21  INPLActivationFile() : m_refcount(0) {};
22  virtual ~INPLActivationFile(){};
23 
30  virtual NPL::NPLReturnCode OnActivate(INPLRuntimeState* pState) = 0;
31 
32  public:
34  void addref()const
35  {
36  ++m_refcount;
37  }
38 
41  bool delref()const
42  {
43  return --m_refcount <= 0;
44  }
46  int GetRefCount()const
47  {
48  return m_refcount;
49  }
50 
51  //all overridden functions should call this function in order to use the "delete when
52  //reference is zero" scheme
53  virtual int Release()
54  {
55  if (delref()) {
56  int nRefCount = GetRefCount();
57  delete this;
58  return nRefCount;
59  }
60  return GetRefCount();
61  }
62 
63  protected:
64  mutable int m_refcount;
65  };
66 }
void addref() const
add reference count of the object.
Definition: INPLAcitvationFile.h:34
define this to enable debugging of NPL code in visual studio
Definition: INPL.h:9
INPLRuntimeState interface for DLL interface.
Definition: INPLRuntimeState.h:27
bool delref() const
decrease reference count of the object.
Definition: INPLAcitvationFile.h:41
Definition: INPLAcitvationFile.h:18
virtual NPL::NPLReturnCode OnActivate(INPLRuntimeState *pState)=0
Function to be called when NPL.activate(filename, {msg}); subclass should always overwrite this funct...
int GetRefCount() const
get the reference count
Definition: INPLAcitvationFile.h:46