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