6 Usage: genclass [path/]stem
11 test -z "$1" && usage "Missing name!"
13 TOPSRCDIR=${XTOPSRCDIR:-$(cd @CMAKE_SOURCE_DIR@ && pwd)}
14 test -z "$TOPSRCDIR" && {
15 echo "Dir does not exist '$TOPSRCDIR'" >&2
21 STEMDIR=$( cd $OUTDIR && pwd )
22 test -z "$STEMDIR" && {
23 echo "Dir does not exist '$(dirname $1)'" >&2
26 STEMDIR=${STEMDIR#$TOPSRCDIR/}
29 CLASS_H=$STEMDIR/$STEM.h
30 CLASS_CC=$STEMDIR/$STEM.cc
32 OUT_CLASS_H=$OUTDIR/$STEM.h
33 OUT_CLASS_CC=$OUTDIR/$STEM.cc
34 test -e $OUT_CLASS_H -o -e $OUT_CLASS_CC && {
35 test -e $OUT_CLASS_H && echo "File exists '$OUT_CLASS_H' using '$OUT_CLASS_H.new'" >&2
36 test -e $OUT_CLASS_CC && echo "File exists '$OUT_CLASS_CC' using '$OUT_CLASS_CC.new'" >&2
37 OUT_CLASS_H="$OUT_CLASS_H.new"
38 OUT_CLASS_CC="$OUT_CLASS_CC.new"
42 INCLUDE_DEF=$(echo $INCLUDE_H | sed 's/[./]/_/g' | awk '{print toupper($0)}')
43 NSLIST=$(echo $(dirname $INCLUDE_H) | awk '{l=tolower($0);gsub("/"," ",l);print l}')
51 ######################################################################
53 ######################################################################
56 /*---------------------------------------------------------------------\\
58 | |__ / \ / / . \ . \ |
61 | /_____||_| |_| |_| |
63 \---------------------------------------------------------------------*/
69 ######################################################################
71 ######################################################################
74 echo "${I}///////////////////////////////////////////////////////////////////"
75 echo "${I}namespace $N"
81 ######################################################################
83 ######################################################################
87 echo "${I}} // namespace $N"
88 echo "${I}///////////////////////////////////////////////////////////////////"
92 ######################################################################
94 ######################################################################
102 #include "zypp/base/PtrTypes.h"
103 #include "zypp/base/SafeBool.h"
104 #include "zypp/base/NonCopyable.h"
107 ${INDENT}///////////////////////////////////////////////////////////////////
108 ${INDENT}/// \class ${CLASS}
110 ${INDENT}///////////////////////////////////////////////////////////////////
111 ${INDENT}class ${CLASS} : protected base::SafeBool<${CLASS}>, private base::NonCopyable
113 ${INDENT} friend std::ostream & operator<<( std::ostream & str, const ${CLASS} & obj );
114 ${INDENT} friend std::ostream & dumpOn( std::ostream & str, const ${CLASS} & obj );
115 ${INDENT} friend bool operator==( const ${CLASS} & lhs, const ${CLASS} & rhs );
118 ${INDENT} /** Default ctor */
119 ${INDENT} ${CLASS}();
121 ${INDENT} /** Dtor */
122 ${INDENT} ~${CLASS}();
125 ${INDENT} /** Validate object in a boolean context. */
126 ${INDENT} using base::SafeBool<${CLASS}>::operator bool_type;
129 ${INDENT} friend base::SafeBool<${CLASS}>::operator bool_type() const;
130 ${INDENT} /** Validate object in a boolean context. */
131 ${INDENT} bool boolTest() const
133 ${INDENT} /* !!! Perform Boolean logic here AND check implememtation of operator==!!!
134 ${INDENT} * NOTE: SafeBool requires operator== otherwise equality is reduced to
135 ${INDENT} * ( bool(${CLASS}) == bool(${CLASS}) ).
139 ${INDENT} class Impl; ///< Implementation class.
141 ${INDENT} RWCOW_pointer<Impl> _pimpl; ///< Pointer to implementation.
144 ${INDENT}/** \relates ${CLASS} Stream output */
145 ${INDENT}std::ostream & operator<<( std::ostream & str, const ${CLASS} & obj );
147 ${INDENT}/** \relates ${CLASS} Verbose stream output */
148 ${INDENT}std::ostream & dumOn( std::ostream & str, const ${CLASS} & obj );
150 ${INDENT}/** \relates ${CLASS} */
151 ${INDENT}bool operator==( const ${CLASS} & lhs, const ${CLASS} & rhs );
153 ${INDENT}/** \relates ${CLASS} */
154 ${INDENT}inline bool operator!=( const ${CLASS} & lhs, const ${CLASS} & rhs )
155 ${INDENT}{ return !( lhs == rhs ); }
158 #endif // $INCLUDE_DEF
162 ######################################################################
164 ######################################################################
168 //#include "zypp/base/LogTools.h"
170 #include "${INCLUDE_H}"
176 ${INDENT}///////////////////////////////////////////////////////////////////
177 ${INDENT}/// \class ${CLASS}::Impl
178 ${INDENT}/// \brief ${CLASS} implementation.
179 ${INDENT}///////////////////////////////////////////////////////////////////
180 ${INDENT}struct ${CLASS}::Impl
182 ${INDENT} friend std::ostream & operator<<( std::ostream & str, const Impl & obj );
183 ${INDENT} friend std::ostream & dumpOn( std::ostream & str, const Impl & obj );
188 ${INDENT} /** Offer default Impl. */
189 ${INDENT} static shared_ptr<Impl> nullimpl()
191 ${INDENT} static shared_ptr<Impl> _nullimpl( new Impl );
192 ${INDENT} return _nullimpl;
195 ${INDENT} friend Impl * rwcowClone<Impl>( const Impl * rhs );
196 ${INDENT} /** clone for RWCOW_pointer */
197 ${INDENT} Impl * clone() const
198 ${INDENT} { return new Impl( *this ); }
201 ${INDENT}/** \relates ${CLASS}::Impl Stream output */
202 ${INDENT}inline std::ostream & operator<<( std::ostream & str, const ${CLASS}::Impl & obj )
203 ${INDENT}{ return str << "${CLASS}::Impl"; }
205 ${INDENT}/** \relates ${CLASS}::Impl Verbose stream output */
206 ${INDENT}inline std::ostream & dumpOn( std::ostream & str, const ${CLASS}::Impl & obj )
207 ${INDENT}{ return str << obj; }
209 ${INDENT}///////////////////////////////////////////////////////////////////
211 ${INDENT}// CLASS NAME : ${CLASS}
213 ${INDENT}///////////////////////////////////////////////////////////////////
215 ${INDENT}${CLASS}::${CLASS}()
216 ${INDENT} : _pimpl( Impl::nullimpl() )
219 ${INDENT}${CLASS}::~${CLASS}()
222 ${INDENT}std::ostream & operator<<( std::ostream & str, const ${CLASS} & obj )
223 ${INDENT}{ return str << *obj._pimpl; }
225 ${INDENT}std::ostream & dumpOn( std::ostream & str, const ${CLASS} & obj )
226 ${INDENT}{ return dumpOn( str, *obj._pimpl ); }
228 ${INDENT}bool operator==( const ${CLASS} & lhs, const ${CLASS} & rhs )
229 ${INDENT}{ return lhs._pimpl == rhs._pimpl || lhs._pimpl && rhs._pimpl && *lhs._pimpl == *rhs._pimpl; }
235 ######################################################################
236 ######################################################################
237 ######################################################################