private void GenerateHeaders(AttributeClass attributeClass) { var code = new SourceCode(); code.Append("#pragma once"); code.NewLine(); code.Append("#include \"cbes/attribute.h\""); code.NewLine(); code.BracketStart("struct {0} : public attribute_t<{0}>", attributeClass.StructName); foreach (var attributeField in attributeClass.Fields) { code.Append("{2}{0} {1};", TypeUtil.ToDeclareTypeName(attributeField.Type), attributeField.Name, attributeField.Volatile ? "volatile " : ""); } code.NewLine(); code.Append("// default constructor"); var constructorArgs = attributeClass.Fields.Select( e => string.Format("{0}({1})", e.Name, e.Default ?? TypeUtil.ToDefaultValueInInitializer(e.Type))).ToList(); if (constructorArgs.Count > 0) { code.Append("{0}()", attributeClass.StructName); code.IndentRight(); code.Append(": {0} {{}}", string.Join(", ", constructorArgs)); code.IndentLeft(); } else { code.Append("{0}() {{}}", attributeClass.StructName); } if (attributeClass.NonDefaultFields.Any()) { code.NewLine(); code.Append("// argumented constructor"); var paramArgs = new List <string>(); var initializeArgs = new List <string>(); // default가 없는 field를 대상으로만 argumented constructor를 만들어준다. foreach (var attributeField in attributeClass.Fields) { if (attributeField.Default == null) { paramArgs.Add(string.Format("{0} _{1}", TypeUtil.ToArgumentTypeName(attributeField.Type), attributeField.Name)); initializeArgs.Add(string.Format("{0}(_{0})", attributeField.Name)); } else { initializeArgs.Add(string.Format("{0}({1})", attributeField.Name, attributeField.Default)); } } if (initializeArgs.Count > 0) { code.Append("{0}({1})", attributeClass.StructName, string.Join(", ", paramArgs)); code.IndentRight(); code.Append(": {0} {{}}", string.Join(", ", initializeArgs)); code.IndentLeft(); } } code.NewLine(); code.Append(SourceCode.Parse(@" virtual void from_bson(bson_iterator*); virtual void to_bson(bson*); virtual void from_xml(TiXmlElement*); virtual void to_xml(std::ostream&);".Trim())); if (attributeClass.CustomCode != null) { code.NewLine(); code.Append(SourceCode.Parse(attributeClass.CustomCode)); } code.BracketEnd(";"); code.Append("typedef boost::shared_ptr<{0}> {1};", attributeClass.StructName, attributeClass.ReferenceName); code.NewLine(); var headerPath = Path.Combine(_outputDirectory, attributeClass.HeaderFileName); code.WriteToFile(headerPath); }