1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
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. *
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. *
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 ***************************************************************************/
22 #include "ClassHeaderGenerator.h"
27 #include "StringUtilities.h"
31 ClassHeaderGenerator::ClassHeaderGenerator(TableDefPtr table
, std::ofstream
* file
, std::string ns
) :
37 m_name
= m_table
->getName();
40 ClassHeaderGenerator::~ClassHeaderGenerator()
45 void ClassHeaderGenerator::GenerateClass()
47 Assert(m_table
->primarykeysize() > 0);
54 void ClassHeaderGenerator::AppendHeader()
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
;
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
;
76 (*m_file
) << "KeyImplPtr ";
78 (*m_file
) << "FieldImplPtr ";
80 (*m_file
) << String::Get()->toupper(field
->getName()) << ";";
81 (*m_file
) << " /**< FieldImplPtr for the " << field
->getName() << " field. */" << endl
;
86 void ClassHeaderGenerator::AppendFooter()
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
;
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
;
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
;
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
;
107 (*m_file
) << m_tabs
<< m_tabs
<< "/** Initialize the table's fields. */" << endl
;
108 (*m_file
) << m_tabs
<< m_tabs
<< "void Initialize();" << 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
;