BWAPI
|
00001 // Protocol Buffers - Google's data interchange format 00002 // Copyright 2008 Google Inc. All rights reserved. 00003 // http://code.google.com/p/protobuf/ 00004 // 00005 // Redistribution and use in source and binary forms, with or without 00006 // modification, are permitted provided that the following conditions are 00007 // met: 00008 // 00009 // * Redistributions of source code must retain the above copyright 00010 // notice, this list of conditions and the following disclaimer. 00011 // * Redistributions in binary form must reproduce the above 00012 // copyright notice, this list of conditions and the following disclaimer 00013 // in the documentation and/or other materials provided with the 00014 // distribution. 00015 // * Neither the name of Google Inc. nor the names of its 00016 // contributors may be used to endorse or promote products derived from 00017 // this software without specific prior written permission. 00018 // 00019 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00023 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00025 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00026 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00027 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00029 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 00031 // Author: kenton@google.com (Kenton Varda) 00032 // Based on original Protocol Buffers design by 00033 // Sanjay Ghemawat, Jeff Dean, and others. 00034 // 00035 // Defines the abstract interface implemented by each of the language-specific 00036 // code generators. 00037 00038 #ifndef GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ 00039 #define GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ 00040 00041 #include <google/protobuf/stubs/common.h> 00042 #include <string> 00043 #include <vector> 00044 #include <utility> 00045 00046 namespace google { 00047 namespace protobuf { 00048 00049 namespace io { class ZeroCopyOutputStream; } 00050 class FileDescriptor; 00051 00052 namespace compiler { 00053 00054 // Defined in this file. 00055 class CodeGenerator; 00056 class OutputDirectory; 00057 00058 // The abstract interface to a class which generates code implementing a 00059 // particular proto file in a particular language. A number of these may 00060 // be registered with CommandLineInterface to support various languages. 00061 class LIBPROTOC_EXPORT CodeGenerator { 00062 public: 00063 inline CodeGenerator() {} 00064 virtual ~CodeGenerator(); 00065 00066 // Generates code for the given proto file, generating one or more files in 00067 // the given output directory. 00068 // 00069 // A parameter to be passed to the generator can be specified on the 00070 // command line. This is intended to be used by Java and similar languages 00071 // to specify which specific class from the proto file is to be generated, 00072 // though it could have other uses as well. It is empty if no parameter was 00073 // given. 00074 // 00075 // Returns true if successful. Otherwise, sets *error to a description of 00076 // the problem (e.g. "invalid parameter") and returns false. 00077 virtual bool Generate(const FileDescriptor* file, 00078 const string& parameter, 00079 OutputDirectory* output_directory, 00080 string* error) const = 0; 00081 00082 private: 00083 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator); 00084 }; 00085 00086 // CodeGenerators generate one or more files in a given directory. This 00087 // abstract interface represents the directory to which the CodeGenerator is 00088 // to write. 00089 class LIBPROTOC_EXPORT OutputDirectory { 00090 public: 00091 inline OutputDirectory() {} 00092 virtual ~OutputDirectory(); 00093 00094 // Opens the given file, truncating it if it exists, and returns a 00095 // ZeroCopyOutputStream that writes to the file. The caller takes ownership 00096 // of the returned object. This method never fails (a dummy stream will be 00097 // returned instead). 00098 // 00099 // The filename given should be relative to the root of the source tree. 00100 // E.g. the C++ generator, when generating code for "foo/bar.proto", will 00101 // generate the files "foo/bar.pb.h" and "foo/bar.pb.cc"; note that 00102 // "foo/" is included in these filenames. The filename is not allowed to 00103 // contain "." or ".." components. 00104 virtual io::ZeroCopyOutputStream* Open(const string& filename) = 0; 00105 00106 // Creates a ZeroCopyOutputStream which will insert code into the given file 00107 // at the given insertion point. See plugin.proto (plugin.pb.h) for more 00108 // information on insertion points. The default implementation 00109 // assert-fails -- it exists only for backwards-compatibility. 00110 // 00111 // WARNING: This feature is currently EXPERIMENTAL and is subject to change. 00112 virtual io::ZeroCopyOutputStream* OpenForInsert( 00113 const string& filename, const string& insertion_point); 00114 00115 private: 00116 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OutputDirectory); 00117 }; 00118 00119 // Several code generators treat the parameter argument as holding a 00120 // list of options separated by commas. This helper function parses 00121 // a set of comma-delimited name/value pairs: e.g., 00122 // "foo=bar,baz,qux=corge" 00123 // parses to the pairs: 00124 // ("foo", "bar"), ("baz", ""), ("qux", "corge") 00125 extern void ParseGeneratorParameter(const string&, 00126 vector<pair<string, string> >*); 00127 00128 } // namespace compiler 00129 } // namespace protobuf 00130 00131 } // namespace google 00132 #endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__