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"
105 ${INDENT}///////////////////////////////////////////////////////////////////
106 ${INDENT}/// \class ${CLASS}
108 ${INDENT}///////////////////////////////////////////////////////////////////
109 ${INDENT}class ${CLASS}
111 ${INDENT} friend std::ostream & operator<<( std::ostream & str, const ${CLASS} & obj );
112 ${INDENT} friend std::ostream & dumpOn( std::ostream & str, const ${CLASS} & obj );
113 ${INDENT} friend bool operator==( const ${CLASS} & lhs, const ${CLASS} & rhs );
116 ${INDENT} /** Default ctor */
117 ${INDENT} ${CLASS}();
119 ${INDENT} /** Dtor */
120 ${INDENT} ~${CLASS}();
123 ${INDENT} /** Validate object in a boolean context. */
124 ${INDENT} explicit operator bool() const
126 ${INDENT} /* !!! Perform Boolean logic here AND check implememtation of operator==!!!
127 ${INDENT} * NOTE: SafeBool requires operator== otherwise equality is reduced to
128 ${INDENT} * ( bool(${CLASS}) == bool(${CLASS}) ).
132 ${INDENT} class Impl; ///< Implementation class.
134 ${INDENT} RWCOW_pointer<Impl> _pimpl; ///< Pointer to implementation.
137 ${INDENT}/** \relates ${CLASS} Stream output */
138 ${INDENT}std::ostream & operator<<( std::ostream & str, const ${CLASS} & obj );
140 ${INDENT}/** \relates ${CLASS} Verbose stream output */
141 ${INDENT}std::ostream & dumOn( std::ostream & str, const ${CLASS} & obj );
143 ${INDENT}/** \relates ${CLASS} */
144 ${INDENT}bool operator==( const ${CLASS} & lhs, const ${CLASS} & rhs );
146 ${INDENT}/** \relates ${CLASS} */
147 ${INDENT}inline bool operator!=( const ${CLASS} & lhs, const ${CLASS} & rhs )
148 ${INDENT}{ return !( lhs == rhs ); }
151 #endif // $INCLUDE_DEF
155 ######################################################################
157 ######################################################################
161 //#include "zypp/base/LogTools.h"
162 #include "zypp/base/NonCopyable.h"
164 #include "${INCLUDE_H}"
170 ${INDENT}///////////////////////////////////////////////////////////////////
171 ${INDENT}/// \class ${CLASS}::Impl
172 ${INDENT}/// \brief ${CLASS} implementation.
173 ${INDENT}///////////////////////////////////////////////////////////////////
174 ${INDENT}class ${CLASS}::Impl : private base::NonCopyable
176 ${INDENT} friend std::ostream & operator<<( std::ostream & str, const Impl & obj );
177 ${INDENT} friend std::ostream & dumpOn( std::ostream & str, const Impl & obj );
182 ${INDENT} /** Offer default Impl. */
183 ${INDENT} static shared_ptr<Impl> nullimpl()
185 ${INDENT} static shared_ptr<Impl> _nullimpl( new Impl );
186 ${INDENT} return _nullimpl;
189 ${INDENT} friend Impl * rwcowClone<Impl>( const Impl * rhs );
190 ${INDENT} /** clone for RWCOW_pointer */
191 ${INDENT} Impl * clone() const
192 ${INDENT} { return new Impl( *this ); }
195 ${INDENT}/** \relates ${CLASS}::Impl Stream output */
196 ${INDENT}inline std::ostream & operator<<( std::ostream & str, const ${CLASS}::Impl & obj )
197 ${INDENT}{ return str << "${CLASS}::Impl"; }
199 ${INDENT}/** \relates ${CLASS}::Impl Verbose stream output */
200 ${INDENT}inline std::ostream & dumpOn( std::ostream & str, const ${CLASS}::Impl & obj )
201 ${INDENT}{ return str << obj; }
203 ${INDENT}///////////////////////////////////////////////////////////////////
205 ${INDENT}// CLASS NAME : ${CLASS}
207 ${INDENT}///////////////////////////////////////////////////////////////////
209 ${INDENT}${CLASS}::${CLASS}()
210 ${INDENT} : _pimpl( Impl::nullimpl() )
213 ${INDENT}${CLASS}::~${CLASS}()
216 ${INDENT}std::ostream & operator<<( std::ostream & str, const ${CLASS} & obj )
217 ${INDENT}{ return str << *obj._pimpl; }
219 ${INDENT}std::ostream & dumpOn( std::ostream & str, const ${CLASS} & obj )
220 ${INDENT}{ return dumpOn( str, *obj._pimpl ); }
222 ${INDENT}bool operator==( const ${CLASS} & lhs, const ${CLASS} & rhs )
223 ${INDENT}{ return lhs._pimpl == rhs._pimpl || lhs._pimpl && rhs._pimpl && *lhs._pimpl == *rhs._pimpl; }
229 ######################################################################
230 ######################################################################
231 ######################################################################