c++添加swich case string 的支持
来源:互联网 发布:access窗体输入数据 编辑:程序博客网 时间:2024/04/27 12:05
#pragma once // ---------------------------------------------------------------------------- // string_switch_case.h // // These macros together implement switch-case functionality for C strings and // std::string. When first encountered, the switch-case structure does two // passes. The first pass is a one-time initialization of a std::map with the // strings as keys, and line numbers as values, to get the unique keys needed // for a numeric switch-case. All subsequent passes use the std::map to // retrieve an unsigned integer for a given string, that was mapped during the // first pass, to use for a numeric switch case. This switch-case approach can // be used repeatedly and even nested. An example of the usage is as follows: // // switch_string(a) // { // case_string("first string") // printf("first string"); // break; // case_string("second string") // printf("second string"); // case_string("third string") // printf("falls through to third string"); // break; // default_case_string // printf("default"); // } // end_switch_string // // The end_switch_string macro is required after the closing brace of the // switch-case structure. Each case_string statement must be on a unique line. // Each case_string has its own local scope. A case_string statement is // ignored if declared within scope brackets beneath a sibling case statement. // ---------------------------------------------------------------------------- #include <map> #include <string> // switch macro #define switch_string(a) while (true) { static std::map<std::string, unsigned int> _string_lookup_; static bool _init_ = true; unsigned int _val_ = 0; if (!_init_) { std::map<std::string, unsigned int>::iterator _iter_ = _string_lookup_.find(a); if (_iter_ != _string_lookup_.end()) { _val_ = (*_iter_).second; } else { _val_ = 0xffffffff; } } switch(_val_) { case 0: // case macro #define case_string(a) } case __LINE__: if (_init_) _string_lookup_.insert (std::pair<std::string, unsigned int>(a, __LINE__)); else { // default case macro #define default_case_string } default: if (!_init_) { // required macro for the end of the switch-case #define end_switch_string } if (_init_) { _init_ = false; } else { break; } }
0 0
- c++添加swich case string 的支持
- C/C++/C#是否支持基于string的switch-case??
- ******************* swich-case 语句 *******************
- 【Python 笔记】Python中 swich...case 的实现
- Java7中的switch...case支持string的实现细节
- 为C++添加短字符串的switch-case支持
- php流程控制以及swich、case、default、break,continue的用法
- Matlab--------------swich的用法
- 简单的 swich开关
- switch case支持的类型
- 支持UML的CASE工具概览
- switch/case语句支持的数据类型
- 枚举类型和swich的比较
- swich 的一些用法,注意点
- c++ switch/case 使用 string的方法
- 添加ActionBar的支持
- 添加ES6的支持
- 左移(右移)运算符结合swich case语句详解
- linux安装问题
- d3.js—— 绘制二维数组的动态图表
- Java中有关Null的9件事
- JAVA Static关键字理解
- unite2016上海Unity大会--Unity3D性能优化篇
- c++添加swich case string 的支持
- Android中Application设置全局变量以及传值
- Android_Fragment详解
- Linux内核学习笔记二——进程
- sql server 查看字段备注等信息
- hihoCoder 1066 无间道之并查集
- NoClassDefFoundError解决
- 界面设置按钮菜单设置
- ZOJ 2818