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"
106 ${INDENT}///////////////////////////////////////////////////////////////////
107 ${INDENT}/// \class ${CLASS}
109 ${INDENT}///////////////////////////////////////////////////////////////////
110 ${INDENT}class ${CLASS} : protected base::SafeBool<${CLASS}>
112 ${INDENT} friend std::ostream & operator<<( std::ostream & str, const ${CLASS} & obj );
113 ${INDENT} friend std::ostream & dumpOn( std::ostream & str, const ${CLASS} & obj );
114 ${INDENT} friend bool operator==( const ${CLASS} & lhs, const ${CLASS} & rhs );
117 ${INDENT} /** Default ctor */
118 ${INDENT} ${CLASS}();
120 ${INDENT} /** Dtor */
121 ${INDENT} ~${CLASS}();
124 ${INDENT} /** Validate object in a boolean context. */
125 ${INDENT} using base::SafeBool<${CLASS}>::operator bool_type;
128 ${INDENT} friend base::SafeBool<${CLASS}>::operator bool_type() const;
129 ${INDENT} /** Validate object in a boolean context. */
130 ${INDENT} bool boolTest() const
132 ${INDENT} /* !!! Perform Boolean logic here AND check implememtation of operator==!!!
133 ${INDENT} * NOTE: SafeBool requires operator== otherwise equality is reduced to
134 ${INDENT} * ( bool(${CLASS}) == bool(${CLASS}) ).
138 ${INDENT} class Impl; ///< Implementation class.
140 ${INDENT} RWCOW_pointer<Impl> _pimpl; ///< Pointer to implementation.
143 ${INDENT}/** \relates ${CLASS} Stream output */
144 ${INDENT}std::ostream & operator<<( std::ostream & str, const ${CLASS} & obj );
146 ${INDENT}/** \relates ${CLASS} Verbose stream output */
147 ${INDENT}std::ostream & dumOn( std::ostream & str, const ${CLASS} & obj );
149 ${INDENT}/** \relates ${CLASS} */
150 ${INDENT}bool operator==( const ${CLASS} & lhs, const ${CLASS} & rhs );
152 ${INDENT}/** \relates ${CLASS} */
153 ${INDENT}inline bool operator!=( const ${CLASS} & lhs, const ${CLASS} & rhs )
154 ${INDENT}{ return !( lhs == rhs ); }
157 #endif // $INCLUDE_DEF
161 ######################################################################
163 ######################################################################
167 //#include "zypp/base/LogTools.h"
168 #include "zypp/base/NonCopyable.h"
170 #include "${INCLUDE_H}"
176 ${INDENT}///////////////////////////////////////////////////////////////////
177 ${INDENT}/// \class ${CLASS}::Impl
178 ${INDENT}/// \brief ${CLASS} implementation.
179 ${INDENT}///////////////////////////////////////////////////////////////////
180 ${INDENT}class ${CLASS}::Impl : private base::NonCopyable
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 ######################################################################