libUTL++
UnixModeMask.h
1 #pragma once
2 
4 
5 #if UTL_HOST_OS != UTL_OS_MINGW
6 
8 
9 #include <libutl/Object.h>
10 
12 
13 UTL_NS_BEGIN;
14 
16 
27 
29 class UnixModeMask : public Object, protected FlagsMI
30 {
32 
33 public:
39  {
40  _mode = mode;
41  }
42 
43  virtual int compare(const Object& rhs) const;
44 
45  virtual void copy(const Object& rhs);
46 
47  virtual void serialize(Stream& stream, uint_t io, uint_t mode = ser_default);
48 
49  virtual String toString() const;
50 
52  uint32_t
53  get() const
54  {
55  return _mode;
56  }
57 
59  void
60  set(uint32_t mode)
61  {
62  _mode = mode;
63  }
64 
66  bool isSetUserId() const;
67 
69  void setSetUserId(bool suid);
70 
72  bool isSetGroupId() const;
73 
75  void setSetGroupId(bool sgid);
76 
78  bool isSticky() const;
79 
81  void setSticky(bool sticky);
82 
84  bool isOwnerReadable() const;
85 
87  void setOwnerReadable(bool ownerReadable);
88 
90  bool isOwnerWritable() const;
91 
93  void setOwnerWritable(bool ownerWritable);
94 
96  bool isOwnerExecutable() const;
97 
99  void setOwnerExecutable(bool ownerExecutable);
100 
102  bool isGroupReadable() const;
103 
105  void setGroupReadable(bool groupReadable);
106 
108  bool isGroupWritable() const;
109 
111  void setGroupWritable(bool groupWritable);
112 
114  bool isGroupExecutable() const;
115 
117  void setGroupExecutable(bool groupExecutable);
118 
120  bool isOtherReadable() const;
121 
123  void setOtherReadable(bool worldReadable);
124 
126  bool isOtherWritable() const;
127 
129  void setOtherWritable(bool worldWritable);
130 
132  bool isOtherExecutable() const;
133 
135  void setOtherExecutable(bool worldExecutable);
136 
138  operator uint32_t() const
139  {
140  return _mode;
141  }
142 
143  uint_t
144  getCompareMode() const
145  {
146  return (_flags & 3ULL);
147  }
148 
149  void
150  setCompareMode(uint_t cmode)
151  {
152  _flags &= ~3ULL;
153  _flags |= (uint64_t)((uint64_t)cmode & 3ULL);
154  }
155 
157  enum cmode_t
158  {
161  cm_and_rhs
162  };
163 
164 private:
165  enum flg_t
166  {
167  flg_cmode0,
168  flg_cmode1
169  };
170 
171 private:
172  void
173  init()
174  {
175  _mode = 0;
176  }
177  void
178  deInit()
179  {
180  }
181 
182 private:
183  uint32_t _mode;
184 };
185 
187 
188 UTL_NS_END;
189 
191 
192 #endif
String toString(const FwdIt &begin, const FwdIt &end, const String &sep, bool key=false)
Obtain a string representation of a sequence (via Object::toString()).
void serialize(bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boolean.
cmode_t
Comparison mode.
Definition: UnixModeMask.h:157
void deInit()
De-initialize UTL++.
default representation (via getSerializeMode())
Definition: util.h:75
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
Character string.
Definition: String.h:31
Mix-in to provide 64-bits for space-efficient storage of up to 64 boolean flags.
Definition: FlagsMI.h:25
unsigned int uint32_t
Unsigned 32-bit integer.
Definition: types.h:115
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
unsigned long uint64_t
Unsigned 64-bit integer.
Definition: types.h:154
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Stream I/O abstraction.
Definition: Stream.h:68
UnixModeMask(uint32_t mode)
Constructor.
Definition: UnixModeMask.h:38
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
Unix file mode mask.
Definition: UnixModeMask.h:29
void init()
Initialize UTL++.
all bits high in lhs must be high in rhs
Definition: UnixModeMask.h:160