• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
31 // Author: wink@google.com (Wink Saville)
32 
33 #ifndef PROTOBUF_COMPILER_JAVANANO_JAVANANO_PARAMS_H_
34 #define PROTOBUF_COMPILER_JAVANANO_JAVANANO_PARAMS_H_
35 
36 #include <map>
37 #include <set>
38 #include <google/protobuf/stubs/strutil.h>
39 
40 namespace google {
41 namespace protobuf {
42 namespace compiler {
43 namespace javanano {
44 
45 enum eMultipleFiles { JAVANANO_MUL_UNSET, JAVANANO_MUL_FALSE, JAVANANO_MUL_TRUE };
46 
47 // Parameters for used by the generators
48 class Params {
49  public:
50   typedef std::map<string, string> NameMap;
51   typedef std::set<string> NameSet;
52  private:
53   string empty_;
54   string base_name_;
55   eMultipleFiles override_java_multiple_files_;
56   bool store_unknown_fields_;
57   NameMap java_packages_;
58   NameMap java_outer_classnames_;
59   NameSet java_multiple_files_;
60   bool generate_has_;
61   bool java_enum_style_;
62   bool optional_field_accessors_;
63   bool use_reference_types_for_primitives_;
64   bool generate_equals_;
65   bool ignore_services_;
66   bool parcelable_messages_;
67   bool reftypes_primitive_enums_;
68   bool generate_clear_;
69   bool generate_clone_;
70   bool generate_intdefs_;
71 
72  public:
Params(const string & base_name)73   Params(const string & base_name) :
74     empty_(""),
75     base_name_(base_name),
76     override_java_multiple_files_(JAVANANO_MUL_UNSET),
77     store_unknown_fields_(false),
78     generate_has_(false),
79     java_enum_style_(false),
80     optional_field_accessors_(false),
81     use_reference_types_for_primitives_(false),
82     generate_equals_(false),
83     ignore_services_(false),
84     parcelable_messages_(false),
85     reftypes_primitive_enums_(false),
86     generate_clear_(true),
87     generate_clone_(false),
88     generate_intdefs_(false) {
89   }
90 
base_name()91   const string& base_name() const {
92     return base_name_;
93   }
94 
has_java_package(const string & file_name)95   bool has_java_package(const string& file_name) const {
96     return java_packages_.find(file_name)
97                         != java_packages_.end();
98   }
set_java_package(const string & file_name,const string & java_package)99   void set_java_package(const string& file_name,
100       const string& java_package) {
101     java_packages_[file_name] = java_package;
102   }
java_package(const string & file_name)103   const string& java_package(const string& file_name) const {
104     NameMap::const_iterator itr;
105 
106     itr = java_packages_.find(file_name);
107     if  (itr == java_packages_.end()) {
108       return empty_;
109     } else {
110       return itr->second;
111     }
112   }
java_packages()113   const NameMap& java_packages() {
114     return java_packages_;
115   }
116 
has_java_outer_classname(const string & file_name)117   bool has_java_outer_classname(const string& file_name) const {
118     return java_outer_classnames_.find(file_name)
119                         != java_outer_classnames_.end();
120   }
set_java_outer_classname(const string & file_name,const string & java_outer_classname)121   void set_java_outer_classname(const string& file_name,
122       const string& java_outer_classname) {
123     java_outer_classnames_[file_name] = java_outer_classname;
124   }
java_outer_classname(const string & file_name)125   const string& java_outer_classname(const string& file_name) const {
126     NameMap::const_iterator itr;
127 
128     itr = java_outer_classnames_.find(file_name);
129     if  (itr == java_outer_classnames_.end()) {
130       return empty_;
131     } else {
132       return itr->second;
133     }
134   }
java_outer_classnames()135   const NameMap& java_outer_classnames() {
136     return java_outer_classnames_;
137   }
138 
set_override_java_multiple_files(bool java_multiple_files)139   void set_override_java_multiple_files(bool java_multiple_files) {
140     if (java_multiple_files) {
141       override_java_multiple_files_ = JAVANANO_MUL_TRUE;
142     } else {
143       override_java_multiple_files_ = JAVANANO_MUL_FALSE;
144     }
145   }
clear_override_java_multiple_files()146   void clear_override_java_multiple_files() {
147     override_java_multiple_files_ = JAVANANO_MUL_UNSET;
148   }
149 
set_java_multiple_files(const string & file_name,bool value)150   void set_java_multiple_files(const string& file_name, bool value) {
151     if (value) {
152       java_multiple_files_.insert(file_name);
153     } else {
154       java_multiple_files_.erase(file_name);
155     }
156   }
java_multiple_files(const string & file_name)157   bool java_multiple_files(const string& file_name) const {
158     switch (override_java_multiple_files_) {
159       case JAVANANO_MUL_FALSE:
160         return false;
161       case JAVANANO_MUL_TRUE:
162         return true;
163       default:
164         return java_multiple_files_.find(file_name)
165                 != java_multiple_files_.end();
166     }
167   }
168 
set_store_unknown_fields(bool value)169   void set_store_unknown_fields(bool value) {
170     store_unknown_fields_ = value;
171   }
store_unknown_fields()172   bool store_unknown_fields() const {
173     return store_unknown_fields_;
174   }
175 
set_generate_has(bool value)176   void set_generate_has(bool value) {
177     generate_has_ = value;
178   }
generate_has()179   bool generate_has() const {
180     return generate_has_;
181   }
182 
set_java_enum_style(bool value)183   void set_java_enum_style(bool value) {
184     java_enum_style_ = value;
185   }
java_enum_style()186   bool java_enum_style() const {
187     return java_enum_style_;
188   }
189 
set_optional_field_accessors(bool value)190   void set_optional_field_accessors(bool value) {
191     optional_field_accessors_ = value;
192   }
optional_field_accessors()193   bool optional_field_accessors() const {
194     return optional_field_accessors_;
195   }
196 
set_use_reference_types_for_primitives(bool value)197   void set_use_reference_types_for_primitives(bool value) {
198     use_reference_types_for_primitives_ = value;
199   }
use_reference_types_for_primitives()200   bool use_reference_types_for_primitives() const {
201     return use_reference_types_for_primitives_;
202   }
203 
set_generate_equals(bool value)204   void set_generate_equals(bool value) {
205     generate_equals_ = value;
206   }
generate_equals()207   bool generate_equals() const {
208     return generate_equals_;
209   }
210 
set_ignore_services(bool value)211   void set_ignore_services(bool value) {
212     ignore_services_ = value;
213   }
ignore_services()214   bool ignore_services() const {
215     return ignore_services_;
216   }
217 
set_parcelable_messages(bool value)218   void set_parcelable_messages(bool value) {
219     parcelable_messages_ = value;
220   }
parcelable_messages()221   bool parcelable_messages() const {
222     return parcelable_messages_;
223   }
224 
set_reftypes_primitive_enums(bool value)225   void set_reftypes_primitive_enums(bool value) {
226     reftypes_primitive_enums_ = value;
227   }
reftypes_primitive_enums()228   bool reftypes_primitive_enums() const {
229     return reftypes_primitive_enums_;
230   }
231 
set_generate_clear(bool value)232   void set_generate_clear(bool value) {
233     generate_clear_ = value;
234   }
generate_clear()235   bool generate_clear() const {
236     return generate_clear_;
237   }
238 
set_generate_clone(bool value)239   void set_generate_clone(bool value) {
240     generate_clone_ = value;
241   }
generate_clone()242   bool generate_clone() const {
243     return generate_clone_;
244   }
245 
set_generate_intdefs(bool value)246   void set_generate_intdefs(bool value) {
247     generate_intdefs_ = value;
248   }
generate_intdefs()249   bool generate_intdefs() const {
250     return generate_intdefs_;
251   }
252 };
253 
254 }  // namespace javanano
255 }  // namespace compiler
256 }  // namespace protobuf
257 }  // namespace google
258 #endif  // PROTOBUF_COMPILER_JAVANANO_JAVANANO_PARAMS_H_
259