• 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 map<string, string> NameMap;
51   typedef 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   bool bytes_offset_length_;
72 
73  public:
Params(const string & base_name)74   Params(const string & base_name) :
75     empty_(""),
76     base_name_(base_name),
77     override_java_multiple_files_(JAVANANO_MUL_UNSET),
78     store_unknown_fields_(false),
79     generate_has_(false),
80     java_enum_style_(false),
81     optional_field_accessors_(false),
82     use_reference_types_for_primitives_(false),
83     generate_equals_(false),
84     ignore_services_(false),
85     parcelable_messages_(false),
86     reftypes_primitive_enums_(false),
87     generate_clear_(true),
88     generate_clone_(false),
89     generate_intdefs_(false),
90     bytes_offset_length_(false) {
91   }
92 
base_name()93   const string& base_name() const {
94     return base_name_;
95   }
96 
has_java_package(const string & file_name)97   bool has_java_package(const string& file_name) const {
98     return java_packages_.find(file_name)
99                         != java_packages_.end();
100   }
set_java_package(const string & file_name,const string & java_package)101   void set_java_package(const string& file_name,
102       const string& java_package) {
103     java_packages_[file_name] = java_package;
104   }
java_package(const string & file_name)105   const string& java_package(const string& file_name) const {
106     NameMap::const_iterator itr;
107 
108     itr = java_packages_.find(file_name);
109     if  (itr == java_packages_.end()) {
110       return empty_;
111     } else {
112       return itr->second;
113     }
114   }
java_packages()115   const NameMap& java_packages() {
116     return java_packages_;
117   }
118 
has_java_outer_classname(const string & file_name)119   bool has_java_outer_classname(const string& file_name) const {
120     return java_outer_classnames_.find(file_name)
121                         != java_outer_classnames_.end();
122   }
set_java_outer_classname(const string & file_name,const string & java_outer_classname)123   void set_java_outer_classname(const string& file_name,
124       const string& java_outer_classname) {
125     java_outer_classnames_[file_name] = java_outer_classname;
126   }
java_outer_classname(const string & file_name)127   const string& java_outer_classname(const string& file_name) const {
128     NameMap::const_iterator itr;
129 
130     itr = java_outer_classnames_.find(file_name);
131     if  (itr == java_outer_classnames_.end()) {
132       return empty_;
133     } else {
134       return itr->second;
135     }
136   }
java_outer_classnames()137   const NameMap& java_outer_classnames() {
138     return java_outer_classnames_;
139   }
140 
set_override_java_multiple_files(bool java_multiple_files)141   void set_override_java_multiple_files(bool java_multiple_files) {
142     if (java_multiple_files) {
143       override_java_multiple_files_ = JAVANANO_MUL_TRUE;
144     } else {
145       override_java_multiple_files_ = JAVANANO_MUL_FALSE;
146     }
147   }
clear_override_java_multiple_files()148   void clear_override_java_multiple_files() {
149     override_java_multiple_files_ = JAVANANO_MUL_UNSET;
150   }
151 
set_java_multiple_files(const string & file_name,bool value)152   void set_java_multiple_files(const string& file_name, bool value) {
153     if (value) {
154       java_multiple_files_.insert(file_name);
155     } else {
156       java_multiple_files_.erase(file_name);
157     }
158   }
java_multiple_files(const string & file_name)159   bool java_multiple_files(const string& file_name) const {
160     switch (override_java_multiple_files_) {
161       case JAVANANO_MUL_FALSE:
162         return false;
163       case JAVANANO_MUL_TRUE:
164         return true;
165       default:
166         return java_multiple_files_.find(file_name)
167                 != java_multiple_files_.end();
168     }
169   }
170 
set_store_unknown_fields(bool value)171   void set_store_unknown_fields(bool value) {
172     store_unknown_fields_ = value;
173   }
store_unknown_fields()174   bool store_unknown_fields() const {
175     return store_unknown_fields_;
176   }
177 
set_generate_has(bool value)178   void set_generate_has(bool value) {
179     generate_has_ = value;
180   }
generate_has()181   bool generate_has() const {
182     return generate_has_;
183   }
184 
set_java_enum_style(bool value)185   void set_java_enum_style(bool value) {
186     java_enum_style_ = value;
187   }
java_enum_style()188   bool java_enum_style() const {
189     return java_enum_style_;
190   }
191 
set_optional_field_accessors(bool value)192   void set_optional_field_accessors(bool value) {
193     optional_field_accessors_ = value;
194   }
optional_field_accessors()195   bool optional_field_accessors() const {
196     return optional_field_accessors_;
197   }
198 
set_use_reference_types_for_primitives(bool value)199   void set_use_reference_types_for_primitives(bool value) {
200     use_reference_types_for_primitives_ = value;
201   }
use_reference_types_for_primitives()202   bool use_reference_types_for_primitives() const {
203     return use_reference_types_for_primitives_;
204   }
205 
set_generate_equals(bool value)206   void set_generate_equals(bool value) {
207     generate_equals_ = value;
208   }
generate_equals()209   bool generate_equals() const {
210     return generate_equals_;
211   }
212 
set_ignore_services(bool value)213   void set_ignore_services(bool value) {
214     ignore_services_ = value;
215   }
ignore_services()216   bool ignore_services() const {
217     return ignore_services_;
218   }
219 
set_parcelable_messages(bool value)220   void set_parcelable_messages(bool value) {
221     parcelable_messages_ = value;
222   }
parcelable_messages()223   bool parcelable_messages() const {
224     return parcelable_messages_;
225   }
226 
set_reftypes_primitive_enums(bool value)227   void set_reftypes_primitive_enums(bool value) {
228     reftypes_primitive_enums_ = value;
229   }
reftypes_primitive_enums()230   bool reftypes_primitive_enums() const {
231     return reftypes_primitive_enums_;
232   }
233 
set_generate_clear(bool value)234   void set_generate_clear(bool value) {
235     generate_clear_ = value;
236   }
generate_clear()237   bool generate_clear() const {
238     return generate_clear_;
239   }
240 
set_generate_clone(bool value)241   void set_generate_clone(bool value) {
242     generate_clone_ = value;
243   }
generate_clone()244   bool generate_clone() const {
245     return generate_clone_;
246   }
247 
set_generate_intdefs(bool value)248   void set_generate_intdefs(bool value) {
249     generate_intdefs_ = value;
250   }
generate_intdefs()251   bool generate_intdefs() const {
252     return generate_intdefs_;
253   }
254 
255   // An advanced setting which uses buffer/offset/length tuples for each
256   // non-repeated bytes field, instead of a byte array which is serialized
257   // directly.
258   // The field is considered present iff the offset is not equal to the default
259   // value of -1; the value of the buffer has no relevance otherwise.
260   // In serialization, the [fieldName]Buffer array will be serialized starting
261   // at [fieldName]Offset and with length [fieldName]Length.
262   // In deserialization, the underlying byte array will be the same instance
263   // backing the underlying CodedInputByteBufferNano for all bytes fields, with
264   // appropriate offsets and lengths.
265   // Use with caution! This feature comes with no SLA.
set_bytes_offset_length(bool value)266   void set_bytes_offset_length(bool value) {
267     bytes_offset_length_ = value;
268   }
bytes_offset_length()269   bool bytes_offset_length() const {
270     return bytes_offset_length_;
271   }
272 };
273 
274 }  // namespace javanano
275 }  // namespace compiler
276 }  // namespace protobuf
277 }  // namespace google
278 #endif  // PROTOBUF_COMPILER_JAVANANO_JAVANANO_PARAMS_H_
279