Ran the fixer on Generator.
[UnsignedByte.git] / src / Generator / ClassHeaderGenerator.cpp
blobbe511e3d4ec35573f6abf812a4cd81e291ef84bc
1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "Assert.h"
22 #include "ClassHeaderGenerator.h"
23 #include "FieldDef.h"
24 #include "Global.h"
25 #include "StringUtilities.h"
26 #include "TableDef.h"
27 #include "Tables.h"
29 using std::endl;
31 ClassHeaderGenerator::ClassHeaderGenerator(TableDefPtr table, std::ofstream* file, std::string ns) :
32 m_tabs("\t"),
33 m_namespace(ns),
34 m_table(table),
35 m_file(file)
37 m_name = m_table->getName();
40 ClassHeaderGenerator::~ClassHeaderGenerator()
45 void ClassHeaderGenerator::GenerateClass()
47 Assert(m_table->primarykeysize() > 0);
49 AppendHeader();
50 AppendFields();
51 AppendFooter();
54 void ClassHeaderGenerator::AppendHeader()
56 Assert(m_file);
58 (*m_file) << m_tabs << "/**" << endl;
59 (*m_file) << m_tabs << " * This is a generated class that contains all FieldImpls for the " << m_name << " table." << endl;
60 (*m_file) << m_tabs << " */" << endl;
61 (*m_file) << m_tabs << "class " << m_name << " : public TableImpl" << endl;
62 (*m_file) << m_tabs << "{" << endl;
63 (*m_file) << m_tabs << "public:" << endl;
65 return;
68 void ClassHeaderGenerator::AppendFields()
70 for(FieldDefVector::const_iterator it = m_table->begin(); it != m_table->end(); it++)
72 (*m_file) << m_tabs << m_tabs;
74 FieldDefPtr field = *it;
75 if(field->isKey())
76 (*m_file) << "KeyImplPtr ";
77 else
78 (*m_file) << "FieldImplPtr ";
80 (*m_file) << String::Get()->toupper(field->getName()) << ";";
81 (*m_file) << " /**< FieldImplPtr for the " << field->getName() << " field. */" << endl;
83 (*m_file) << endl;
86 void ClassHeaderGenerator::AppendFooter()
88 Assert(m_file);
90 (*m_file) << m_tabs << "private:" << endl;
91 (*m_file) << m_tabs << m_tabs << "/** This is a managed class, use <code>TableImpls</code> to get an instance. */" << endl;
92 (*m_file) << m_tabs << m_tabs << m_name << "(): TableImpl(\"" << m_name << "\") { }" << endl;
93 (*m_file) << endl;
95 (*m_file) << m_tabs << m_tabs << "/** This is a managed class, free <code>TableImpls</code> to free the instance. */" << endl;
96 (*m_file) << m_tabs << m_tabs << "~" << m_name << "() { }" << endl;
97 (*m_file) << endl;
99 (*m_file) << m_tabs << m_tabs << "/** Hide the copy constructor. */" << endl;
100 (*m_file) << m_tabs << m_tabs << m_name << "(const " << m_name << "& rhs);" << endl;
101 (*m_file) << endl;
103 (*m_file) << m_tabs << m_tabs << "/** Hide the assignment operator. */" << endl;
104 (*m_file) << m_tabs << m_tabs << m_name << " operator=(const " << m_name << "& rhs);" << endl;
105 (*m_file) << endl;
107 (*m_file) << m_tabs << m_tabs << "/** Initialize the table's fields. */" << endl;
108 (*m_file) << m_tabs << m_tabs << "void Initialize();" << endl;
109 (*m_file) << endl;
111 (*m_file) << m_tabs << m_tabs << "friend class TableImpls;" << endl;
112 (*m_file) << m_tabs << m_tabs << "friend SmartPtrDelete(" << m_name << ");" << endl;
113 (*m_file) << m_tabs << "};" << endl;
114 (*m_file) << endl;
116 return;