mirror of
https://gitee.com/TarsCloud/TarsCpp.git
synced 2024-12-22 22:16:38 +08:00
246 lines
5.7 KiB
C++
246 lines
5.7 KiB
C++
/**
|
||
* Tencent is pleased to support the open source community by making Tars available.
|
||
*
|
||
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
|
||
*
|
||
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||
* in compliance with the License. You may obtain a copy of the License at
|
||
*
|
||
* https://opensource.org/licenses/BSD-3-Clause
|
||
*
|
||
* Unless required by applicable law or agreed to in writing, software distributed
|
||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||
* specific language governing permissions and limitations under the License.
|
||
*/
|
||
#ifndef _TARS2CS_H
|
||
#define _TARS2CS_H
|
||
|
||
#include "parse.h"
|
||
|
||
#include <cassert>
|
||
#include <string>
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>tars<72><73><EFBFBD><EFBFBD>java<76>ļ<EFBFBD>
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>Proxy<78><79>Servant
|
||
*/
|
||
class Tars2Cs
|
||
{
|
||
public:
|
||
/**
|
||
* <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵĸ<C9B5>Ŀ¼
|
||
* @param dir
|
||
*/
|
||
void setBaseDir(const string &dir);
|
||
|
||
/**
|
||
* <20><><EFBFBD>ð<EFBFBD>ǰ
|
||
* @param prefix
|
||
*/
|
||
void setBasePackage(const string &prefix);
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD>
|
||
*/
|
||
void setWithServant(bool bWithServant) { _bWithServant = bWithServant;}
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>
|
||
* @param file
|
||
* @param isFramework <20>Ƿ<EFBFBD><C7B7>ǿ<EFBFBD><C7BF>
|
||
*/
|
||
void createFile(const string &file);
|
||
|
||
protected:
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC>ȡ<EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
|
||
* @param ns <20><><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>
|
||
*
|
||
* @return string
|
||
*/
|
||
string getFilePath(const string &ns) const;
|
||
|
||
string _packagePrefix;
|
||
string _baseDir;
|
||
bool _bWithServant;
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
protected:
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>͵Ľ<CDB5><C4BD><EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string writeTo(const TypeIdPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>͵ı<CDB5><C4B1><EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string readFrom(const TypeIdPtr &pPtr) const;
|
||
|
||
/**
|
||
*
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string display(const TypeIdPtr &pPtr) const;
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
protected:
|
||
|
||
/*
|
||
* <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>͵ij<CDB5>ʼ<EFBFBD><CABC><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string toTypeInit(const TypePtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>͵Ķ<CDB5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string toObjStr(const TypePtr &pPtr) const;
|
||
|
||
/**
|
||
* <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*/
|
||
bool isObjType(const TypePtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>͵<EFBFBD><CDB5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostr(const TypePtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5>ַ<EFBFBD><D6B7><EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostrBuiltin(const BuiltinPtr &pPtr) const;
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>vector<6F><72><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostrVector(const VectorPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>map<61><70><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostrMap(const MapPtr &pPtr, bool bNew = false) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ij<EFBFBD>ֽṹ<D6BD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostrStruct(const StructPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>ö<EFBFBD>ٵķ<D9B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string tostrEnum(const EnumPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string decode(const TypeIdPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string encode(const TypeIdPtr &pPtr) const;
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>h<EFBFBD><68>java<76>ļ<EFBFBD><C4BC>ľ<EFBFBD><C4BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
protected:
|
||
/**
|
||
* <20><><EFBFBD>ɽṹ<C9BD><E1B9B9>java<76>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generateCs(const StructPtr &pPtr, const NamespacePtr &nPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>javaԴ<61><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generateCs(const ContainerPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD>ɲ<EFBFBD><C9B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>java<76>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generateCs(const ParamDeclPtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ö<EFBFBD>ٵ<EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
string generateCs(const EnumPtr &pPtr, const NamespacePtr &nPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD>ɳ<EFBFBD><C9B3><EFBFBD>javaԴ<61><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
void generateCs(const ConstPtr &pPtr, const NamespacePtr &nPtr) const;
|
||
|
||
void generateCs(const vector<EnumPtr> &es,const vector<ConstPtr> &cs,const NamespacePtr &nPtr) const;
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿռ<D6BF>java<76>ļ<EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
void generateCs(const NamespacePtr &pPtr) const;
|
||
|
||
/**
|
||
* <20><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>tars<72>ļ<EFBFBD><C4BC><EFBFBD>java<76>ļ<EFBFBD>Դ<EFBFBD><D4B4>
|
||
* @param pPtr
|
||
*
|
||
* @return string
|
||
*/
|
||
void generateCs(const ContextPtr &pPtr) const;
|
||
|
||
};
|
||
|
||
#endif
|
||
|
||
|