file.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package cc
  2. const moduleFileTpl = `// Code generated by protoc-gen-validate
  3. // source: {{ .InputPath }}
  4. // DO NOT EDIT!!!
  5. #include "{{ output .File ".validate.h" }}"
  6. #include <google/protobuf/message.h>
  7. #include <google/protobuf/util/time_util.h>
  8. #include "re2/re2.h"
  9. namespace pgv {
  10. namespace protobuf = google::protobuf;
  11. namespace protobuf_wkt = google::protobuf;
  12. namespace validate {
  13. using std::string;
  14. // define the regex for a UUID once up-front
  15. const re2::RE2 _uuidPattern("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
  16. {{ range .AllMessages }}
  17. {{- if not (ignored .) -}}
  18. {{- if not (disabled .) -}}
  19. pgv::Validator<{{ class . }}> {{ staticVarName . }}(static_cast<bool(*)(const {{ class .}}&, pgv::ValidationMsg*)>({{ package .}}::Validate));
  20. {{- end -}}
  21. {{ end }}
  22. {{ end }}
  23. } // namespace validate
  24. } // namespace pgv
  25. {{ range .Package.ProtoName.Split }}
  26. namespace {{ . }} {
  27. {{- end }}
  28. {{ range .AllMessages }}
  29. {{- template "msg" . }}
  30. {{ end }}
  31. {{ range .Package.ProtoName.Split -}}
  32. } // namespace
  33. {{ end }}
  34. `
  35. const headerFileTpl = `// Code generated by protoc-gen-validate
  36. // source: {{ .InputPath }}
  37. // DO NOT EDIT!!!
  38. #pragma once
  39. #include <algorithm>
  40. #include <string>
  41. #include <sstream>
  42. #include <unordered_set>
  43. #include <vector>
  44. #include "validate/validate.h"
  45. #include "{{ output .File ".h" }}"
  46. {{ range .Package.ProtoName.Split }}
  47. namespace {{ . }} {
  48. {{- end }}
  49. using std::string;
  50. {{ range .AllMessages }}
  51. {{- template "decl" . }}
  52. {{ end }}
  53. {{ range .Package.ProtoName.Split -}}
  54. } // namespace
  55. {{ end }}
  56. #define X_{{ .Package.ProtoName.ScreamingSnakeCase }}_{{ .File.InputPath.BaseName | screaming_snake_case }}(X) \
  57. {{ range .AllMessages -}}
  58. {{- if not (ignored .) -}}
  59. X({{class . }}) \
  60. {{ end -}}
  61. {{ end }}
  62. `