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