27 #include <SimoxUtility/algorithm/string/string_tools.h>
29 #include <boost/format.hpp>
36 CppClass::CppClass(
const std::vector<std::string>& namespaces,
const std::string& name,
const std::string& templates)
39 this->namespaces = namespaces;
40 this->templates = templates;
45 CppWriterPtr w = std::dynamic_pointer_cast<CppWriter>(writer);
51 for (
const auto& meta : classes)
53 meta->writeCpp(writer);
60 if (includes.size() > 0)
62 for (
const auto& incl : includes)
64 writer->header.lineCheckDuplicate(
boost::str(boost::format(
"#include %s") % incl));
66 writer->header.line();
69 for (
const auto& ns : namespaces)
71 writer->body.startBlock(std::string(
"namespace ") + ns);
76 const std::string preSpace =
" ";
77 writer->body.line(
"/**");
79 std::vector<std::string> blockLines;
80 writer->ConvertToTextWithMaxWidth(80, docLines, blockLines);
82 for (
auto& line : blockLines)
84 writer->body.line(preSpace + line);
87 writer->body.line(
" */");
89 if (!templates.empty())
91 writer->body.line(templates);
94 writer->body.line(std::string(
"class ") +
name);
96 for (
size_t i = 0; i < inherit.size(); i++)
98 writer->body.line(
boost::str(boost::format(
"%s%s%s") % (i == 0 ?
": " :
" ") % inherit.at(i) % (i < inherit.size() - 1 ?
"," :
"")), 1);
101 writer->body.startBlock();
103 if (innerEnums.size() > 0)
105 writer->body.line(
"public:", -1);
108 for (
const auto& inner : innerEnums)
110 inner->writeCpp(writer);
115 if (innerClasses.size() > 0)
117 writer->body.line(
"protected:", -1);
120 for (
const auto& inner : innerClasses)
122 inner->writeCpp(writer);
127 if (privateFields.size() > 0)
129 writer->body.line(
"private:", -1);
132 for (
const auto& field : privateFields)
134 field->writeCpp(writer);
139 if (protectedFields.size() > 0)
141 writer->body.line(
"protected:", -1);
144 for (
const auto& field : protectedFields)
146 field->writeCpp(writer);
151 if (publicFields.size() > 0)
153 writer->body.line(
"public:", -1);
156 for (
const auto& field : publicFields)
158 field->writeCpp(writer);
163 if (ctors.size() > 0)
165 writer->body.line(
"public:", -1);
168 for (
const auto& ctor : ctors)
170 ctor->writeCpp(writer);
175 if (publicMethods.size() > 0)
177 writer->body.line(
"public:", -1);
180 for (
const auto& method : publicMethods)
182 method->writeCpp(writer);
187 writer->body.endBlock(
"; // class " +
name);
189 for (std::vector<std::string>::reverse_iterator it = namespaces.rbegin(); it != namespaces.rend(); it++)
191 writer->body.endBlockComment(std::string(
"namespace ") + *it);
198 publicMethods.push_back(method);
204 publicMethods.push_back(method);
210 ctors.push_back(ctor);
216 ctors.push_back(ctor);
223 ctors.push_back(ctor);
230 privateFields.push_back(field);
236 protectedFields.push_back(field);
242 publicFields.push_back(field);
248 innerClasses.push_back(innerClass);
254 innerClasses.push_back(inner);
261 innerEnums.push_back(inner);
267 innerEnums.push_back(innerEnum);
273 this->inherit.push_back(inherit);
278 includes.push_back(include);
283 return (std::find(includes.begin(), includes.end(), include) != includes.end());