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, const Volume* v, 
00034                   bool destr=false ) 
00035         { stage=s; type=t; descr=d; destructive=destr; container=false; 
00036           u.vol=v; }
00037     commitAction( CommitStage s, CType t, const string& d, const Container* co, 
00038                   bool destr=false ) 
00039         { stage=s; type=t; descr=d; destructive=destr; container=true; 
00040           u.co=co; }
00041     commitAction( CommitStage s, CType t, Volume* v )
00042         { stage=s; type=t; destructive=false; container=false; u.vol=v; }
00043     commitAction( CommitStage s, CType t, Container* c )
00044         { stage=s; type=t; destructive=false; container=true; u.co=c; }
00045     CommitStage stage;
00046     CType type;
00047     string descr;
00048     bool destructive;
00049     bool container;
00050     union 
00051         {
00052         const Volume* vol;
00053         const Container* co;
00054         } u;
00055     const Container* co() const { return( container?u.co:NULL ); }
00056     const Volume* vol() const { return( container?NULL:u.vol ); }
00057     bool operator==( const commitAction& rhs ) const
00058         { return( stage==rhs.stage && type==rhs.type ); }
00059     bool operator<( const commitAction& rhs ) const
00060         {
00061         contOrder l(type);
00062         contOrder r(rhs.type);
00063 
00064         if( stage==rhs.stage && stage==MOUNT )
00065             return( false );
00066         else if( unsigned(r)==unsigned(l) )
00067             {
00068             if( stage==rhs.stage )
00069                 {
00070                 if( stage==DECREASE )
00071                     {
00072                     if( type!=rhs.type )
00073                         return( type>rhs.type );
00074                     else
00075                         return( container<rhs.container );
00076                     }
00077                 else
00078                     {
00079                     if( type!=rhs.type )
00080                         return( type<rhs.type );
00081                     else
00082                         return( container>rhs.container );
00083                     }
00084                 }
00085             else
00086                 return( stage<rhs.stage );
00087             }
00088         else
00089             return( unsigned(l)<unsigned(r) );
00090         }
00091     bool operator<=( const commitAction& rhs ) const
00092         { return( *this < rhs || *this == rhs ); }
00093     bool operator>=( const commitAction& rhs ) const
00094         { return( ! (*this < rhs) ); }
00095     bool operator>( const commitAction& rhs ) const
00096         { return( !(*this < rhs && *this == rhs) ); }
00097     };
00098 
00099 struct usedBy
00100     {
00101     usedBy() : t(storage::UB_NONE) {;}
00102     usedBy( storage::UsedByType typ, const string& n ) : t(typ), nm(n) {;}
00103     void clear() { t=storage::UB_NONE; nm.erase(); }
00104     void set( storage::UsedByType type, const string& n ) 
00105         { t=type; (t==storage::UB_NONE)?nm.erase():nm=n; }
00106     bool operator==( const usedBy& rhs ) const
00107         { return( t==rhs.t && nm==rhs.nm ); }
00108     bool operator!=( const usedBy& rhs ) const
00109         { return( !(*this==rhs)); }
00110     inline operator string() const;
00111 
00112     storage::UsedByType type() const { return( t ); }
00113     const string& name() const { return( nm ); }
00114     friend inline std::ostream& operator<< (std::ostream&, const usedBy& );
00115 
00116     storage::UsedByType t;
00117     string nm;
00118     };
00119 
00120 inline usedBy::operator string() const
00121     {
00122     string st;
00123     if( t!=storage::UB_NONE )
00124         {
00125         switch( t )
00126             {
00127             case storage::UB_LVM:
00128                 st = "lvm";
00129                 break;
00130             case storage::UB_MD: 
00131                 st = "md";
00132                 break;
00133             case storage::UB_EVMS: 
00134                 st = "evms";
00135                 break;
00136             case storage::UB_DM:
00137                 st = "dm";
00138                 break;
00139             case storage::UB_DMRAID:
00140                 st = "dmraid";
00141                 break;
00142             default:
00143                 st = "UNKNOWN";
00144                 break;
00145             }
00146         st += "[" + nm + "]";
00147         }
00148     return( st );
00149     }
00150 
00151 inline std::ostream& operator<< (std::ostream& s, const usedBy& d )
00152     {
00153     if( d.t!=storage::UB_NONE )
00154         {
00155         s << " UsedBy:" << string(d);
00156         }
00157     return( s );
00158     }
00159 
00160 struct match_string
00161     {
00162     match_string( const string& t ) : r(t) {};
00163     bool operator()(const string&s) { return( r.match( s )); }
00164     Regex r;
00165     };
00166 
00167 struct find_begin
00168     {
00169     find_begin( const string& t ) : val(t) {};
00170     bool operator()(const string&s) { return( s.find(val)==0 ); }
00171     const string& val;
00172     };
00173 
00174 struct find_any
00175     {
00176     find_any( const string& t ) : val(t) {};
00177     bool operator()(const string&s) { return( s.find(val)!=string::npos ); }
00178     const string& val;
00179     };
00180 
00181 }
00182 
00183 #endif

Generated on Tue Nov 28 17:50:01 2006 for yast2-storage by  doxygen 1.5.0