Author: mlandres Date: Tue Apr 10 23:22:07 2007 New Revision: 5328 URL: http://svn.opensuse.org/viewcvs/zypp?rev=5328&view=rev Log: Added class PackageKeyword Added: trunk/libzypp/zypp/PackageKeyword.h Modified: trunk/libzypp/zypp/CMakeLists.txt trunk/libzypp/zypp/base/UniqueString.h Modified: trunk/libzypp/zypp/CMakeLists.txt URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=5328&r1=5327&r2=5328&view=diff ============================================================================== --- trunk/libzypp/zypp/CMakeLists.txt (original) +++ trunk/libzypp/zypp/CMakeLists.txt Tue Apr 10 23:22:07 2007 @@ -128,6 +128,7 @@ NeedAType.h OnMediaLocation.h Package.h + PackageKeyword.h Patch.h PathInfo.h Pathname.h Added: trunk/libzypp/zypp/PackageKeyword.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PackageKeyword.h?rev=5328&view=auto ============================================================================== --- trunk/libzypp/zypp/PackageKeyword.h (added) +++ trunk/libzypp/zypp/PackageKeyword.h Tue Apr 10 23:22:07 2007 @@ -0,0 +1,40 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/PackageKeyword.h + * +*/ +#ifndef ZYPP_PACKAGEKEYWORD_H +#define ZYPP_PACKAGEKEYWORD_H + +#include "zypp/base/UniqueString.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : PackageKeyword + // + /** Package keywords. */ + struct PackageKeyword : public base::UniqueString<PackageKeyword> + { + KeyWord() + {} + + KeyWord( const std::string & name_r ) + :base::UniqueString<KeyWord>( name_r ) + {} + }; + /////////////////////////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_PACKAGEKEYWORD_H Modified: trunk/libzypp/zypp/base/UniqueString.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/UniqueString.h?rev=5328&r1=5327&r2=5328&view=diff ============================================================================== --- trunk/libzypp/zypp/base/UniqueString.h (original) +++ trunk/libzypp/zypp/base/UniqueString.h Tue Apr 10 23:22:07 2007 @@ -30,18 +30,60 @@ // /** Immutable strings with unique representation in memory. * - * Uses CRTP to provide the unifying hash and define operators. - * All operatoins are string based. + * Each UniqueString provides a <tt>const std::string</tt>. + * This string is stored in a unifying hash, that way equal + * UniqueStrings share their string representation in memory. + * + * At the same time the unifying hash contains all the string + * values created so far. Static methods are provided to query + * the hash contents. + * + * Uses CRTP to provide the unifying hash. + * + * \code + * struct KeyWord : public base::UniqueString<KeyWord> + * { + * KeyWord() + * {} + * KeyWord( const std::string & name_r ) + * :base::UniqueString<KeyWord>( name_r ) + * {} + * }; + * + * int main( int argc, char * argv[] ) + * { + * KeyWord(); + * KeyWord( "a" ); + * KeyWord( "b" ); + * KeyWord( "c" ); + * KeyWord( "a" ); + * KeyWord( "c" ); + * + * DBG << "Known KeyWords: " << KeyWord::allSize() << endl; + * for ( KeyWord::const_iterator it = KeyWord::allBegin(); it != KeyWord::allEnd(); ++it ) + * { + * DBG << *it << endl; + * } + * + * return 0; + * } + * \endcode + * \code + * Known KeyWords: 3 + * a + * b + * c + * \endcode */ template<class _Derived> class UniqueString { protected: - /** Default ctor */ + /** Default ctor provides an empty string. */ UniqueString() {} - /** Ctor taking a name to store unified. */ + /** Ctor taking a name to store. */ UniqueString( const std::string & name_r ) { if ( !name_r.empty() ) @@ -113,90 +155,90 @@ }; /////////////////////////////////////////////////////////////////// - // operator == + /** \relates UniqueString operator == */ template<class _Derived> inline bool operator==( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs.str() == rhs.str() ); } - + /** \relates UniqueString operator == */ template<class _Derived> inline bool operator==( const UniqueString<_Derived> & lhs, const std::string & rhs ) { return ( lhs.str() == rhs ); } - + /** \relates UniqueString operator == */ template<class _Derived> inline bool operator==( const std::string & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs == rhs.str() ); } - // operator != + /** \relates UniqueString operator != */ template<class _Derived> inline bool operator!=( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs.str() != rhs.str() ); } - + /** \relates UniqueString operator != */ template<class _Derived> inline bool operator!=( const UniqueString<_Derived> & lhs, const std::string & rhs ) { return ( lhs.str() != rhs ); } - + /** \relates UniqueString operator != */ template<class _Derived> inline bool operator!=( const std::string & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs != rhs.str() ); } - // operator < + /** \relates UniqueString operator < */ template<class _Derived> inline bool operator<( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs.str() < rhs.str() ); } - + /** \relates UniqueString operator < */ template<class _Derived> inline bool operator<( const UniqueString<_Derived> & lhs, const std::string & rhs ) { return ( lhs.str() < rhs ); } - + /** \relates UniqueString operator < */ template<class _Derived> inline bool operator<( const std::string & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs < rhs.str() ); } - // operator > + /** \relates UniqueString operator > */ template<class _Derived> inline bool operator>( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs.str() > rhs.str() ); } - + /** \relates UniqueString operator > */ template<class _Derived> inline bool operator>( const UniqueString<_Derived> & lhs, const std::string & rhs ) { return ( lhs.str() > rhs ); } - + /** \relates UniqueString operator > */ template<class _Derived> inline bool operator>( const std::string & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs > rhs.str() ); } - // operator <= + /** \relates UniqueString operator <= */ template<class _Derived> inline bool operator<=( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs.str() <= rhs.str() ); } - + /** \relates UniqueString operator <= */ template<class _Derived> inline bool operator<=( const UniqueString<_Derived> & lhs, const std::string & rhs ) { return ( lhs.str() <= rhs ); } - + /** \relates UniqueString operator <= */ template<class _Derived> inline bool operator<=( const std::string & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs <= rhs.str() ); } - // operator != + /** \relates UniqueString operator >= */ template<class _Derived> inline bool operator>=( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs.str() >= rhs.str() ); } - + /** \relates UniqueString operator >= */ template<class _Derived> inline bool operator>=( const UniqueString<_Derived> & lhs, const std::string & rhs ) { return ( lhs.str() >= rhs ); } - + /** \relates UniqueString operator >= */ template<class _Derived> inline bool operator>=( const std::string & lhs, const UniqueString<_Derived> & rhs ) { return ( lhs >= rhs.str() ); } - /** \relates UniqueString Stream output */ + /** \relates UniqueString Stream output */ template<class _Derived> inline std::ostream & operator<<( std::ostream & str, const UniqueString<_Derived> & obj ) { return str << obj.str(); } -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org