SerializationStructCompiler.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Copyright The kNet Project.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License. */
  11. #pragma once
  12. /** @file SerializationStructCompiler.h
  13. @brief The SerializationStructCompiler class. */
  14. #include <string>
  15. #include <fstream>
  16. #include "MessageListParser.h"
  17. namespace kNet
  18. {
  19. /// Generates .h files out of XML description files for serializable structs and network messages.
  20. class SerializationStructCompiler
  21. {
  22. public:
  23. void CompileStruct(const SerializedElementDesc &structure, const char *outfile);
  24. void CompileMessage(const SerializedMessageDesc &message, const char *outfile);
  25. static std::string ParseToValidCSymbolName(const char *str);
  26. private:
  27. void WriteFilePreamble(std::ofstream &out);
  28. void WriteStruct(const SerializedElementDesc &elem, int level, std::ofstream &out);
  29. void WriteMessage(const SerializedMessageDesc &message, std::ofstream &out);
  30. void WriteMemberDefinition(const SerializedElementDesc &elem, int level, std::ofstream &out);
  31. void WriteStructMembers(const SerializedElementDesc &elem, int level, std::ofstream &out);
  32. void WriteNestedStructs(const SerializedElementDesc &elem, int level, std::ofstream &out);
  33. void WriteStructSizeMemberFunction(const SerializedElementDesc &elem, int level, std::ofstream &out);
  34. void WriteSerializeMemberFunction(/*const std::string &className, */const SerializedElementDesc &elem, int level, std::ofstream &out);
  35. void WriteDeserializeMemberFunction(/*const std::string &className, */const SerializedElementDesc &elem, int level, std::ofstream &out);
  36. static std::string Indent(int level);
  37. };
  38. } // ~kNet