| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // http://code.google.com/p/protobuf/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| 11 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
| 12 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
| 13 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | 30 |
| 31 // Author: kenton@google.com (Kenton Varda) | 31 // Author: kenton@google.com (Kenton Varda) |
| 32 // Based on original Protocol Buffers design by | 32 // Based on original Protocol Buffers design by |
| 33 // Sanjay Ghemawat, Jeff Dean, and others. | 33 // Sanjay Ghemawat, Jeff Dean, and others. |
| 34 | 34 |
| 35 #include <google/protobuf/compiler/cpp/cpp_generator.h> | 35 #include <google/protobuf/compiler/cpp/cpp_generator.h> |
| 36 | 36 |
| 37 #include <vector> | 37 #include <vector> |
| 38 #include <memory> |
| 39 #ifndef _SHARED_PTR_H |
| 40 #include <google/protobuf/stubs/shared_ptr.h> |
| 41 #endif |
| 38 #include <utility> | 42 #include <utility> |
| 39 | 43 |
| 40 #include <google/protobuf/compiler/cpp/cpp_file.h> | 44 #include <google/protobuf/compiler/cpp/cpp_file.h> |
| 41 #include <google/protobuf/compiler/cpp/cpp_helpers.h> | 45 #include <google/protobuf/compiler/cpp/cpp_helpers.h> |
| 42 #include <google/protobuf/io/printer.h> | 46 #include <google/protobuf/io/printer.h> |
| 43 #include <google/protobuf/io/zero_copy_stream.h> | 47 #include <google/protobuf/io/zero_copy_stream.h> |
| 44 #include <google/protobuf/descriptor.pb.h> | 48 #include <google/protobuf/descriptor.pb.h> |
| 45 | 49 |
| 46 namespace google { | 50 namespace google { |
| 47 namespace protobuf { | 51 namespace protobuf { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 71 // it in front of every symbol that should be exported if this .proto is | 75 // it in front of every symbol that should be exported if this .proto is |
| 72 // compiled into a Windows DLL. E.g., if the user invokes the protocol | 76 // compiled into a Windows DLL. E.g., if the user invokes the protocol |
| 73 // compiler as: | 77 // compiler as: |
| 74 // protoc --cpp_out=dllexport_decl=FOO_EXPORT:outdir foo.proto | 78 // protoc --cpp_out=dllexport_decl=FOO_EXPORT:outdir foo.proto |
| 75 // then we'll define classes like this: | 79 // then we'll define classes like this: |
| 76 // class FOO_EXPORT Foo { | 80 // class FOO_EXPORT Foo { |
| 77 // ... | 81 // ... |
| 78 // } | 82 // } |
| 79 // FOO_EXPORT is a macro which should expand to __declspec(dllexport) or | 83 // FOO_EXPORT is a macro which should expand to __declspec(dllexport) or |
| 80 // __declspec(dllimport) depending on what is being compiled. | 84 // __declspec(dllimport) depending on what is being compiled. |
| 85 // |
| 81 Options file_options; | 86 Options file_options; |
| 82 | 87 |
| 83 for (int i = 0; i < options.size(); i++) { | 88 for (int i = 0; i < options.size(); i++) { |
| 84 if (options[i].first == "dllexport_decl") { | 89 if (options[i].first == "dllexport_decl") { |
| 85 file_options.dllexport_decl = options[i].second; | 90 file_options.dllexport_decl = options[i].second; |
| 86 } else if (options[i].first == "safe_boundary_check") { | 91 } else if (options[i].first == "safe_boundary_check") { |
| 87 file_options.safe_boundary_check = true; | 92 file_options.safe_boundary_check = true; |
| 88 } else { | 93 } else { |
| 89 *error = "Unknown generator option: " + options[i].first; | 94 *error = "Unknown generator option: " + options[i].first; |
| 90 return false; | 95 return false; |
| 91 } | 96 } |
| 92 } | 97 } |
| 93 | 98 |
| 94 // ----------------------------------------------------------------- | 99 // ----------------------------------------------------------------- |
| 95 | 100 |
| 96 | 101 |
| 97 string basename = StripProto(file->name()); | 102 string basename = StripProto(file->name()); |
| 98 basename.append(".pb"); | |
| 99 | 103 |
| 100 FileGenerator file_generator(file, file_options); | 104 FileGenerator file_generator(file, file_options); |
| 101 | 105 |
| 102 // Generate header. | 106 // Generate header(s). |
| 107 if (file_options.proto_h) { |
| 108 google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output( |
| 109 generator_context->Open(basename + ".proto.h")); |
| 110 io::Printer printer(output.get(), '$'); |
| 111 file_generator.GenerateProtoHeader(&printer); |
| 112 } |
| 113 |
| 114 basename.append(".pb"); |
| 103 { | 115 { |
| 104 scoped_ptr<io::ZeroCopyOutputStream> output( | 116 google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output( |
| 105 generator_context->Open(basename + ".h")); | 117 generator_context->Open(basename + ".h")); |
| 106 io::Printer printer(output.get(), '$'); | 118 io::Printer printer(output.get(), '$'); |
| 107 file_generator.GenerateHeader(&printer); | 119 file_generator.GeneratePBHeader(&printer); |
| 108 } | 120 } |
| 109 | 121 |
| 110 // Generate cc file. | 122 // Generate cc file. |
| 111 { | 123 { |
| 112 scoped_ptr<io::ZeroCopyOutputStream> output( | 124 google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output( |
| 113 generator_context->Open(basename + ".cc")); | 125 generator_context->Open(basename + ".cc")); |
| 114 io::Printer printer(output.get(), '$'); | 126 io::Printer printer(output.get(), '$'); |
| 115 file_generator.GenerateSource(&printer); | 127 file_generator.GenerateSource(&printer); |
| 116 } | 128 } |
| 117 | 129 |
| 118 return true; | 130 return true; |
| 119 } | 131 } |
| 120 | 132 |
| 121 } // namespace cpp | 133 } // namespace cpp |
| 122 } // namespace compiler | 134 } // namespace compiler |
| 123 } // namespace protobuf | 135 } // namespace protobuf |
| 124 } // namespace google | 136 } // namespace google |
| OLD | NEW |