enum 枚举 字符串 转换 在调试时 写log时方便查找
来源:互联网 发布:微信淘宝优惠券可靠吗 编辑:程序博客网 时间:2024/05/16 11:22
msg.inl:
// 测试起始值MSGDEFINE_VAL(CMD_TEST_START,0)// A类消息起始值MSGDEFINE_VAL(CMD_TEST_A_BEGIN,CMD_TEST_START)// A类第一个测试消息MSGDEFINE(CMD_TEST_A_1)// A类第二个测试消息MSGDEFINE(CMD_TEST_A_2)// A类测试消息结束MSGDEFINE(CMD_TEST_A_END)
define.inl
#ifdef __MSGCMD_DEFINE#define MSGDEFINE(msg) msg,#define MSGDEFINE_VAL(msg,default_value) msg = default_value,#else#define MSGDEFINE(msg) ms[MsgCmd::msg] = string(#msg);#define MSGDEFINE_VAL(msg,default_value) ms[MsgCmd::msg] = string(#msg);#endif
protocol.h
#pragma once#include <map>#include<string>using std::map;using std::string;class MsgCmd{public:enum E{#ifdef __MSGCMD_DEFINE#undef __MSGCMD_DEFINE#endif#define __MSGCMD_DEFINE#include "define.inl"#include "msg.inl"#undef __MSGCMD_DEFINE};};class MsgCmd_String{map<int,string> ms;public:MsgCmd_String(){#ifdef __MSGCMD_DEFINE#undef __MSGCMD_DEFINE#endif#include "define.inl"#include "msg.inl"}public:string toString(int cmd){auto itr = ms.find(cmd);if (itr == ms.end()){return "";}return itr->second;}};
main.cpp
#include "protocol.h"#include<iostream>using std::cout;using std::endl;int main(){int iTestA1 = MsgCmd::CMD_TEST_A_1;MsgCmd_String cmdString;string strTmp = cmdString.toString(iTestA1);cout<<strTmp<<endl;return 0;}
0 0
- enum 枚举 字符串 转换 在调试时 写log时方便查找
- 将Enum枚举转换成字符串数组
- C# 枚举类型转换字符串 Enum to string,枚举转换为下拉菜单 Enum DropDownList
- 曲线救国,使枚举enum支持字符串string
- 枚举转换字符串
- 在枚举类型的值和字符串之间相互转换
- 在枚举类型的值和字符串之间相互转换
- 在C#中枚举的作用(enum)
- 枚举(enum)在model中的应用
- 在映射表中使用enum枚举
- js屏蔽掉调试时写的console.log
- C# Enum,Int,String的互相转换 枚举转换
- C# Enum,Int,String的互相转换 枚举转换
- (转)C# Enum,Int,String的互相转换 枚举转换
- C# Enum,Int,String的互相转换 枚举转换
- C# Enum,Int,String的互相转换 枚举转换
- C# Enum,Int,String的互相转换 枚举转换
- C# Enum,Int,String的互相转换 枚举转换
- Nagios监控mysql从库报错: libmysqlclient.so.18: cannot open shared object file: No such
- 判断手机登录还是电脑登录
- 数的计算
- 2014百姓网暑期技术实习笔试
- 浅谈C++中extern的用法
- enum 枚举 字符串 转换 在调试时 写log时方便查找
- 前台传递参数,乱码问题
- 理解VMWare的三种网络连接模式(bridged、NAT、host-only)
- Android导出jar包后的资源使用问题
- s:iterator遍历 object.List<List<String>>
- Win7x64下VC6.0的一些蛋疼的问题+解决方案。
- 为VMware里的虚拟机设置静态IP
- leetcode第一刷_Substring with Concatenation of All Words
- 上司