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
40namespace google {
41namespace protobuf {
42namespace compiler {
43namespace javanano {
44
45enum eMultipleFiles { JAVANANO_MUL_UNSET, JAVANANO_MUL_FALSE, JAVANANO_MUL_TRUE };
46
47// Parameters for used by the generators
48class 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
68 public:
69  Params(const string & base_name) :
70    empty_(""),
71    base_name_(base_name),
72    override_java_multiple_files_(JAVANANO_MUL_UNSET),
73    store_unknown_fields_(false),
74    generate_has_(false),
75    java_enum_style_(false),
76    optional_field_accessors_(false),
77    use_reference_types_for_primitives_(false),
78    generate_equals_(false),
79    ignore_services_(false),
80    parcelable_messages_(false) {
81  }
82
83  const string& base_name() const {
84    return base_name_;
85  }
86
87  bool has_java_package(const string& file_name) const {
88    return java_packages_.find(file_name)
89                        != java_packages_.end();
90  }
91  void set_java_package(const string& file_name,
92      const string& java_package) {
93    java_packages_[file_name] = java_package;
94  }
95  const string& java_package(const string& file_name) const {
96    NameMap::const_iterator itr;
97
98    itr = java_packages_.find(file_name);
99    if  (itr == java_packages_.end()) {
100      return empty_;
101    } else {
102      return itr->second;
103    }
104  }
105  const NameMap& java_packages() {
106    return java_packages_;
107  }
108
109  bool has_java_outer_classname(const string& file_name) const {
110    return java_outer_classnames_.find(file_name)
111                        != java_outer_classnames_.end();
112  }
113  void set_java_outer_classname(const string& file_name,
114      const string& java_outer_classname) {
115    java_outer_classnames_[file_name] = java_outer_classname;
116  }
117  const string& java_outer_classname(const string& file_name) const {
118    NameMap::const_iterator itr;
119
120    itr = java_outer_classnames_.find(file_name);
121    if  (itr == java_outer_classnames_.end()) {
122      return empty_;
123    } else {
124      return itr->second;
125    }
126  }
127  const NameMap& java_outer_classnames() {
128    return java_outer_classnames_;
129  }
130
131  void set_override_java_multiple_files(bool java_multiple_files) {
132    if (java_multiple_files) {
133      override_java_multiple_files_ = JAVANANO_MUL_TRUE;
134    } else {
135      override_java_multiple_files_ = JAVANANO_MUL_FALSE;
136    }
137  }
138  void clear_override_java_multiple_files() {
139    override_java_multiple_files_ = JAVANANO_MUL_UNSET;
140  }
141
142  void set_java_multiple_files(const string& file_name, bool value) {
143    if (value) {
144      java_multiple_files_.insert(file_name);
145    } else {
146      java_multiple_files_.erase(file_name);
147    }
148  }
149  bool java_multiple_files(const string& file_name) const {
150    switch (override_java_multiple_files_) {
151      case JAVANANO_MUL_FALSE:
152        return false;
153      case JAVANANO_MUL_TRUE:
154        return true;
155      default:
156        return java_multiple_files_.find(file_name)
157                != java_multiple_files_.end();
158    }
159  }
160
161  void set_store_unknown_fields(bool value) {
162    store_unknown_fields_ = value;
163  }
164  bool store_unknown_fields() const {
165    return store_unknown_fields_;
166  }
167
168  void set_generate_has(bool value) {
169    generate_has_ = value;
170  }
171  bool generate_has() const {
172    return generate_has_;
173  }
174
175  void set_java_enum_style(bool value) {
176    java_enum_style_ = value;
177  }
178  bool java_enum_style() const {
179    return java_enum_style_;
180  }
181
182  void set_optional_field_accessors(bool value) {
183    optional_field_accessors_ = value;
184  }
185  bool optional_field_accessors() const {
186    return optional_field_accessors_;
187  }
188
189  void set_use_reference_types_for_primitives(bool value) {
190    use_reference_types_for_primitives_ = value;
191  }
192  bool use_reference_types_for_primitives() const {
193    return use_reference_types_for_primitives_;
194  }
195
196  void set_generate_equals(bool value) {
197    generate_equals_ = value;
198  }
199  bool generate_equals() const {
200    return generate_equals_;
201  }
202
203  void set_ignore_services(bool value) {
204    ignore_services_ = value;
205  }
206  bool ignore_services() const {
207    return ignore_services_;
208  }
209
210  void set_parcelable_messages(bool value) {
211    parcelable_messages_ = value;
212  }
213  bool parcelable_messages() const {
214    return parcelable_messages_;
215  }
216};
217
218}  // namespace javanano
219}  // namespace compiler
220}  // namespace protobuf
221}  // namespace google
222#endif  // PROTOBUF_COMPILER_JAVANANO_JAVANANO_PARAMS_H_
223