• 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_JAVAMICRO_JAVAMICRO_PARAMS_H_
34 #define PROTOBUF_COMPILER_JAVAMICRO_JAVAMICRO_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 javamicro {
44 
45 enum eOptimization { JAVAMICRO_OPT_SPEED, JAVAMICRO_OPT_SPACE, JAVAMICRO_OPT_DEFAULT = JAVAMICRO_OPT_SPACE };
46 enum eMultipleFiles { JAVAMICRO_MUL_UNSET, JAVAMICRO_MUL_FALSE, JAVAMICRO_MUL_TRUE };
47 
48 // Parameters for used by the generators
49 class Params {
50  public:
51   typedef map<string, string> NameMap;
52   typedef set<string> NameSet;
53  private:
54   string empty_;
55   string base_name_;
56   eOptimization optimization_;
57   eMultipleFiles override_java_multiple_files_;
58   bool java_use_vector_;
59   NameMap java_packages_;
60   NameMap java_outer_classnames_;
61   NameSet java_multiple_files_;
62 
63  public:
Params(const string & base_name)64   Params(const string & base_name) :
65     empty_(""),
66     base_name_(base_name),
67     optimization_(JAVAMICRO_OPT_DEFAULT),
68     override_java_multiple_files_(JAVAMICRO_MUL_UNSET),
69     java_use_vector_(false) {
70   }
71 
base_name()72   const string& base_name() const {
73     return base_name_;
74   }
75 
has_java_package(const string & file_name)76   bool has_java_package(const string& file_name) const {
77     return java_packages_.find(file_name)
78                         != java_packages_.end();
79   }
set_java_package(const string & file_name,const string & java_package)80   void set_java_package(const string& file_name,
81       const string& java_package) {
82     java_packages_[file_name] = java_package;
83   }
java_package(const string & file_name)84   const string& java_package(const string& file_name) const {
85     NameMap::const_iterator itr;
86 
87     itr = java_packages_.find(file_name);
88     if  (itr == java_packages_.end()) {
89       return empty_;
90     } else {
91       return itr->second;
92     }
93   }
java_packages()94   const NameMap& java_packages() {
95     return java_packages_;
96   }
97 
has_java_outer_classname(const string & file_name)98   bool has_java_outer_classname(const string& file_name) const {
99     return java_outer_classnames_.find(file_name)
100                         != java_outer_classnames_.end();
101   }
set_java_outer_classname(const string & file_name,const string & java_outer_classname)102   void set_java_outer_classname(const string& file_name,
103       const string& java_outer_classname) {
104     java_outer_classnames_[file_name] = java_outer_classname;
105   }
java_outer_classname(const string & file_name)106   const string& java_outer_classname(const string& file_name) const {
107     NameMap::const_iterator itr;
108 
109     itr = java_outer_classnames_.find(file_name);
110     if  (itr == java_outer_classnames_.end()) {
111       return empty_;
112     } else {
113       return itr->second;
114     }
115   }
java_outer_classnames()116   const NameMap& java_outer_classnames() {
117     return java_outer_classnames_;
118   }
119 
set_optimization(eOptimization optimization)120   void set_optimization(eOptimization optimization) {
121     optimization_ = optimization;
122   }
optimization()123   eOptimization optimization() const {
124     return optimization_;
125   }
126 
set_override_java_multiple_files(bool value)127   void set_override_java_multiple_files(bool value) {
128     if (value) {
129       override_java_multiple_files_ = JAVAMICRO_MUL_TRUE;
130     } else {
131       override_java_multiple_files_ = JAVAMICRO_MUL_FALSE;
132     }
133   }
clear_override_java_multiple_files()134   void clear_override_java_multiple_files() {
135     override_java_multiple_files_ = JAVAMICRO_MUL_UNSET;
136   }
137 
set_java_multiple_files(const string & file_name,bool value)138   void set_java_multiple_files(const string& file_name, bool value) {
139     if (value) {
140       java_multiple_files_.insert(file_name);
141     } else {
142       java_multiple_files_.erase(file_name);
143     }
144   }
java_multiple_files(const string & file_name)145   bool java_multiple_files(const string& file_name) const {
146     switch (override_java_multiple_files_) {
147       case JAVAMICRO_MUL_FALSE:
148         return false;
149       case JAVAMICRO_MUL_TRUE:
150         return true;
151       default:
152         return java_multiple_files_.find(file_name)
153                 != java_multiple_files_.end();
154     }
155   }
156 
set_java_use_vector(bool value)157   void set_java_use_vector(bool value) {
158     java_use_vector_ = value;
159   }
java_use_vector()160   bool java_use_vector() const {
161     return java_use_vector_;
162   }
163 
164 };
165 
166 }  // namespace javamicro
167 }  // namespace compiler
168 }  // namespace protobuf
169 }  // namespace google
170 #endif  // PROTOBUF_COMPILER_JAVAMICRO_JAVAMICRO_PARAMS_H_
171