• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/io/Permissions.h

00001 /*
00002  *   Ported to SPL, original attribution below.
00003  */
00004  /* ---------------------------------------------------------------------------
00005    commonc++ - A C++ Common Class Library
00006    Copyright (C) 2005-2009  Mark A Lindner
00007 
00008    Ported from the commonc++ project.
00009 
00010    This library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Library General Public
00012    License as published by the Free Software Foundation; either
00013    version 2 of the License, or (at your option) any later version.
00014 
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Library General Public License for more details.
00019 
00020    You should have received a copy of the GNU Library General Public
00021    License along with this library; if not, write to the Free
00022    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023    ---------------------------------------------------------------------------
00024 */
00025 
00026 #ifndef __ccxx_Permissions_hxx
00027 #define __ccxx_Permissions_hxx
00028 
00029 #include <spl/types.h>
00030 #include <spl/Debug.h>
00031 
00032 #ifdef _WINDOWS
00033 #include <spl/configwin32.h>
00034 #else
00035 #include <spl/autoconf/config.h>
00036 #endif
00037 
00038 #include <spl/String.h>
00039 
00052 class Permissions
00053 {
00054 private:
00055 
00056         uint32 _mask;
00057 
00058 public:
00059 
00064         Permissions(uint32 mask = 0) throw();
00065 
00068         Permissions(const Permissions& other) throw();
00069 
00072         ~Permissions() throw();
00073 
00075         static const int USER_READ;
00076 
00078         static const int USER_WRITE;
00079 
00081         static const int USER_READ_WRITE;
00082 
00084         static const int USER_EXECUTE;
00085 
00087         static const int USER_ALL;
00088 
00090         static const int GROUP_READ;
00091 
00093         static const int GROUP_WRITE;
00094 
00096         static const int GROUP_READ_WRITE;
00097 
00099         static const int GROUP_EXECUTE;
00100 
00102         static const int GROUP_ALL;
00103 
00105         static const int OTHERS_READ;
00106 
00108         static const int OTHERS_WRITE;
00109 
00111         static const int OTHERS_READ_WRITE;
00112 
00114         static const int OTHERS_EXECUTE;
00115 
00117         static const int OTHERS_ALL;
00118 
00120         static const int ALL_READ_WRITE;
00121 
00123         static const int ALLBITS;
00124 
00125         // user
00126 
00128         inline bool CanUserRead() const throw()
00129         { return((_mask & USER_READ) != 0); }
00130 
00132         inline void SetUserRead() throw()
00133         { _mask |= USER_READ; }
00134 
00136         inline void ClearUserRead() throw()
00137         { _mask &= ~USER_READ; }
00138 
00140         inline bool CanUserWrite() const throw()
00141         { return((_mask & USER_WRITE) != 0); }
00142 
00144         inline void SetUserWrite() throw()
00145         { _mask |= USER_WRITE; }
00146 
00148         inline void ClearUserWrite() throw()
00149         { _mask &= ~USER_WRITE; }
00150 
00152         inline bool CanUserExecute() const throw()
00153         { return((_mask & USER_EXECUTE) != 0); }
00154 
00156         inline void SetUserExecute() throw()
00157         { _mask |= USER_EXECUTE; }
00158 
00160         inline void ClearUserExecute() throw()
00161         { _mask &= ~USER_EXECUTE; }
00162 
00163         // group
00164 
00166         inline bool CanGroupRead() const throw()
00167         { return((_mask & GROUP_READ) != 0); }
00168 
00170         inline void SetGroupRead() throw()
00171         { _mask |= GROUP_READ; }
00172 
00174         inline void ClearGroupRead() throw()
00175         { _mask &= ~GROUP_READ; }
00176 
00178         inline bool CanGroupWrite() const throw()
00179         { return((_mask & GROUP_WRITE) != 0); }
00180 
00182         inline void SetGroupWrite() throw()
00183         { _mask |= GROUP_WRITE; }
00184 
00186         inline void ClearGroupWrite() throw()
00187         { _mask &= ~GROUP_WRITE; }
00188 
00190         inline bool CanGroupExecute() const throw()
00191         { return((_mask & GROUP_EXECUTE) != 0); }
00192 
00194         inline void SetGroupExecute() throw()
00195         { _mask |= GROUP_EXECUTE; }
00196 
00198         inline void ClearGroupExecute() throw()
00199         { _mask &= ~GROUP_EXECUTE; }
00200 
00201         // others
00202 
00204         inline bool CanOthersRead() const throw()
00205         { return((_mask & OTHERS_READ) != 0); }
00206 
00208         inline void SetOthersRead() throw()
00209         { _mask |= OTHERS_READ; }
00210 
00212         inline void ClearOthersRead() throw()
00213         { _mask &= ~OTHERS_READ; }
00214 
00216         inline bool CanOthersWrite() const throw()
00217         { return((_mask & OTHERS_WRITE) != 0); }
00218 
00220         inline void SetOthersWrite() throw()
00221         { _mask |= OTHERS_WRITE; }
00222 
00224         inline void ClearOthersWrite() throw()
00225         { _mask &= ~OTHERS_WRITE; }
00226 
00228         inline bool CanOthersExecute() const throw()
00229         { return((_mask & OTHERS_EXECUTE) != 0); }
00230 
00232         inline void SetOthersExecute() throw()
00233         { _mask |= OTHERS_EXECUTE; }
00234 
00236         inline void ClearOthersExecute() throw()
00237         { _mask &= ~OTHERS_EXECUTE; }
00238 
00240         inline void ClearAll() throw()
00241         { _mask = 0; }
00242 
00243         // operators
00244 
00245         Permissions& operator=(const Permissions& other) throw();
00246 
00249         inline uint32 GetMask() const throw()
00250         { return(_mask); }
00251 
00254         inline operator uint32() throw()
00255         { return(_mask); }
00256 
00260         StringPtr ToString() const;
00261 
00262         inline uint32 operator=(uint32 rhs) throw()
00263         { return((_mask = rhs)); }
00264 
00265         inline uint32 operator|=(uint32 rhs) throw()
00266         { return(_mask |= (rhs & ALLBITS)); }
00267 
00268         inline uint32 operator&=(uint32 rhs) throw()
00269         { return(_mask &= (rhs & ALLBITS)); }
00270 
00275         static const Permissions DefaultFilePerms;
00276 
00281         static const Permissions DefaultDirPerms;
00282 };
00283 
00284 REGISTER_TYPEOF(118, Permissions);
00285 
00286 inline uint32 operator|(const Permissions& perm, const uint32 rhs) throw()
00287 { return(perm.GetMask() | (rhs & Permissions::ALLBITS)); }
00288 
00289 inline uint32 operator&(const Permissions& perm, const uint32 rhs) throw()
00290 { return(perm.GetMask() & (rhs & Permissions::ALLBITS)); }
00291 
00294 #endif // __ccxx_Permissions_hxx
00295 
00296 /* end of header file */
00297 
00298