StorageTypes.h

Go to the documentation of this file.
00001 #ifndef STORAGE_TYPES_H
00002 #define STORAGE_TYPES_H
00003 
00004 #include <iostream>
00005 #include <ext/stdio_filebuf.h>
00006 
00007 #include "y2storage/Regex.h"
00008 #include "y2storage/AppUtil.h"
00009 #include "y2storage/StorageInterface.h"
00010 
00011 namespace storage
00012 {
00013 
00014 struct contOrder
00015     {
00016     contOrder(CType t) : order(0)
00017         {
00018         if( t==LOOP )
00019             order=1;
00020         }
00021     operator unsigned() const { return( order ); }
00022     protected:
00023         unsigned order;
00024     };
00025 
00026 typedef enum { DECREASE, INCREASE, FORMAT, MOUNT } CommitStage;
00027 
00028 class Volume;
00029 class Container;
00030 
00031 struct commitAction
00032     {
00033     commitAction( CommitStage s, CType t, const string& d, bool destr=false,
00034                   bool cont=false ) 
00035         { stage=s; type=t; descr=d; destructive=destr; container=cont; 
00036           u.co=NULL; u.vol=NULL; }
00037     commitAction( CommitStage s, CType t, Volume* v )
00038         { stage=s; type=t; destructive=false; container=false; u.vol=v; }
00039     commitAction( CommitStage s, CType t, Container* c )
00040         { stage=s; type=t; destructive=false; container=true; u.co=c; }
00041     CommitStage stage;
00042     CType type;
00043     string descr;
00044     bool destructive;
00045     bool container;
00046     union 
00047         {
00048         Volume* vol;
00049         Container* co;
00050         } u;
00051     Container* co() const { return( container?u.co:NULL ); }
00052     Volume* vol() const { return( container?NULL:u.vol ); }
00053     bool operator==( const commitAction& rhs ) const
00054         { return( stage==rhs.stage && type==rhs.type ); }
00055     bool operator<( const commitAction& rhs ) const
00056         {
00057         contOrder l(type);
00058         contOrder r(rhs.type);
00059 
00060         if( stage==rhs.stage && stage==MOUNT )
00061             return( false );
00062         else if( unsigned(r)==unsigned(l) )
00063             {
00064             if( stage==rhs.stage )
00065                 {
00066                 if( stage==DECREASE )
00067                     {
00068                     if( type!=rhs.type )
00069                         return( type>rhs.type );
00070                     else
00071                         return( container<rhs.container );
00072                     }
00073                 else
00074                     {
00075                     if( type!=rhs.type )
00076                         return( type<rhs.type );
00077                     else
00078                         return( container>rhs.container );
00079                     }
00080                 }
00081             else
00082                 return( stage<rhs.stage );
00083             }
00084         else
00085             return( unsigned(l)<unsigned(r) );
00086         }
00087     bool operator<=( const commitAction& rhs ) const
00088         { return( *this < rhs || *this == rhs ); }
00089     bool operator>=( const commitAction& rhs ) const
00090         { return( ! (*this < rhs) ); }
00091     bool operator>( const commitAction& rhs ) const
00092         { return( !(*this < rhs && *this == rhs) ); }
00093     };
00094 
00095 struct usedBy
00096     {
00097     usedBy() : t(storage::UB_NONE) {;}
00098     usedBy( storage::UsedByType typ, const string& n ) : t(typ), nm(n) {;}
00099     void clear() { t=storage::UB_NONE; nm.erase(); }
00100     void set( storage::UsedByType type, const string& n ) 
00101         { t=type; (t==storage::UB_NONE)?nm.erase():nm=n; }
00102     bool operator==( const usedBy& rhs ) const
00103         { return( t==rhs.t && nm==rhs.nm ); }
00104     bool operator!=( const usedBy& rhs ) const
00105         { return( !(*this==rhs)); }
00106     inline operator string() const;
00107 
00108     storage::UsedByType type() const { return( t ); }
00109     const string& name() const { return( nm ); }
00110     friend inline std::ostream& operator<< (std::ostream&, const usedBy& );
00111 
00112     storage::UsedByType t;
00113     string nm;
00114     };
00115 
00116 inline usedBy::operator string() const
00117     {
00118     string st;
00119     if( t!=storage::UB_NONE )
00120         {
00121         switch( t )
00122             {
00123             case storage::UB_LVM:
00124                 st = "lvm";
00125                 break;
00126             case storage::UB_MD: 
00127                 st = "md";
00128                 break;
00129             case storage::UB_EVMS: 
00130                 st = "evms";
00131                 break;
00132             case storage::UB_DM:
00133                 st = "dm";
00134                 break;
00135             default:
00136                 st = "UNKNOWN";
00137                 break;
00138             }
00139         st += "[" + nm + "]";
00140         }
00141     return( st );
00142     }
00143 
00144 inline std::ostream& operator<< (std::ostream& s, const usedBy& d )
00145     {
00146     if( d.t!=storage::UB_NONE )
00147         {
00148         s << " UsedBy:" << string(d);
00149         }
00150     return( s );
00151     }
00152 
00153 struct match_string
00154     {
00155     match_string( const string& t ) : r(t) {};
00156     bool operator()(const string&s) { return( r.match( s )); }
00157     Regex r;
00158     };
00159 
00160 struct find_begin
00161     {
00162     find_begin( const string& t ) : val(t) {};
00163     bool operator()(const string&s) { return( s.find(val)==0 ); }
00164     const string& val;
00165     };
00166 
00167 struct find_any
00168     {
00169     find_any( const string& t ) : val(t) {};
00170     bool operator()(const string&s) { return( s.find(val)!=string::npos ); }
00171     const string& val;
00172     };
00173 
00174 }
00175 
00176 #endif

Generated on Thu Jul 6 00:40:24 2006 for yast2-storage by  doxygen 1.4.6