tars2php.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #ifndef _TARS2PHP_H
  17. #define _TARS2PHP_H
  18. #include "parse.h"
  19. #include <cassert>
  20. #include <string>
  21. using namespace tars;
  22. /**
  23. */
  24. class Tars2Php
  25. {
  26. public:
  27. Tars2Php();
  28. /**
  29. *
  30. * @param file
  31. */
  32. void createFile(const string &file, const vector<string> &vsCoder);
  33. /**
  34. *
  35. *
  36. */
  37. void setBaseDir(const std::string & sPath) { m_sBaseDir = sPath; }
  38. /**
  39. *
  40. */
  41. void setCheckDefault(bool bCheck) { m_bCheckDefault = bCheck; }
  42. protected:
  43. /**
  44. *
  45. * @param pPtr
  46. *
  47. * @return string
  48. */
  49. string writeTo(const TypeIdPtr &pPtr) const;
  50. /**
  51. *
  52. * @param pPtr
  53. *
  54. * @return string
  55. */
  56. string readFrom(const TypeIdPtr &pPtr, bool bIsRequire = true) const;
  57. protected:
  58. /**
  59. *
  60. * @param pPtr
  61. *
  62. * @return string
  63. */
  64. string tostr(const TypePtr &pPtr) const;
  65. /**
  66. * @param pPtr
  67. *
  68. * @return string
  69. */
  70. string tostrBuiltin(const BuiltinPtr &pPtr) const;
  71. /**
  72. *
  73. * @param pPtr
  74. *
  75. * @return string
  76. */
  77. string tostrVector(const VectorPtr &pPtr) const;
  78. /**
  79. *
  80. * @param pPtr
  81. *
  82. * @return string
  83. */
  84. string tostrMap(const MapPtr &pPtr) const;
  85. /**
  86. *
  87. * @param pPtr
  88. *
  89. * @return string
  90. */
  91. string tostrStruct(const StructPtr &pPtr) const;
  92. /**
  93. *
  94. * @param pPtr
  95. *
  96. * @return string
  97. */
  98. string tostrEnum(const EnumPtr &pPtr) const;
  99. /**
  100. *
  101. * @param pPtr
  102. *
  103. * @return string
  104. */
  105. string toStrSuffix(const TypeIdPtr &pPtr) const;
  106. /**
  107. *
  108. * @param pPtr
  109. *
  110. * @return int
  111. */
  112. int getSuffix(const TypeIdPtr &pPtr) const;
  113. /**
  114. *
  115. * @param pPtr
  116. *
  117. * @return string
  118. */
  119. string decode(const TypeIdPtr &pPtr) const;
  120. /**
  121. *
  122. * @param pPtr
  123. *
  124. * @return string
  125. */
  126. string encode(const TypeIdPtr &pPtr) const;
  127. protected:
  128. /**
  129. *
  130. * @param pPtr
  131. *
  132. * @return string
  133. */
  134. string generatePHP(const StructPtr &pPtr, const string& namespaceId) const;
  135. /**
  136. *
  137. * @param pPtr
  138. *
  139. * @return string
  140. */
  141. string generatePHP(const NamespacePtr &pPtr) const;
  142. /**
  143. *
  144. * @param pPtr
  145. *
  146. * @return string
  147. */
  148. void generatePHP(const ContextPtr &pPtr) const;
  149. void generatePHP_Pdu(const ContextPtr &pPtr) const;
  150. private:
  151. std::string m_sBaseDir;
  152. bool m_bCheckDefault;
  153. };
  154. #endif