Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

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/StorageInterface.h"
00009 
00010 namespace storage
00011 {
00012 struct contOrder
00013     {
00014     contOrder(CType t) : order(0)
00015         {
00016         if( t==LOOP )
00017             order=1;
00018         }
00019     operator unsigned() const { return( order ); }
00020     protected:
00021         unsigned order;
00022     };
00023 
00024 typedef enum { DECREASE, INCREASE, FORMAT, MOUNT } CommitStage;
00025 
00026 struct commitAction
00027     {
00028     commitAction( CommitStage s, CType t, const string& d, bool destr=false,
00029                   bool cont=false ) 
00030         { stage=s; type=t; descr=d; destructive=destr; container=cont; }
00031     CommitStage stage;
00032     CType type;
00033     string descr;
00034     bool destructive;
00035     bool container;
00036     bool operator==( const commitAction& rhs ) const
00037         { return( stage==rhs.stage && type==rhs.type ); }
00038     bool operator<( const commitAction& rhs ) const
00039         {
00040         contOrder l(type);
00041         contOrder r(rhs.type);
00042 
00043         if( unsigned(r)==unsigned(l) )
00044             {
00045             if( stage==rhs.stage )
00046                 {
00047                 if( stage==DECREASE )
00048                     {
00049                     if( type!=rhs.type )
00050                         return( type>rhs.type );
00051                     else
00052                         return( container<rhs.container );
00053                     }
00054                 else
00055                     {
00056                     if( type!=rhs.type )
00057                         return( type<rhs.type );
00058                     else
00059                         return( container>rhs.container );
00060                     }
00061                 }
00062             else
00063                 return( stage<rhs.stage );
00064             }
00065         else
00066             return( unsigned(l)<unsigned(r) );
00067         }
00068     bool operator<=( const commitAction& rhs ) const
00069         { return( *this < rhs || *this == rhs ); }
00070     bool operator>=( const commitAction& rhs ) const
00071         { return( ! (*this < rhs) ); }
00072     bool operator>( const commitAction& rhs ) const
00073         { return( !(*this < rhs && *this == rhs) ); }
00074     };
00075 
00076 struct usedBy
00077     {
00078     usedBy() : t(storage::UB_NONE) {;}
00079     usedBy( storage::UsedByType typ, const string& n ) : t(typ), nm(n) {;}
00080     void clear() { t=storage::UB_NONE; nm.erase(); }
00081     void set( storage::UsedByType type, const string& n ) 
00082         { t=type; (t==storage::UB_NONE)?nm.erase():nm=n; }
00083     bool operator==( const usedBy& rhs ) const
00084         { return( t==rhs.t && nm==rhs.nm ); }
00085     bool operator!=( const usedBy& rhs ) const
00086         { return( !(*this==rhs)); }
00087     inline operator string() const;
00088 
00089     storage::UsedByType type() const { return( t ); }
00090     const string& name() const { return( nm ); }
00091     friend inline std::ostream& operator<< (std::ostream&, const usedBy& );
00092 
00093     storage::UsedByType t;
00094     string nm;
00095     };
00096 
00097 inline usedBy::operator string() const
00098     {
00099     string st;
00100     if( t!=storage::UB_NONE )
00101         {
00102         switch( t )
00103             {
00104             case storage::UB_LVM:
00105                 st = "lvm";
00106                 break;
00107             case storage::UB_MD: 
00108                 st = "md";
00109                 break;
00110             case storage::UB_EVMS: 
00111                 st = "evms";
00112                 break;
00113             case storage::UB_DM:
00114                 st = "dm";
00115                 break;
00116             default:
00117                 st = "UNKNOWN";
00118                 break;
00119             }
00120         st += "[" + nm + "]";
00121         }
00122     return( st );
00123     }
00124 
00125 inline std::ostream& operator<< (std::ostream& s, const usedBy& d )
00126     {
00127     if( d.t!=storage::UB_NONE )
00128         {
00129         s << " UsedBy:" << string(d);
00130         }
00131     return( s );
00132     }
00133 
00134 struct match_string
00135     {
00136     match_string( const string& t ) : r(t) {};
00137     bool operator()(const string&s) { return( r.match( s )); }
00138     Regex r;
00139     };
00140 
00141 struct find_begin
00142     {
00143     find_begin( const string& t ) : val(t) {};
00144     bool operator()(const string&s) { return( s.find(val)==0 ); }
00145     const string& val;
00146     };
00147 
00148 }
00149 
00150 #endif

Generated on Wed Sep 14 11:27:07 2005 for yast2-storage by  doxygen 1.4.4