Permissions.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ccxx_Permissions_hxx
00024 #define __ccxx_Permissions_hxx
00025
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/String.h++>
00028
00029 namespace ccxx {
00030
00038 class COMMONCPP_API Permissions
00039 {
00040 public:
00041
00046 Permissions(uint_t mask = 0) throw();
00047
00049 Permissions(const Permissions& other) throw();
00050
00052 ~Permissions() throw();
00053
00055 static const int USER_READ;
00056
00058 static const int USER_WRITE;
00059
00061 static const int USER_READ_WRITE;
00062
00064 static const int USER_EXECUTE;
00065
00067 static const int USER_ALL;
00068
00070 static const int GROUP_READ;
00071
00073 static const int GROUP_WRITE;
00074
00076 static const int GROUP_READ_WRITE;
00077
00079 static const int GROUP_EXECUTE;
00080
00082 static const int GROUP_ALL;
00083
00085 static const int OTHERS_READ;
00086
00088 static const int OTHERS_WRITE;
00089
00091 static const int OTHERS_READ_WRITE;
00092
00094 static const int OTHERS_EXECUTE;
00095
00097 static const int OTHERS_ALL;
00098
00100 static const int ALL_READ_WRITE;
00101
00103 static const int ALLBITS;
00104
00105
00106
00108 inline bool canUserRead() const throw()
00109 { return((_mask & USER_READ) != 0); }
00110
00112 inline void setUserRead() throw()
00113 { _mask |= USER_READ; }
00114
00116 inline void clearUserRead() throw()
00117 { _mask &= ~USER_READ; }
00118
00120 inline bool canUserWrite() const throw()
00121 { return((_mask & USER_WRITE) != 0); }
00122
00124 inline void setUserWrite() throw()
00125 { _mask |= USER_WRITE; }
00126
00128 inline void clearUserWrite() throw()
00129 { _mask &= ~USER_WRITE; }
00130
00132 inline bool canUserExecute() const throw()
00133 { return((_mask & USER_EXECUTE) != 0); }
00134
00136 inline void setUserExecute() throw()
00137 { _mask |= USER_EXECUTE; }
00138
00140 inline void clearUserExecute() throw()
00141 { _mask &= ~USER_EXECUTE; }
00142
00143
00144
00146 inline bool canGroupRead() const throw()
00147 { return((_mask & GROUP_READ) != 0); }
00148
00150 inline void setGroupRead() throw()
00151 { _mask |= GROUP_READ; }
00152
00154 inline void clearGroupRead() throw()
00155 { _mask &= ~GROUP_READ; }
00156
00158 inline bool canGroupWrite() const throw()
00159 { return((_mask & GROUP_WRITE) != 0); }
00160
00162 inline void setGroupWrite() throw()
00163 { _mask |= GROUP_WRITE; }
00164
00166 inline void clearGroupWrite() throw()
00167 { _mask &= ~GROUP_WRITE; }
00168
00170 inline bool canGroupExecute() const throw()
00171 { return((_mask & GROUP_EXECUTE) != 0); }
00172
00174 inline void setGroupExecute() throw()
00175 { _mask |= GROUP_EXECUTE; }
00176
00178 inline void clearGroupExecute() throw()
00179 { _mask &= ~GROUP_EXECUTE; }
00180
00181
00182
00184 inline bool canOthersRead() const throw()
00185 { return((_mask & OTHERS_READ) != 0); }
00186
00188 inline void setOthersRead() throw()
00189 { _mask |= OTHERS_READ; }
00190
00192 inline void clearOthersRead() throw()
00193 { _mask &= ~OTHERS_READ; }
00194
00196 inline bool canOthersWrite() const throw()
00197 { return((_mask & OTHERS_WRITE) != 0); }
00198
00200 inline void setOthersWrite() throw()
00201 { _mask |= OTHERS_WRITE; }
00202
00204 inline void clearOthersWrite() throw()
00205 { _mask &= ~OTHERS_WRITE; }
00206
00208 inline bool canOthersExecute() const throw()
00209 { return((_mask & OTHERS_EXECUTE) != 0); }
00210
00212 inline void setOthersExecute() throw()
00213 { _mask |= OTHERS_EXECUTE; }
00214
00216 inline void clearOthersExecute() throw()
00217 { _mask &= ~OTHERS_EXECUTE; }
00218
00220 inline void clearAll() throw()
00221 { _mask = 0; }
00222
00223
00224
00226 Permissions& operator=(const Permissions& other) throw();
00227
00229 inline uint_t getMask() const throw()
00230 { return(_mask); }
00231
00233 inline operator uint_t() throw()
00234 { return(_mask); }
00235
00237 String toString() const;
00238
00239 inline uint_t operator=(uint_t rhs) throw()
00240 { return((_mask = rhs)); }
00241
00242 inline uint_t operator|=(uint_t rhs) throw()
00243 { return(_mask |= (rhs & ALLBITS)); }
00244
00245 inline uint_t operator&=(uint_t rhs) throw()
00246 { return(_mask &= (rhs & ALLBITS)); }
00247
00251 static const Permissions defaultFilePerms;
00252
00256 static const Permissions defaultDirPerms;
00257
00258 private:
00259
00260 uint_t _mask;
00261 };
00262
00263 inline uint_t operator|(const Permissions& perm, const uint_t rhs) throw()
00264 { return(perm.getMask() | (rhs & Permissions::ALLBITS)); }
00265
00266 inline uint_t operator&(const Permissions& perm, const uint_t rhs) throw()
00267 { return(perm.getMask() & (rhs & Permissions::ALLBITS)); }
00268
00269 };
00270
00271 #endif // __ccxx_Permissions_hxx
00272
00273