Home | History | Annotate | Download | only in javanano
      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 (at) 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 
     62  public:
     63   Params(const string & base_name) :
     64     empty_(""),
     65     base_name_(base_name),
     66     override_java_multiple_files_(JAVANANO_MUL_UNSET),
     67     store_unknown_fields_(false),
     68     generate_has_(false) {
     69   }
     70 
     71   const string& base_name() const {
     72     return base_name_;
     73   }
     74 
     75   bool has_java_package(const string& file_name) const {
     76     return java_packages_.find(file_name)
     77                         != java_packages_.end();
     78   }
     79   void set_java_package(const string& file_name,
     80       const string& java_package) {
     81     java_packages_[file_name] = java_package;
     82   }
     83   const string& java_package(const string& file_name) const {
     84     NameMap::const_iterator itr;
     85 
     86     itr = java_packages_.find(file_name);
     87     if  (itr == java_packages_.end()) {
     88       return empty_;
     89     } else {
     90       return itr->second;
     91     }
     92   }
     93   const NameMap& java_packages() {
     94     return java_packages_;
     95   }
     96 
     97   bool has_java_outer_classname(const string& file_name) const {
     98     return java_outer_classnames_.find(file_name)
     99                         != java_outer_classnames_.end();
    100   }
    101   void set_java_outer_classname(const string& file_name,
    102       const string& java_outer_classname) {
    103     java_outer_classnames_[file_name] = java_outer_classname;
    104   }
    105   const string& java_outer_classname(const string& file_name) const {
    106     NameMap::const_iterator itr;
    107 
    108     itr = java_outer_classnames_.find(file_name);
    109     if  (itr == java_outer_classnames_.end()) {
    110       return empty_;
    111     } else {
    112       return itr->second;
    113     }
    114   }
    115   const NameMap& java_outer_classnames() {
    116     return java_outer_classnames_;
    117   }
    118 
    119   void set_override_java_multiple_files(bool java_multiple_files) {
    120     if (java_multiple_files) {
    121       override_java_multiple_files_ = JAVANANO_MUL_TRUE;
    122     } else {
    123       override_java_multiple_files_ = JAVANANO_MUL_FALSE;
    124     }
    125   }
    126   void clear_override_java_multiple_files() {
    127     override_java_multiple_files_ = JAVANANO_MUL_UNSET;
    128   }
    129 
    130   void set_java_multiple_files(const string& file_name, bool value) {
    131     if (value) {
    132       java_multiple_files_.insert(file_name);
    133     } else {
    134       java_multiple_files_.erase(file_name);
    135     }
    136   }
    137   bool java_multiple_files(const string& file_name) const {
    138     switch (override_java_multiple_files_) {
    139       case JAVANANO_MUL_FALSE:
    140         return false;
    141       case JAVANANO_MUL_TRUE:
    142         return true;
    143       default:
    144         return java_multiple_files_.find(file_name)
    145                 != java_multiple_files_.end();
    146     }
    147   }
    148 
    149   void set_store_unknown_fields(bool value) {
    150     store_unknown_fields_ = value;
    151   }
    152   bool store_unknown_fields() const {
    153     return store_unknown_fields_;
    154   }
    155 
    156   void set_generate_has(bool value) {
    157     generate_has_ = value;
    158   }
    159   bool generate_has() const {
    160     return generate_has_;
    161   }
    162 
    163 };
    164 
    165 }  // namespace javanano
    166 }  // namespace compiler
    167 }  // namespace protobuf
    168 }  // namespace google
    169 #endif  // PROTOBUF_COMPILER_JAVANANO_JAVANANO_PARAMS_H_
    170