teditor  1.8.0@@fee5e94
Terminal based editor written in C++
command.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <unordered_map>
5 #include "utils.h"
6 #include <utility>
7 
8 namespace teditor {
9 
10 class Editor;
11 
12 
14 typedef void (*OperateFunc)(Editor& ed);
16 typedef std::pair<OperateFunc, std::string> Command;
18 typedef std::unordered_map<std::string, Command> CommandMap;
20 typedef bool (*CmdFilterOp)(const std::string&);
21 
23 bool defaultCmdFilterOp(const std::string& name);
24 
25 
35 const Command& getCmd(const std::string& cmd);
46 struct CmdRegistrar {
47  CmdRegistrar(const std::string& cmd, OperateFunc op, const std::string& grp);
48 };
49 
51 #define DEF_CMD(UniqName, CmdName, CmdGroup, OpFunc) \
52  CmdRegistrar cmd ## UniqName(CmdName, OpFunc, CmdGroup)
53 
55 #define DEF_OP() [](Editor& ed)
56 
57 }; // end namespace teditor
teditor::OperateFunc
void(* OperateFunc)(Editor &ed)
Definition: command.h:14
teditor::Command
std::pair< OperateFunc, std::string > Command
Definition: command.h:16
teditor::cmds
CommandMap & cmds()
Definition: command.cpp:8
teditor::allCmdNames
Strings allCmdNames(CmdFilterOp filterOp)
Accessor function to the list of command names.
Definition: command.cpp:30
teditor::Strings
std::vector< std::string > Strings
Definition: utils.h:42
command.h
utils.h
ASSERT
#define ASSERT(check, fmt,...)
Macro to assert with runtime_error exception if the check fails.
Definition: utils.h:35
teditor::CmdRegistrar::CmdRegistrar
CmdRegistrar(const std::string &cmd, OperateFunc op, const std::string &grp)
Definition: command.cpp:13
teditor::getCmd
const Command & getCmd(const std::string &cmd)
Helper to return the command of interest.
Definition: command.cpp:23
teditor::defaultCmdFilterOp
bool defaultCmdFilterOp(const std::string &name)
Definition: command.cpp:21
teditor::Editor
Definition: editor.h:23
teditor::CmdFilterOp
bool(* CmdFilterOp)(const std::string &)
Definition: command.h:20
teditor::CmdRegistrar
Definition: command.h:46
teditor::CommandMap
std::unordered_map< std::string, Command > CommandMap
Definition: command.h:18
editor.h
teditor
Definition: any.hpp:10