javanano_params.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2010 Google Inc. All rights reserved.
  3. // http://code.google.com/p/protobuf/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: wink@google.com (Wink Saville)
  31. #ifndef PROTOBUF_COMPILER_JAVANANO_JAVANANO_PARAMS_H_
  32. #define PROTOBUF_COMPILER_JAVANANO_JAVANANO_PARAMS_H_
  33. #include <map>
  34. #include <set>
  35. #include <google/protobuf/stubs/strutil.h>
  36. namespace google {
  37. namespace protobuf {
  38. namespace compiler {
  39. namespace javanano {
  40. enum eMultipleFiles { JAVANANO_MUL_UNSET, JAVANANO_MUL_FALSE, JAVANANO_MUL_TRUE };
  41. // Parameters for used by the generators
  42. class Params {
  43. public:
  44. typedef map<string, string> NameMap;
  45. typedef set<string> NameSet;
  46. private:
  47. string empty_;
  48. string base_name_;
  49. eMultipleFiles override_java_multiple_files_;
  50. bool store_unknown_fields_;
  51. NameMap java_packages_;
  52. NameMap java_outer_classnames_;
  53. NameSet java_multiple_files_;
  54. bool generate_has_;
  55. bool java_enum_style_;
  56. bool optional_field_accessors_;
  57. bool use_reference_types_for_primitives_;
  58. bool generate_equals_;
  59. bool ignore_services_;
  60. public:
  61. Params(const string & base_name) :
  62. empty_(""),
  63. base_name_(base_name),
  64. override_java_multiple_files_(JAVANANO_MUL_UNSET),
  65. store_unknown_fields_(false),
  66. generate_has_(false),
  67. java_enum_style_(false),
  68. optional_field_accessors_(false),
  69. use_reference_types_for_primitives_(false),
  70. generate_equals_(false),
  71. ignore_services_(false) {
  72. }
  73. const string& base_name() const {
  74. return base_name_;
  75. }
  76. bool has_java_package(const string& file_name) const {
  77. return java_packages_.find(file_name)
  78. != java_packages_.end();
  79. }
  80. void set_java_package(const string& file_name,
  81. const string& java_package) {
  82. java_packages_[file_name] = java_package;
  83. }
  84. const string& java_package(const string& file_name) const {
  85. NameMap::const_iterator itr;
  86. itr = java_packages_.find(file_name);
  87. if (itr == java_packages_.end()) {
  88. return empty_;
  89. } else {
  90. return itr->second;
  91. }
  92. }
  93. const NameMap& java_packages() {
  94. return java_packages_;
  95. }
  96. bool has_java_outer_classname(const string& file_name) const {
  97. return java_outer_classnames_.find(file_name)
  98. != java_outer_classnames_.end();
  99. }
  100. void set_java_outer_classname(const string& file_name,
  101. const string& java_outer_classname) {
  102. java_outer_classnames_[file_name] = java_outer_classname;
  103. }
  104. const string& java_outer_classname(const string& file_name) const {
  105. NameMap::const_iterator itr;
  106. itr = java_outer_classnames_.find(file_name);
  107. if (itr == java_outer_classnames_.end()) {
  108. return empty_;
  109. } else {
  110. return itr->second;
  111. }
  112. }
  113. const NameMap& java_outer_classnames() {
  114. return java_outer_classnames_;
  115. }
  116. void set_override_java_multiple_files(bool java_multiple_files) {
  117. if (java_multiple_files) {
  118. override_java_multiple_files_ = JAVANANO_MUL_TRUE;
  119. } else {
  120. override_java_multiple_files_ = JAVANANO_MUL_FALSE;
  121. }
  122. }
  123. void clear_override_java_multiple_files() {
  124. override_java_multiple_files_ = JAVANANO_MUL_UNSET;
  125. }
  126. void set_java_multiple_files(const string& file_name, bool value) {
  127. if (value) {
  128. java_multiple_files_.insert(file_name);
  129. } else {
  130. java_multiple_files_.erase(file_name);
  131. }
  132. }
  133. bool java_multiple_files(const string& file_name) const {
  134. switch (override_java_multiple_files_) {
  135. case JAVANANO_MUL_FALSE:
  136. return false;
  137. case JAVANANO_MUL_TRUE:
  138. return true;
  139. default:
  140. return java_multiple_files_.find(file_name)
  141. != java_multiple_files_.end();
  142. }
  143. }
  144. void set_store_unknown_fields(bool value) {
  145. store_unknown_fields_ = value;
  146. }
  147. bool store_unknown_fields() const {
  148. return store_unknown_fields_;
  149. }
  150. void set_generate_has(bool value) {
  151. generate_has_ = value;
  152. }
  153. bool generate_has() const {
  154. return generate_has_;
  155. }
  156. void set_java_enum_style(bool value) {
  157. java_enum_style_ = value;
  158. }
  159. bool java_enum_style() const {
  160. return java_enum_style_;
  161. }
  162. void set_optional_field_accessors(bool value) {
  163. optional_field_accessors_ = value;
  164. }
  165. bool optional_field_accessors() const {
  166. return optional_field_accessors_;
  167. }
  168. void set_use_reference_types_for_primitives(bool value) {
  169. use_reference_types_for_primitives_ = value;
  170. }
  171. bool use_reference_types_for_primitives() const {
  172. return use_reference_types_for_primitives_;
  173. }
  174. void set_generate_equals(bool value) {
  175. generate_equals_ = value;
  176. }
  177. bool generate_equals() const {
  178. return generate_equals_;
  179. }
  180. void set_ignore_services(bool value) {
  181. ignore_services_ = value;
  182. }
  183. bool ignore_services() const {
  184. return ignore_services_;
  185. }
  186. };
  187. } // namespace javanano
  188. } // namespace compiler
  189. } // namespace protobuf
  190. } // namespace google
  191. #endif // PROTOBUF_COMPILER_JAVANANO_JAVANANO_PARAMS_H_