AnyCAD C++ API  2018
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 
APIUserCommandManager.h
浏览该文件的文档.
1 //Public API. Powered by AnyCAD.
2 
3 #ifndef _APIUserCommandManager_H_
4 #define _APIUserCommandManager_H_
5 
6 #include "APIObjectDef.h"
7 #include "APICustomCommand.h"
8 #include <unordered_map>
9 
10 namespace AnyCAD{ namespace API
11 {
19  {
20  public:
22 
23  template<class TCommand>
24  bool Register()
25  {
26  auto command = std::make_shared<TCommand>();
27  auto itr = m_Commands.find(command->GetName());
28  if (itr != m_Commands.end())
29  return false;
30 
31  return AddCommand(command);
32  }
33 
34  typedef std::shared_ptr<CustomCommand> CustomCommandPtr;
35 
36  static UserCommandManager& Instance();
37  protected:
38  bool AddCommand(const CustomCommandPtr& command);
39  private:
40 
41  std::unordered_map<String, CustomCommandPtr> m_Commands;
42  };//UserCommandManager;
43 
44  template<class TCommand>
46  {
47  public:
49  {
51  }
52 
53  private:
54  };
55 
56 #define REGISTER_USER_COMMAND(command)\
57  static TCommandRegisger<command> s_register##command;
58 }}//API
59 
60 #endif //_APIUserCommandManager_H_
#define AnyPlatformAPI_API
Definition: AnyPlatformAPI.h:8
std::shared_ptr< CustomCommand > CustomCommandPtr
Definition: APIUserCommandManager.h:34
static UserCommandManager & Instance()
Definition: APIUserCommandManager.h:45
The user command manager.
Definition: APIUserCommandManager.h:18
bool Register()
Definition: APIUserCommandManager.h:24
TCommandRegisger()
Definition: APIUserCommandManager.h:48