| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // separate Importer object to import each one (but use the same | 159 // separate Importer object to import each one (but use the same |
| 160 // DescriptorPool so that they can be cross-linked). | 160 // DescriptorPool so that they can be cross-linked). |
| 161 const FileDescriptor* Import(const string& filename); | 161 const FileDescriptor* Import(const string& filename); |
| 162 | 162 |
| 163 // The DescriptorPool in which all imported FileDescriptors and their | 163 // The DescriptorPool in which all imported FileDescriptors and their |
| 164 // contents are stored. | 164 // contents are stored. |
| 165 inline const DescriptorPool* pool() const { | 165 inline const DescriptorPool* pool() const { |
| 166 return &pool_; | 166 return &pool_; |
| 167 } | 167 } |
| 168 | 168 |
| 169 void AddUnusedImportTrackFile(const string& file_name); |
| 170 void ClearUnusedImportTrackFiles(); |
| 171 |
| 169 private: | 172 private: |
| 170 SourceTreeDescriptorDatabase database_; | 173 SourceTreeDescriptorDatabase database_; |
| 171 DescriptorPool pool_; | 174 DescriptorPool pool_; |
| 172 | 175 |
| 173 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Importer); | 176 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Importer); |
| 174 }; | 177 }; |
| 175 | 178 |
| 176 // If the importer encounters problems while trying to import the proto files, | 179 // If the importer encounters problems while trying to import the proto files, |
| 177 // it reports them to a MultiFileErrorCollector. | 180 // it reports them to a MultiFileErrorCollector. |
| 178 class LIBPROTOBUF_EXPORT MultiFileErrorCollector { | 181 class LIBPROTOBUF_EXPORT MultiFileErrorCollector { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 197 public: | 200 public: |
| 198 inline SourceTree() {} | 201 inline SourceTree() {} |
| 199 virtual ~SourceTree(); | 202 virtual ~SourceTree(); |
| 200 | 203 |
| 201 // Open the given file and return a stream that reads it, or NULL if not | 204 // Open the given file and return a stream that reads it, or NULL if not |
| 202 // found. The caller takes ownership of the returned object. The filename | 205 // found. The caller takes ownership of the returned object. The filename |
| 203 // must be a path relative to the root of the source tree and must not | 206 // must be a path relative to the root of the source tree and must not |
| 204 // contain "." or ".." components. | 207 // contain "." or ".." components. |
| 205 virtual io::ZeroCopyInputStream* Open(const string& filename) = 0; | 208 virtual io::ZeroCopyInputStream* Open(const string& filename) = 0; |
| 206 | 209 |
| 210 // If Open() returns NULL, calling this method immediately will return an |
| 211 // description of the error. |
| 212 // Subclasses should implement this method and return a meaningful value for |
| 213 // better error reporting. |
| 214 // TODO(xiaofeng): change this to a pure virtual function. |
| 215 virtual string GetLastErrorMessage(); |
| 216 |
| 207 private: | 217 private: |
| 208 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree); | 218 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree); |
| 209 }; | 219 }; |
| 210 | 220 |
| 211 // An implementation of SourceTree which loads files from locations on disk. | 221 // An implementation of SourceTree which loads files from locations on disk. |
| 212 // Multiple mappings can be set up to map locations in the DiskSourceTree to | 222 // Multiple mappings can be set up to map locations in the DiskSourceTree to |
| 213 // locations in the physical filesystem. | 223 // locations in the physical filesystem. |
| 214 class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { | 224 class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { |
| 215 public: | 225 public: |
| 216 DiskSourceTree(); | 226 DiskSourceTree(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 DiskFileToVirtualFile(const string& disk_file, | 276 DiskFileToVirtualFile(const string& disk_file, |
| 267 string* virtual_file, | 277 string* virtual_file, |
| 268 string* shadowing_disk_file); | 278 string* shadowing_disk_file); |
| 269 | 279 |
| 270 // Given a virtual path, find the path to the file on disk. | 280 // Given a virtual path, find the path to the file on disk. |
| 271 // Return true and update disk_file with the on-disk path if the file exists. | 281 // Return true and update disk_file with the on-disk path if the file exists. |
| 272 // Return false and leave disk_file untouched if the file doesn't exist. | 282 // Return false and leave disk_file untouched if the file doesn't exist. |
| 273 bool VirtualFileToDiskFile(const string& virtual_file, string* disk_file); | 283 bool VirtualFileToDiskFile(const string& virtual_file, string* disk_file); |
| 274 | 284 |
| 275 // implements SourceTree ------------------------------------------- | 285 // implements SourceTree ------------------------------------------- |
| 276 io::ZeroCopyInputStream* Open(const string& filename); | 286 virtual io::ZeroCopyInputStream* Open(const string& filename); |
| 287 |
| 288 virtual string GetLastErrorMessage(); |
| 277 | 289 |
| 278 private: | 290 private: |
| 279 struct Mapping { | 291 struct Mapping { |
| 280 string virtual_path; | 292 string virtual_path; |
| 281 string disk_path; | 293 string disk_path; |
| 282 | 294 |
| 283 inline Mapping(const string& virtual_path_param, | 295 inline Mapping(const string& virtual_path_param, |
| 284 const string& disk_path_param) | 296 const string& disk_path_param) |
| 285 : virtual_path(virtual_path_param), disk_path(disk_path_param) {} | 297 : virtual_path(virtual_path_param), disk_path(disk_path_param) {} |
| 286 }; | 298 }; |
| 287 vector<Mapping> mappings_; | 299 vector<Mapping> mappings_; |
| 300 string last_error_message_; |
| 288 | 301 |
| 289 // Like Open(), but returns the on-disk path in disk_file if disk_file is | 302 // Like Open(), but returns the on-disk path in disk_file if disk_file is |
| 290 // non-NULL and the file could be successfully opened. | 303 // non-NULL and the file could be successfully opened. |
| 291 io::ZeroCopyInputStream* OpenVirtualFile(const string& virtual_file, | 304 io::ZeroCopyInputStream* OpenVirtualFile(const string& virtual_file, |
| 292 string* disk_file); | 305 string* disk_file); |
| 293 | 306 |
| 294 // Like Open() but given the actual on-disk path. | 307 // Like Open() but given the actual on-disk path. |
| 295 io::ZeroCopyInputStream* OpenDiskFile(const string& filename); | 308 io::ZeroCopyInputStream* OpenDiskFile(const string& filename); |
| 296 | 309 |
| 297 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree); | 310 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree); |
| 298 }; | 311 }; |
| 299 | 312 |
| 300 } // namespace compiler | 313 } // namespace compiler |
| 301 } // namespace protobuf | 314 } // namespace protobuf |
| 302 | 315 |
| 303 } // namespace google | 316 } // namespace google |
| 304 #endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ | 317 #endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ |
| OLD | NEW |