Watch Star Fork

RonxBulld / ftrpcC++GPL-3.0

加入码云
与超过 300 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
这是一个简单的异步RPC框架,基于JSON进行传输。程序只进行打/解包参数工作,不涉及具体通信方式,socket、websocket都可以使用。目前作者使用此项目生成 typescript 前端和 C++ 后端,更多语言将被支持。 https://gitee.com/RonxBulld/ftrpc/wikis
一键复制 编辑 原始数据 按行查看 历史
symman.cpp 2.38 KB RonxBulld 提交于 2018-07-09 00:23 . 添加数组支持
//
// Created by Rexfield on 2018/5/3.
//
#include <exception>
#include "symman.h"
TokenManage::TokenManage(std::initializer_list<std::pair<std::string, TokenID>> initToken) {
for(const auto & [literal,id] : initToken) {
this->i2s.insert(std::make_pair(id, literal));
this->s2i.insert(std::make_pair(literal, id));
this->indexReg = id >= this->indexReg ? id + 1 : this->indexReg;
}
}
TokenID TokenManage::operator[](const std::string &Token) {
if (this->s2i.find(Token) != this->s2i.end()) {
return this->s2i[Token];
}
TokenID i = this->indexReg++;
this->s2i.insert(std::make_pair(Token, i));
this->i2s.insert(std::make_pair(i, Token));
return i;
}
const std::string &TokenManage::operator[](const TokenID &ID) {
if (this->i2s.find(ID) != this->i2s.end()) {
return this->i2s[ID];
}
}
TypeManage::TypeManage(std::initializer_list<std::pair<TypeID, TokenID>> initBaseType) {
for(auto member : initBaseType) {
this->tk2ty.insert(std::make_pair(member.second, member.first));
this->ty2tk.insert(std::make_pair(member.first, member.second));
this->indexReg = member.first >= this->indexReg ? member.first + 1 : this->indexReg;
}
}
TypeID TypeManage::getTypeID(TokenID Name) {
if (this->tk2ty.find(Name) == this->tk2ty.end()) {
throw std::runtime_error("Referenced an undefined type.");
}
return this->tk2ty[Name];
}
void TypeManage::registType(TokenID Name, enum typeDefType DeclareType, MemberLists &MemberList) {
if (this->tk2ty.find(Name) != this->tk2ty.end()) {
throw std::runtime_error("Redefine the type.");
}
TypeID i = this->indexReg++;
this->tk2ty.insert(std::make_pair(Name, i));
this->ty2tk.insert(std::make_pair(i, Name));
switch (DeclareType)
{
case typeDefType::DeclareStruct: {
this->StructsMap[i] = MemberList;
break;
}
case typeDefType::DeclareBase: {
// If *MemberList is nullptr, it means that the underlying type is being defined.
// No extra work needs to be done.
break;
}
default:
throw std::runtime_error("DeclareType was set to an inappropriate value.");
}
}
bool TypeManage::isType(TokenID Name) {
return this->tk2ty.find(Name) != this->tk2ty.end();
}

评论 ( 0 )

你可以在登录后,发表评论

11_float_left_people 11_float_left_close