Container.h

Go to the documentation of this file.
00001 #ifndef CONTAINER_H
00002 #define CONTAINER_H
00003 
00004 #include <list>
00005 
00006 #include "y2storage/Volume.h"
00007 #include "y2storage/StorageTypes.h"
00008 #include "y2storage/StorageTmpl.h"
00009 
00010 namespace storage
00011 {
00012 
00013 class Container
00014     {
00015     friend class Storage;
00016     protected:
00017         template<typename L1, typename L2> friend class ListListIterator;
00018 
00019         typedef std::list<Volume*> VCont;
00020         typedef VCont::iterator VIter;
00021         typedef VCont::const_iterator CVIter;
00022         typedef VCont::reverse_iterator RVIter;
00023         typedef VCont::const_reverse_iterator CRVIter;
00024 
00025 
00026     public:
00027         bool operator== ( const Container& rhs ) const
00028             { return( typ == rhs.typ && nm == rhs.nm && del == rhs.del ); }
00029         bool operator!= ( const Container& rhs ) const
00030             { return( !(*this==rhs) ); }
00031         bool operator< ( const Container& rhs ) const
00032             {
00033             if( typ != rhs.typ )
00034                 return( typ<rhs.typ );
00035             else if( nm != rhs.nm )
00036                 return( nm<rhs.nm );
00037             else
00038                 return( !del );
00039             }
00040         bool operator<= ( const Container& rhs ) const
00041             { return( *this<rhs || *this==rhs ); }
00042         bool operator>= ( const Container& rhs ) const
00043             { return( !(*this<rhs) ); }
00044         bool operator> ( const Container& rhs ) const
00045             { return( !(*this<=rhs) ); }
00046         virtual bool equalContent( const Container& rhs ) const;
00047         virtual string getDiffString( const Container& c ) const;
00048         virtual void logDifference( const Container& c ) const;
00049 
00050         virtual void getCommitActions( std::list<storage::commitAction*>& l ) const;
00051         virtual int getToCommit( storage::CommitStage stage, 
00052                                  std::list<Container*>& col,
00053                                  std::list<Volume*>& vol );
00054 
00055         virtual int commitChanges( storage::CommitStage stage );
00056         virtual int commitChanges( storage::CommitStage stage, Volume* vol );
00057         virtual void changeDeviceName( const string& old, const string& nw )
00058             {};
00059         unsigned numVolumes() const;
00060         bool isEmpty() const;
00061         void getInfo( storage::ContainerInfo& info ) const;
00062         bool findVolume( const string& device, Volume*& vol );
00063 
00064 // iterators over volumes of a container
00065     protected:
00066         // protected typedefs for iterators over volumes
00067         template< class Pred >
00068             struct ConstVolumePI { typedef ContainerIter<Pred, CVIter> type; };
00069         template< class Pred >
00070             struct VolumePI { typedef ContainerIter<Pred, VIter> type; };
00071         template< class Pred >
00072             struct VolumeI { typedef ContainerDerIter<Pred, typename VolumePI<Pred>::type, Volume> type; };
00073         typedef CheckFnc<const Volume> CheckFncVol;
00074         typedef CheckerIterator< CheckFncVol, ConstVolumePI<CheckFncVol>::type,
00075                                  CVIter, Volume> ConstVolPIterator;
00076         typedef CheckerIterator< CheckFncVol, VolumePI<CheckFncVol>::type,
00077                                  VIter, Volume> VolPIterator;
00078         typedef DerefIterator<VolPIterator,Volume> VolIterator;
00079         typedef IterPair<VolIterator> VolPair;
00080 
00081     public:
00082         // public typedefs for iterators over volumes
00083         template< class Pred >
00084             struct ConstVolumeI { typedef ContainerDerIter<Pred, typename ConstVolumePI<Pred>::type, const Volume> type; };
00085         template< class Pred >
00086             struct VolCondIPair { typedef MakeCondIterPair<Pred, typename ConstVolumeI<Pred>::type> type;};
00087         typedef DerefIterator<ConstVolPIterator,const Volume> ConstVolIterator;
00088         typedef IterPair<ConstVolIterator> ConstVolPair;
00089 
00090         // public member functions for iterators over volumes
00091         ConstVolPair volPair( bool (* CheckFnc)( const Volume& )=NULL ) const
00092             {
00093             return( ConstVolPair( volBegin( CheckFnc ), volEnd( CheckFnc ) ));
00094             }
00095         ConstVolIterator volBegin( bool (* CheckFnc)( const Volume& )=NULL ) const
00096             {
00097             return( ConstVolIterator( ConstVolPIterator(vols.begin(), vols.end(), CheckFnc )) );
00098             }
00099         ConstVolIterator volEnd( bool (* CheckFnc)( const Volume& )=NULL ) const
00100             {
00101             return( ConstVolIterator( ConstVolPIterator(vols.begin(), vols.end(), CheckFnc, true )) );
00102             }
00103 
00104         template< class Pred > typename VolCondIPair<Pred>::type volCondPair( const Pred& p ) const
00105             {
00106             return( VolCondIPair<Pred>::type( volCondBegin( p ), volCondEnd( p ) ) );
00107             }
00108         template< class Pred > typename ConstVolumeI<Pred>::type volCondBegin( const Pred& p ) const
00109             {
00110             return( ConstVolumeI<Pred>::type( vols.begin(), vols.end(), p ) );
00111             }
00112         template< class Pred > typename ConstVolumeI<Pred>::type volCondEnd( const Pred& p ) const
00113             {
00114             return( ConstVolumeI<Pred>::type( vols.begin(), vols.end(), p, true ) );
00115             }
00116 
00117     protected:
00118         // protected member functions for iterators over volumes
00119         VolPair volPair( bool (* CheckFnc)( const Volume& )=NULL )
00120             {
00121             return( VolPair( vBegin( CheckFnc ), vEnd( CheckFnc ) ));
00122             }
00123         VolIterator vBegin( bool (* CheckFnc)( const Volume& )=NULL )
00124             {
00125             return( VolIterator( VolPIterator(vols.begin(), vols.end(), CheckFnc )) );
00126             }
00127         VolIterator vEnd( bool (* CheckFnc)( const Volume& )=NULL )
00128             {
00129             return( VolIterator( VolPIterator(vols.begin(), vols.end(), CheckFnc, true )) );
00130             }
00131 
00132     public:
00133         Container( Storage * const, const string& Name, storage::CType typ );
00134         Container( const Container& );
00135         Storage * getStorage() const { return sto; }
00136         virtual ~Container();
00137         const string& name() const { return nm; }
00138         const string& device() const { return dev; }
00139         storage::CType type() const { return typ; }
00140         bool deleted() const { return del; }
00141         bool created() const { return create; }
00142         void setDeleted( bool val=true ) { del=val; }
00143         void setCreated( bool val=true ) { create=val; }
00144         void setSilent( bool val=true ) { silent=val; }
00145         void setUsedBy( storage::UsedByType t, const string& name ) { uby.set( t, name );}
00146         const storage::usedBy& getUsedBy() const { return( uby ); }
00147         storage::UsedByType getUsedByType() const { return( uby.type() ); }
00148         const string& usedByName() const { return( uby.name() ); }
00149         bool readonly() const { return ronly; }
00150         unsigned long long sizeK() const { return size_k; }
00151         unsigned long minorNr() const { return mnr; }
00152         unsigned long majorNr() const { return mjr; }
00153         virtual string removeText(bool doing=true) const;
00154         virtual string createText(bool doing=true) const;
00155         virtual int resizeVolume( Volume* v, unsigned long long newSize );
00156         virtual int removeVolume( Volume* v );
00157         static storage::CType staticType() { return storage::CUNKNOWN; }
00158         friend std::ostream& operator<< (std::ostream& s, const Container &c );
00159         virtual Container* getCopy() const { return( new Container( *this ) ); }
00160         bool compareContainer( const Container* c, bool verbose ) const;
00161         void setExtError( const string& txt ) const;
00162         void setExtError( const SystemCmd& cmd, bool serr=true ) const;
00163 
00164     protected:
00165         typedef CVIter ConstPlainIterator;
00166         ConstPlainIterator begin() const { return vols.begin(); }
00167         ConstPlainIterator end() const { return vols.end(); }
00168 
00169         typedef VIter PlainIterator;
00170         PlainIterator begin() { return vols.begin(); }
00171         PlainIterator end() { return vols.end(); }
00172 
00173         virtual void print( std::ostream& s ) const { s << *this; }
00174         void addToList( Volume* e )
00175             { pointerIntoSortedList<Volume>( vols, e ); }
00176         bool removeFromList( Volume* e );
00177         virtual int doCreate( Volume * v );
00178         virtual int doRemove( Volume * v );
00179         virtual int doResize( Volume * v );
00180         virtual void logData( const string& Dir ) {;}
00181         Container& operator=( const Container& );
00182         static bool stageDecrease( const Volume& v )
00183             { return( v.deleted()||v.needShrink()); }
00184         static bool stageCreate( const Volume& v )
00185             { return( v.created()||v.needExtend()); }
00186 
00187         static string type_names[COTYPE_LAST_ENTRY];
00188         static unsigned order[COTYPE_LAST_ENTRY];
00189 
00190         Storage * const sto;
00191         storage::CType typ;
00192         string nm;
00193         string dev;
00194         bool del;
00195         bool create;
00196         bool silent;
00197         bool ronly;
00198         storage::usedBy uby;
00199         unsigned long long size_k;
00200         unsigned long mnr;
00201         unsigned long mjr;
00202         VCont vols;
00203         mutable storage::ContainerInfo info;
00204     };
00205 
00206 }
00207 
00208 #endif

Generated on Wed Apr 30 14:58:40 2008 for yast2-storage by  doxygen 1.4.6