From 02000d8e4c0eebebfe72b9b988a5065782ccd533 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Wed, 4 Jan 2006 21:06:18 +0000 Subject: [PATCH] Fixed initialization of static vars. --- devel/devel.ma/Makefile.am | 4 +- devel/devel.ma/Parse.cc | 75 ++++++++++++++++++++++----------- devel/genclass.in | 13 ++---- zypp/CountryCode.cc | 99 +++++++++++++++++++++---------------------- zypp/Dependencies.cc | 13 ++---- zypp/LanguageCode.cc | 103 ++++++++++++++++++++++----------------------- zypp/Locale.cc | 16 +++---- zypp/Locale.h | 2 +- 8 files changed, 166 insertions(+), 159 deletions(-) diff --git a/devel/devel.ma/Makefile.am b/devel/devel.ma/Makefile.am index 4cd9389..ebd124f 100644 --- a/devel/devel.ma/Makefile.am +++ b/devel/devel.ma/Makefile.am @@ -12,11 +12,11 @@ AM_LDFLAGS = AM_CXXFLAGS = # gperf: -pg -LDADD = $(top_srcdir)/zypp/lib@PACKAGE@.la -lboost_regex +LDADD = -L$(top_srcdir)/zypp/.libs -lzypp -lboost_regex ## ################################################## -Main_SOURCES = Main.cc Packages.cc +Main_SOURCES = Main.cc Main_debug_SOURCES = $(Main_SOURCES) Main_debug_LDFLAGS = -static diff --git a/devel/devel.ma/Parse.cc b/devel/devel.ma/Parse.cc index 82159b4..69ef321 100644 --- a/devel/devel.ma/Parse.cc +++ b/devel/devel.ma/Parse.cc @@ -45,6 +45,36 @@ namespace zypp echoOn( MIL, first, last, s ); } + //////////////////////////////////////////////////////////////////////////// + // + // SingleTag Grammar + // + //////////////////////////////////////////////////////////////////////////// + + + struct Merror_report_parser + { + Merror_report_parser( const char * msg_r ) + : msg( msg_r ) + {} + + typedef spirit::nil_t result_t; + + template + int operator()( const ScannerT & scan, result_t & /*result*/ ) const + { + SEC << scan.first.get_position() << ' ' << msg << std::endl; + return -1; // Fail. + } + + const char * msg; + }; + + typedef functor_parser Merror_report_p; + + + + ///////////////////////////////////////////////////////////////// } // namespace tagfile /////////////////////////////////////////////////////////////////// @@ -92,6 +122,7 @@ NVRA parseNVRA( const std::string & value ) std::string v; std::string r; std::string a; + parse_info<> info = parse( value.c_str(), lexeme_d[(+~space_p)] [assign_a(n)] @@ -150,22 +181,6 @@ struct PConsume scoped_ptr _nvra; }; -struct X -{ - template - struct result - { - typedef rule_t type; - }; - - template - rule_t operator<<( const Item & stag_r ) const - { - return eps_p;//error_report_p( "neither empty nor comment" ); - } -}; -//const phoenix::function XX = X_impl(); - //////////////////////////////////////////////////////////////////////////// // // Main @@ -199,13 +214,10 @@ int main( int argc, char* argv[] ) MTag mtagData; PConsume consume; - rule_t c = eps_p; - rule_t a = nothing_p; - rule_t x = error_report_p( "abort" ); +#if 1 rule_t file = end_p - | ( stag //[var(consume)=arg1] - >> lazy_p(var(x)) + | ( stag [var(consume)=arg1] | mtag [var(consume)=arg1] | ( *blank_p >> !( ch_p('#') @@ -213,14 +225,29 @@ int main( int argc, char* argv[] ) ) >> (eol_p|end_p) ) - | error_report_p( "neither empty nor comment" ) + | error_report_p( "illegal line" ) ) - >> file; + >> file + ; +#else + rule_t file = + end_p + | (+~space_p) [&echo] + >> ( lazy_p(var(skip)) + | Merror_report_p( "lazy failed" ) + ) + >> file + ; +#endif // Parse shared_ptr duration( new Measure ); parse_info info - = parse( begin, end, file ); + = parse( begin, end, + + file + + ); duration.reset(); // Check for fail... diff --git a/devel/genclass.in b/devel/genclass.in index 2cf8229..0934bd3 100644 --- a/devel/genclass.in +++ b/devel/genclass.in @@ -165,11 +165,10 @@ ${INDENT}{ ${INDENT}public: ${INDENT} /** Offer default Impl. */ ${INDENT} static shared_ptr nullimpl() -${INDENT} { if ( ! _nullimpl ) _nullimpl.reset( new Impl ); return _nullimpl; } - -${INDENT}private: -${INDENT} /** Default Impl. */ -${INDENT} static shared_ptr _nullimpl; +${INDENT} { +${INDENT} static shared_ptr _nullimpl( new Impl ); +${INDENT} return _nullimpl; +${INDENT} } ${INDENT}private: ${INDENT} friend Impl * rwcowClone( const Impl * rhs ); @@ -179,10 +178,6 @@ ${INDENT} { return new Impl( *this ); } ${INDENT}}; ${INDENT}/////////////////////////////////////////////////////////////////// -${INDENT}shared_ptr<${CLASS}::Impl> ${CLASS}::Impl::_nullimpl; - -${INDENT}/////////////////////////////////////////////////////////////////// - ${INDENT}/** \relates ${CLASS}::Impl Stream output */ ${INDENT}inline std::ostream & operator<<( std::ostream & str, const ${CLASS}::Impl & obj ) ${INDENT}{ diff --git a/zypp/CountryCode.cc b/zypp/CountryCode.cc index 1bf310b..8b6542d 100644 --- a/zypp/CountryCode.cc +++ b/zypp/CountryCode.cc @@ -28,51 +28,59 @@ namespace zypp namespace { ///////////////////////////////////////////////////////////////// - typedef std::map CodeMap; - typedef CodeMap::const_iterator Index; - - // CodeMap[code] = untranslated country name - // Translation is done in name(). - CodeMap _iso3166_CodeMap; - CodeMap _others_CodeMap; - - void setDefaultCodeMaps( CodeMap & iso3166, - CodeMap & others ); - - /** Assert code maps are initialized. */ - void assertInitCodemaps() + /** Wrap static codemap data. */ + struct CodeMaps // singleton { - if ( _others_CodeMap.empty() ) - setDefaultCodeMaps( _iso3166_CodeMap, - _others_CodeMap ); - } - - /** Return index of \a code_r, if it's in the code maps. */ - Index lookupCode( const std::string & code_r ) + typedef std::map CodeMap; + typedef CodeMap::const_iterator Index; + + /** Return the CodeMap Index for \a code_r. */ + static Index getIndex( const std::string & code_r ) + { + static CodeMaps _maps; // the singleton instance + return _maps.lookup( code_r ); + } + + private: + /** Ctor initializes the code maps. + * http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html + */ + CodeMaps(); + + /** Make shure the code is in the code maps and return it's index. */ + inline Index lookup( const std::string & code_r ); + + /** Return index of \a code_r, if it's in the code maps. */ + inline Index lookupCode( const std::string & code_r ); + + private: + /** Two letter codes. */ + CodeMap iso3166; + /** All the stuff the application injects. */ + CodeMap others; + }; + + inline CodeMaps::Index CodeMaps::lookupCode( const std::string & code_r ) { - assertInitCodemaps(); switch ( code_r.size() ) { case 2: { - Index it = _iso3166_CodeMap.find( code_r ); - if ( it != _iso3166_CodeMap.end() ) + Index it = iso3166.find( code_r ); + if ( it != iso3166.end() ) return it; } break; } - // not found: check _others_CodeMap - // !!! not found at all returns _others_CodeMap.end() - return _others_CodeMap.find( code_r ); + // not found: check others + // !!! not found at all returns others.end() + return others.find( code_r ); } - /** Assert \a code_r is in the code maps and return it's index. - * That's what CountryCode::Impl calls. - */ - Index getIndex( const std::string & code_r ) + inline CodeMaps::Index CodeMaps::lookup( const std::string & code_r ) { Index it = lookupCode( code_r ); - if ( it != _others_CodeMap.end() ) + if ( it != others.end() ) return it; // not found: Remember a new code @@ -88,12 +96,12 @@ namespace zypp // but maybe we're lucky with the upper case code // and find a country name. it = lookupCode( lcode ); - if ( it != _others_CodeMap.end() ) + if ( it != others.end() ) nval.second = it->second; } MIL << "Remember CountryCode '" << code_r << "': '" << nval.second << "'" << endl; - return _others_CodeMap.insert( nval ).first; + return others.insert( nval ).first; } ///////////////////////////////////////////////////////////////// @@ -111,11 +119,11 @@ namespace zypp struct CountryCode::Impl { Impl() - : _index( getIndex( std::string() ) ) + : _index( CodeMaps::getIndex( std::string() ) ) {} Impl( const std::string & code_r ) - : _index( getIndex( code_r ) ) + : _index( CodeMaps::getIndex( code_r ) ) {} std::string code() const @@ -135,23 +143,18 @@ namespace zypp private: /** index into code map. */ - Index _index; + CodeMaps::Index _index; public: /** Offer default Impl. */ static shared_ptr nullimpl() - { if ( ! _nullimpl ) _nullimpl.reset( new Impl ); return _nullimpl; } - - private: - /** Default Impl. */ - static shared_ptr _nullimpl; + { + static shared_ptr _nullimpl( new Impl ); + return _nullimpl; + } }; /////////////////////////////////////////////////////////////////// - shared_ptr CountryCode::Impl::_nullimpl; - - /////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// // // CLASS NAME : CountryCode @@ -206,11 +209,7 @@ namespace zypp namespace { ///////////////////////////////////////////////////////////////// - /** Initialize the code maps. - * http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html - */ - void setDefaultCodeMaps( CodeMap & iso3166, - CodeMap & others ) + CodeMaps::CodeMaps() { // Defined CountryCode constants others[""] = N_( "noCode" ); diff --git a/zypp/Dependencies.cc b/zypp/Dependencies.cc index 98ffdde..8234cdf 100644 --- a/zypp/Dependencies.cc +++ b/zypp/Dependencies.cc @@ -49,11 +49,10 @@ namespace zypp public: /** Offer default Impl. */ static shared_ptr nullimpl() - { if ( ! _nullimpl ) _nullimpl.reset( new Impl ); return _nullimpl; } - - private: - /** Default Impl: empty sets. */ - static shared_ptr _nullimpl; + { + static shared_ptr _nullimpl( new Impl ); + return _nullimpl; + } private: friend Impl * rwcowClone( const Impl * rhs ); @@ -63,10 +62,6 @@ namespace zypp }; /////////////////////////////////////////////////////////////////// - shared_ptr Dependencies::Impl::_nullimpl; - - /////////////////////////////////////////////////////////////////// - /** \relates DependenciesImpl Stream output */ inline std::ostream & operator<<( std::ostream & str, const Dependencies::Impl & obj ) { diff --git a/zypp/LanguageCode.cc b/zypp/LanguageCode.cc index 4dffb1e..fbdc275 100644 --- a/zypp/LanguageCode.cc +++ b/zypp/LanguageCode.cc @@ -28,62 +28,69 @@ namespace zypp namespace { ///////////////////////////////////////////////////////////////// - typedef std::map CodeMap; - typedef CodeMap::const_iterator Index; + /** Wrap static codemap data. */ + struct CodeMaps // singleton + { + typedef std::map CodeMap; + typedef CodeMap::const_iterator Index; - // CodeMap[code] = untranslated language name - // Translation is done in name(). - CodeMap _iso639_1_CodeMap; - CodeMap _iso639_2_CodeMap; - CodeMap _others_CodeMap; + /** Return the CodeMap Index for \a code_r. */ + static Index getIndex( const std::string & code_r ) + { + static CodeMaps _maps; // the singleton instance + return _maps.lookup( code_r ); + } - void setDefaultCodeMaps( CodeMap & iso639_1, - CodeMap & iso639_2, - CodeMap & others ); + private: + /** Ctor initializes the code maps. + * http://www.loc.gov/standards/iso639-2/ISO-639-2_values_8bits.txt + */ + CodeMaps(); - /** Assert code maps are initialized. */ - void assertInitCodemaps() - { - if ( _others_CodeMap.empty() ) - setDefaultCodeMaps( _iso639_1_CodeMap, - _iso639_2_CodeMap, - _others_CodeMap ); - } + /** Make shure the code is in the code maps and return it's index. */ + inline Index lookup( const std::string & code_r ); - /** Return index of \a code_r, if it's in the code maps. */ - Index lookupCode( const std::string & code_r ) + /** Return index of \a code_r, if it's in the code maps. */ + inline Index lookupCode( const std::string & code_r ); + + private: + /** Two letter codes. */ + CodeMap iso639_1; + /** Three letter codes. */ + CodeMap iso639_2; + /** All the stuff the application injects. */ + CodeMap others; + }; + + inline CodeMaps::Index CodeMaps::lookupCode( const std::string & code_r ) { - assertInitCodemaps(); switch ( code_r.size() ) { case 2: { - Index it = _iso639_1_CodeMap.find( code_r ); - if ( it != _iso639_1_CodeMap.end() ) + Index it = iso639_1.find( code_r ); + if ( it != iso639_1.end() ) return it; } break; case 3: { - Index it = _iso639_2_CodeMap.find( code_r ); - if ( it != _iso639_2_CodeMap.end() ) + Index it = iso639_2.find( code_r ); + if ( it != iso639_2.end() ) return it; } break; } - // not found: check _others_CodeMap - // !!! not found at all returns _others_CodeMap.end() - return _others_CodeMap.find( code_r ); + // not found: check others + // !!! not found at all returns others.end() + return others.find( code_r ); } - /** Assert \a code_r is in the code maps and return it's index. - * That's what LanguageCode::Impl calls. - */ - Index getIndex( const std::string & code_r ) + inline CodeMaps::Index CodeMaps::lookup( const std::string & code_r ) { Index it = lookupCode( code_r ); - if ( it != _others_CodeMap.end() ) + if ( it != others.end() ) return it; // not found: Remember a new code @@ -99,12 +106,12 @@ namespace zypp // but maybe we're lucky with the lower case code // and find a language name. it = lookupCode( lcode ); - if ( it != _others_CodeMap.end() ) + if ( it != others.end() ) nval.second = it->second; } MIL << "Remember LanguageCode '" << code_r << "': '" << nval.second << "'" << endl; - return _others_CodeMap.insert( nval ).first; + return others.insert( nval ).first; } ///////////////////////////////////////////////////////////////// @@ -122,11 +129,11 @@ namespace zypp struct LanguageCode::Impl { Impl() - : _index( getIndex( std::string() ) ) + : _index( CodeMaps::getIndex( std::string() ) ) {} Impl( const std::string & code_r ) - : _index( getIndex( code_r ) ) + : _index( CodeMaps::getIndex( code_r ) ) {} std::string code() const @@ -146,23 +153,18 @@ namespace zypp private: /** index into code map. */ - Index _index; + CodeMaps::Index _index; public: /** Offer default Impl. */ static shared_ptr nullimpl() - { if ( ! _nullimpl ) _nullimpl.reset( new Impl ); return _nullimpl; } - - private: - /** Default Impl. */ - static shared_ptr _nullimpl; + { + static shared_ptr _nullimpl( new Impl ); + return _nullimpl; + } }; /////////////////////////////////////////////////////////////////// - shared_ptr LanguageCode::Impl::_nullimpl; - - /////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// // // CLASS NAME : LanguageCode @@ -218,12 +220,7 @@ namespace zypp namespace { ///////////////////////////////////////////////////////////////// - /** Initialize the code maps. - * http://www.loc.gov/standards/iso639-2/ISO-639-2_values_8bits.txt - */ - void setDefaultCodeMaps( CodeMap & iso639_1, - CodeMap & iso639_2, - CodeMap & others ) + CodeMaps::CodeMaps() { // Defined LanguageCode constants others[""] = N_( "noCode" ); diff --git a/zypp/Locale.cc b/zypp/Locale.cc index 8cb9302..e5d2300 100644 --- a/zypp/Locale.cc +++ b/zypp/Locale.cc @@ -85,18 +85,13 @@ namespace zypp public: /** Offer default Impl. */ static shared_ptr nullimpl() - { if ( ! _nullimpl ) _nullimpl.reset( new Impl ); return _nullimpl; } - - private: - /** Default Impl. */ - static shared_ptr _nullimpl; + { + static shared_ptr _nullimpl( new Impl ); + return _nullimpl; + } }; /////////////////////////////////////////////////////////////////// - shared_ptr Locale::Impl::_nullimpl; - - /////////////////////////////////////////////////////////////////// - /** \relates Locale::Impl Stream output */ inline std::ostream & operator<<( std::ostream & str, const Locale::Impl & obj ) { @@ -109,8 +104,7 @@ namespace zypp // /////////////////////////////////////////////////////////////////// -#warning NO STATIC VARIABLES -// const Locale Locale::noCode; + const Locale Locale::noCode; /////////////////////////////////////////////////////////////////// // diff --git a/zypp/Locale.h b/zypp/Locale.h index db52fb2..b2ac8f4 100644 --- a/zypp/Locale.h +++ b/zypp/Locale.h @@ -55,7 +55,7 @@ namespace zypp /** \name Locale constants. */ //@{ /** No or empty code. */ -// static const Locale noCode; + static const Locale noCode; //@} public: -- 2.7.4