HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
-SORT_MEMBER_DOCS = YES
+SORT_MEMBER_DOCS = NO
SORT_BRIEF_DOCS = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
#include <iostream>
+#include <fstream>
+#include <iterator>
+#include <algorithm>
+#include <set>
+#include <map>
+#include <list>
+#include <vector>
+#include <ext/hash_set>
+#include <ext/hash_map>
+#include <ext/rope>
+
+#include <zypp/base/Logger.h>
+#include <zypp/base/String.h>
using namespace std;
+using __gnu_cxx::hash_set;
+
+/******************************************************************
+**
+*/
+inline void memusage()
+{
+ system( zypp::base::string::form( "ps v %d", getpid() ).c_str() );
+}
+
+/******************************************************************
+**
+*/
+struct StringHashFnc
+{
+ size_t operator()( const string & str ) const
+ {
+ unsigned long __h = 0;
+ for ( const char* __s = str.c_str(); *__s; ++__s)
+ __h = 5*__h + *__s;
+
+ return size_t(__h);
+ //return str.size();
+ }
+};
/******************************************************************
**
+*/
+template<typename Cont>
+ struct lookupKey
+ {
+ const Cont & _cont;
+ lookupKey( const Cont & cont )
+ : _cont( cont )
+ {}
+ void operator()( const string & key ) const
+ {
+ typename Cont::const_iterator it = _cont.find( key );
+ }
+ };
+
+template<typename Cont>
+ struct lookupNoKey
+ {
+ const Cont & _cont;
+ lookupNoKey( const Cont & cont )
+ : _cont( cont )
+ {}
+ void operator()( const string & key )
+ {
+ typename Cont::const_iterator it = _cont.find( key+'x' );
+ }
+ };
+
+template<typename Cont>
+ void lookup( const Cont & unames )
+ {
+ for ( unsigned i = 0; i < 1000; ++i ) {
+ for_each( unames.begin(), unames.end(), lookupKey<Cont>( unames ) );
+ for_each( unames.begin(), unames.end(), lookupNoKey<Cont>( unames ) );
+ }
+ }
+
+template<typename Cont>
+ void lookupTest( const vector<string> & names )
+ {
+ Cont unames( names.begin(), names.end() );
+ MIL << "Unique names: " << unames.size() << endl;
+ lookup( unames );
+ }
+
+/******************************************************************
+**
+**
** FUNCTION NAME : main
** FUNCTION TYPE : int
+**
+** DESCRIPTION :
*/
int main( int argc, char * argv[] )
{
+ INT << "===[START]==========================================" << endl;
+
+ ifstream f( "./NameList" );
+ vector<string> names( (istream_iterator<string>(f)), istream_iterator<string>() );
+ MIL << "Total names: " << names.size() << endl;
+ memusage();
+
+ INT << ">===[lookupTest<set<string> >]" << endl;
+ lookupTest<set<string> >( names );
+ memusage();
+
+ INT << ">===[lookupTest<hash_set<string> >]" << endl;
+ lookupTest<hash_set<string,StringHashFnc> >( names );
+ memusage();
+
+ INT << "===[END]============================================" << endl;
return 0;
}
#include <iostream>
#include "zypp/base/Logger.h"
+#include "zypp/base/String.h"
using namespace std;
namespace logger
{ /////////////////////////////////////////////////////////////////
- std::ostream & getStream( LogLevel level_r )
+ std::ostream & getStream( const char * group_r,
+ LogLevel level_r,
+ const char * file_r,
+ const char * func_r,
+ const int line_r )
{
- return level_r == E_DBG ? std::cout : std::cerr;
+ return (level_r < 0 ? std::cout : std::cerr)
+ << string::form( "<%d> [%s] %s(%s):%d ",
+ level_r, group_r,
+ file_r, func_r, line_r );
}
/////////////////////////////////////////////////////////////////
#include <iosfwd>
+/** \defgroup ZYPP_BASE_LOGGER_MACROS
+ * Convenience macros for logging.
+ *
+ * The macros finaly call @ref getStream, providing appropriate arguments,
+ * to return the log stream.
+ *
+ * @code
+ * _DBG("foo") << ....
+ * @endcode
+ * Logs a debug message for group @a "foo".
+ *
+ * @code
+ * #undef ZYPP_BASE_LOGGER_LOGGROUP
+ * #define ZYPP_BASE_LOGGER_LOGGROUP "foo"
+ *
+ * DBG << ....
+ * @endcode
+ * Defines group @a "foo" as default for log messages and logs a
+ * debug message.
+ */
+/*@{*/
+
+#ifndef ZYPP_BASE_LOGGER_LOGGROUP
+/** Default log group if undefined. */
+#define ZYPP_BASE_LOGGER_LOGGROUP "DEFINE_LOGGROUP"
+#endif
+
+#define XXX _XXX( ZYPP_BASE_LOGGER_LOGGROUP )
+#define DBG _DBG( ZYPP_BASE_LOGGER_LOGGROUP )
+#define MIL _MIL( ZYPP_BASE_LOGGER_LOGGROUP )
+#define WAR _WAR( ZYPP_BASE_LOGGER_LOGGROUP )
+#define ERR _ERR( ZYPP_BASE_LOGGER_LOGGROUP )
+#define SEC _SEC( ZYPP_BASE_LOGGER_LOGGROUP )
+#define INT _INT( ZYPP_BASE_LOGGER_LOGGROUP )
+#define USR _USR( ZYPP_BASE_LOGGER_LOGGROUP )
+
+#define _XXX(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_XXX )
+#define _DBG(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_DBG )
+#define _MIL(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_MIL )
+#define _WAR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_WAR )
+#define _ERR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_ERR )
+#define _SEC(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_SEC )
+#define _INT(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_INT )
+#define _USR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_USR )
+
+/** Actual call to @ref getStream. */
+#define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
+ zypp::base::logger::getStream( GROUP, LEVEL, __FILE__, __FUNCTION__, __LINE__ )
+
+/*@}*/
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
namespace logger
{ /////////////////////////////////////////////////////////////////
+ /** Definition of log levels.
+ *
+ * @see getStream
+ */
enum LogLevel {
- E_USR = 0,
- E_DBG, E_MIL, E_WAR, E_ERR, E_SEC, E_INT
+ E_XXX = -1, /**< Excessive logging. */
+ E_DBG = 0, /**< Debug or verbose. */
+ E_MIL, /**< Milestone. */
+ E_WAR, /**< Warning. */
+ E_ERR, /**< Error. */
+ E_SEC, /**< Secutrity related. */
+ E_INT, /**< Internal error. */
+ E_USR /**< User log. */
};
- extern std::ostream & getStream( LogLevel level_r );
+ /** Return a log stream to write on.
+ *
+ * The returned log stream is determined by @a group_r and
+ * @a level_r. The remaining arguments @a file_r, @a func_r
+ * and @a line_r are expected to denote the location in the
+ * source code that issued the message.
+ *
+ * @note You won't call @ref getStream directly, but use the
+ * @ref ZYPP_BASE_LOGGER_MACROS.
+ */
+ extern std::ostream & getStream( const char * group_r,
+ LogLevel level_r,
+ const char * file_r,
+ const char * func_r,
+ const int line_r );
/////////////////////////////////////////////////////////////////
} // namespace logger
///////////////////////////////////////////////////////////////////
-#define USR zypp::base::logger::getStream( zypp::base::logger::E_USR )
-#define DBG zypp::base::logger::getStream( zypp::base::logger::E_DBG )
-#define MIL zypp::base::logger::getStream( zypp::base::logger::E_MIL )
-#define WAR zypp::base::logger::getStream( zypp::base::logger::E_WAR )
-#define ERR zypp::base::logger::getStream( zypp::base::logger::E_ERR )
-#define SEC zypp::base::logger::getStream( zypp::base::logger::E_SEC )
-#define INT zypp::base::logger::getStream( zypp::base::logger::E_INT )
-
/////////////////////////////////////////////////////////////////
} // namespace base
///////////////////////////////////////////////////////////////////
## ##################################################
include_HEADERS = \
+ String.h \
Logger.h
## ##################################################
lib@PACKAGE@_base_la_SOURCES = \
+ String.cc \
Logger.cc
--- /dev/null
+#include <cstdio>
+#include <cstdarg>
+
+#include <iostream>
+
+#include "zypp/base/String.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace base
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ namespace string
+ { /////////////////////////////////////////////////////////////////
+
+ std::string form( const char * format, ... )
+ {
+ struct SafeBuf
+ {
+ char * _buf;
+ SafeBuf() : _buf( 0 ) {}
+ ~SafeBuf() { if ( _buf ) free( _buf ); }
+ std::string asString() const
+ { return _buf ? std::string(_buf) : std::string(); }
+ };
+ SafeBuf safe;
+
+ va_list ap;
+ va_start( ap, format );
+ vasprintf( &safe._buf, format, ap );
+ va_end( ap );
+
+ return safe.asString();
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace string
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace base
+ ///////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////
+} // namespace zypp
+//////////////////////////////////////////////////////////////////
--- /dev/null
+#ifndef ZYPP_BASE_STRING_H
+#define ZYPP_BASE_STRING_H
+
+#include <iosfwd>
+#include <string>
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace base
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ namespace string
+ { /////////////////////////////////////////////////////////////////
+
+ /** Printf style construction of std::string. */
+ std::string form( const char * format, ... )
+ __attribute__ ((format (printf, 1, 2)));
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace string
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace base
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_BASE_STRING_H