/thirdparty/breakpad/third_party/protobuf/protobuf/src/google/protobuf/compiler/code_generator.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 142 lines · 42 code · 19 blank · 81 comment · 0 complexity · fcdcfe99ceec52003b850f20cd748865 MD5 · raw file

  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 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. // Author: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. //
  34. // Defines the abstract interface implemented by each of the language-specific
  35. // code generators.
  36. #ifndef GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__
  37. #define GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__
  38. #include <google/protobuf/stubs/common.h>
  39. #include <string>
  40. #include <vector>
  41. #include <utility>
  42. namespace google {
  43. namespace protobuf {
  44. namespace io { class ZeroCopyOutputStream; }
  45. class FileDescriptor;
  46. namespace compiler {
  47. // Defined in this file.
  48. class CodeGenerator;
  49. class GeneratorContext;
  50. // The abstract interface to a class which generates code implementing a
  51. // particular proto file in a particular language. A number of these may
  52. // be registered with CommandLineInterface to support various languages.
  53. class LIBPROTOC_EXPORT CodeGenerator {
  54. public:
  55. inline CodeGenerator() {}
  56. virtual ~CodeGenerator();
  57. // Generates code for the given proto file, generating one or more files in
  58. // the given output directory.
  59. //
  60. // A parameter to be passed to the generator can be specified on the
  61. // command line. This is intended to be used by Java and similar languages
  62. // to specify which specific class from the proto file is to be generated,
  63. // though it could have other uses as well. It is empty if no parameter was
  64. // given.
  65. //
  66. // Returns true if successful. Otherwise, sets *error to a description of
  67. // the problem (e.g. "invalid parameter") and returns false.
  68. virtual bool Generate(const FileDescriptor* file,
  69. const string& parameter,
  70. GeneratorContext* generator_context,
  71. string* error) const = 0;
  72. private:
  73. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator);
  74. };
  75. // CodeGenerators generate one or more files in a given directory. This
  76. // abstract interface represents the directory to which the CodeGenerator is
  77. // to write and other information about the context in which the Generator
  78. // runs.
  79. class LIBPROTOC_EXPORT GeneratorContext {
  80. public:
  81. inline GeneratorContext() {}
  82. virtual ~GeneratorContext();
  83. // Opens the given file, truncating it if it exists, and returns a
  84. // ZeroCopyOutputStream that writes to the file. The caller takes ownership
  85. // of the returned object. This method never fails (a dummy stream will be
  86. // returned instead).
  87. //
  88. // The filename given should be relative to the root of the source tree.
  89. // E.g. the C++ generator, when generating code for "foo/bar.proto", will
  90. // generate the files "foo/bar.pb.h" and "foo/bar.pb.cc"; note that
  91. // "foo/" is included in these filenames. The filename is not allowed to
  92. // contain "." or ".." components.
  93. virtual io::ZeroCopyOutputStream* Open(const string& filename) = 0;
  94. // Creates a ZeroCopyOutputStream which will insert code into the given file
  95. // at the given insertion point. See plugin.proto (plugin.pb.h) for more
  96. // information on insertion points. The default implementation
  97. // assert-fails -- it exists only for backwards-compatibility.
  98. //
  99. // WARNING: This feature is currently EXPERIMENTAL and is subject to change.
  100. virtual io::ZeroCopyOutputStream* OpenForInsert(
  101. const string& filename, const string& insertion_point);
  102. // Returns a vector of FileDescriptors for all the files being compiled
  103. // in this run. Useful for languages, such as Go, that treat files
  104. // differently when compiled as a set rather than individually.
  105. virtual void ListParsedFiles(vector<const FileDescriptor*>* output);
  106. private:
  107. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext);
  108. };
  109. // The type GeneratorContext was once called OutputDirectory. This typedef
  110. // provides backward compatibility.
  111. typedef GeneratorContext OutputDirectory;
  112. // Several code generators treat the parameter argument as holding a
  113. // list of options separated by commas. This helper function parses
  114. // a set of comma-delimited name/value pairs: e.g.,
  115. // "foo=bar,baz,qux=corge"
  116. // parses to the pairs:
  117. // ("foo", "bar"), ("baz", ""), ("qux", "corge")
  118. extern void ParseGeneratorParameter(const string&,
  119. vector<pair<string, string> >*);
  120. } // namespace compiler
  121. } // namespace protobuf
  122. } // namespace google
  123. #endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__