00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_PARSER_SUSETAGS_FILEREADERBASEIMPL_H
00013 #define ZYPP_PARSER_SUSETAGS_FILEREADERBASEIMPL_H
00014
00015 #include <iosfwd>
00016
00017 #include "zypp/base/Logger.h"
00018 #include "zypp/base/Function.h"
00019
00020 #include "zypp/parser/susetags/FileReaderBase.h"
00021 #include "zypp/parser/ParseException.h"
00022 #include "zypp/data/ResolvableData.h"
00023 #include "zypp/PathInfo.h"
00024
00025 using std::endl;
00026
00028 namespace zypp
00029 {
00030
00031 namespace parser
00032 {
00033
00034 namespace susetags
00035 {
00036
00037 inline std::string makeSharedIdent( ResolvableTraits::KindType kind_r,
00038 const std::string & name_r,
00039 const Edition & edition_r,
00040 const Arch & arch_r )
00041 {
00042 std::string ret( kind_r.asString() );
00043 ret += ":";
00044 ret += name_r;
00045 ret += "-";
00046 ret += edition_r.asString();
00047 ret += ".";
00048 ret += arch_r.asString();
00049 return ret;
00050 }
00051
00053
00054
00055
00057 class FileReaderBase::BaseImpl : private base::NonCopyable
00058 {
00059 public:
00060 BaseImpl( const FileReaderBase & parent_r )
00061 : _parent( parent_r )
00062 {}
00063 virtual ~BaseImpl()
00064 {}
00065
00066 public:
00071 struct CapImplCache
00072 {
00073 template<class _Res>
00074 capability::CapabilityImpl::Ptr get( const std::string & line_r )
00075 {
00076 return get( line_r, ResTraits<_Res>::kind );
00077 }
00078
00079 capability::CapabilityImpl::Ptr get( const std::string & line_r,
00080 ResolvableTraits::KindType refers_r )
00081 {
00082 capability::CapabilityImpl::Ptr & ret( _cache[refers_r][line_r] );
00083 if ( ! ret )
00084 {
00085 ret = capability::parse( refers_r, line_r );
00086 }
00087 return ret;
00088 }
00089
00090 private:
00091 std::map<ResolvableTraits::KindType, std::map<std::string, capability::CapabilityImpl::Ptr> > _cache;
00092 };
00093
00094 public:
00095
00096 template<class _Res>
00097 void depAddLine( const std::string & line_r,
00098 data::DependencyList & deps_r )
00099 {
00100 depAddLine( line_r, ResTraits<_Res>::kind, deps_r );
00101 }
00102
00103 void depAddLine( const std::string & line_r,
00104 ResolvableTraits::KindType refers_r,
00105 data::DependencyList & deps_r )
00106 {
00107 deps_r.insert( _depcache.get( line_r, refers_r ) );
00108 }
00109
00110
00111 template<class _Res>
00112 void depParse( const MultiTagPtr & tag_r,
00113 data::DependencyList & deps_r )
00114 {
00115 depParse( tag_r, ResTraits<_Res>::kind, deps_r );
00116 }
00117
00118 void depParse( const MultiTagPtr & tag_r,
00119 ResolvableTraits::KindType refers_r,
00120 data::DependencyList & deps_r )
00121 {
00122 std::for_each( tag_r->value.begin(),
00123 tag_r->value.end(),
00124 bind( &BaseImpl::depAddLine, this, _1, refers_r, ref(deps_r) ) );
00125 }
00126
00127 public:
00128 ParseException error( const SingleTagPtr & tag_r,
00129 const std::string & msg_r = std::string() ) const
00130 { return ParseException( _parent.errPrefix( tag_r, msg_r ) ); }
00131
00132 ParseException error( const MultiTagPtr & tag_r,
00133 const std::string & msg_r = std::string() ) const
00134 { return ParseException( _parent.errPrefix( tag_r, msg_r ) ); }
00135
00136 private:
00137 const FileReaderBase & _parent;
00138 CapImplCache _depcache;
00139 };
00141
00143 }
00146 }
00149 }
00151 #endif // ZYPP_PARSER_SUSETAGS_FILEREADERBASEIMPL_H