javamicro_params.h revision e2d542951c059563a3b7f74c257dac4f222d9dc5
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 <google/protobuf/stubs/strutil.h> 38 39namespace google { 40namespace protobuf { 41namespace compiler { 42namespace javamicro { 43 44enum eOptimization { JAVAMICRO_OPT_SPEED, JAVAMICRO_OPT_SPACE, JAVAMICRO_OPT_DEFAULT = JAVAMICRO_OPT_SPACE }; 45 46// Parameters for used by the generators 47class Params { 48 public: 49 typedef map<string, string> NameMap; 50 private: 51 string empty_; 52 string base_name_; 53 eOptimization optimization_; 54 bool java_multiple_files_; 55 bool java_use_vector_; 56 NameMap java_packages_; 57 NameMap java_outer_classnames_; 58 59 public: 60 Params(const string & base_name) : 61 empty_(""), 62 base_name_(base_name), 63 optimization_(JAVAMICRO_OPT_DEFAULT), 64 java_multiple_files_(false), 65 java_use_vector_(false) { 66 } 67 68 const string& base_name() const { 69 return base_name_; 70 } 71 72 bool has_java_package(const string& file_name) const { 73 return java_packages_.find(file_name) 74 != java_packages_.end(); 75 } 76 void set_java_package(const string& file_name, 77 const string& java_package) { 78 java_packages_[file_name] = java_package; 79 } 80 const string& java_package(const string& file_name) const { 81 NameMap::const_iterator itr; 82 83 itr = java_packages_.find(file_name); 84 if (itr == java_packages_.end()) { 85 return empty_; 86 } else { 87 return itr->second; 88 } 89 } 90 const NameMap& java_packages() { 91 return java_packages_; 92 } 93 94 bool has_java_outer_classname(const string& file_name) const { 95 return java_outer_classnames_.find(file_name) 96 != java_outer_classnames_.end(); 97 } 98 void set_java_outer_classname(const string& file_name, 99 const string& java_outer_classname) { 100 java_outer_classnames_[file_name] = java_outer_classname; 101 } 102 const string& java_outer_classname(const string& file_name) const { 103 NameMap::const_iterator itr; 104 105 itr = java_outer_classnames_.find(file_name); 106 if (itr == java_outer_classnames_.end()) { 107 return empty_; 108 } else { 109 return itr->second; 110 } 111 } 112 const NameMap& java_outer_classnames() { 113 return java_outer_classnames_; 114 } 115 116 void set_optimization(eOptimization optimization) { 117 optimization_ = optimization; 118 } 119 eOptimization optimization() const { 120 return optimization_; 121 } 122 123 void set_java_multiple_files(bool value) { 124 java_multiple_files_ = value; 125 } 126 bool java_multiple_files() const { 127 return java_multiple_files_; 128 } 129 130 void set_java_use_vector(bool value) { 131 java_use_vector_ = value; 132 } 133 bool java_use_vector() const { 134 return java_use_vector_; 135 } 136 137}; 138 139} // namespace javamicro 140} // namespace compiler 141} // namespace protobuf 142} // namespace google 143#endif // PROTOBUF_COMPILER_JAVAMICRO_JAVAMICRO_PARAMS_H_ 144