LayoutFlags.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
10 #include <UI\UIFramework.h>
11 #include <UI\Layout\LayoutEnums.h>
12 
14 
15 //=======================================================================================
20 //=======================================================================================
22  {
23  public:
25  inline LayoutFlag (int ai) : m_value (ai) {}
26 
28  inline operator int () const { return m_value; }
29 
30  private:
31  int m_value;
32  };
33 
34 template<typename Enum>
35 
36 //=======================================================================================
42 //=======================================================================================
44  {
45  typedef void **Zero;
46 
47  public:
48  typedef Enum enum_type;
49 
51  inline LayoutFlags (const LayoutFlags &f) : m_value (f.m_value) {}
53  inline LayoutFlags (Enum f) : m_value (f) {}
55  inline LayoutFlags (Zero = 0) : m_value (0) {}
57  inline LayoutFlags (LayoutFlag f) : m_value (f) {}
58 
61  {
62  m_value = f.m_value;
63  return *this;
64  }
66  inline LayoutFlags &operator &= (int mask)
67  {
68  m_value &= mask;
69  return *this;
70  }
72  inline LayoutFlags &operator &= (UInt mask)
73  {
74  m_value &= mask;
75  return *this;
76  }
78  inline LayoutFlags &operator |= (LayoutFlags f)
79  {
80  m_value |= f.m_value;
81  return *this;
82  }
84  inline LayoutFlags &operator |= (Enum f)
85  {
86  m_value |= f;
87  return *this;
88  }
90  inline LayoutFlags &operator ^= (LayoutFlags f)
91  {
92  m_value ^= f.m_value;
93  return *this;
94  }
96  inline LayoutFlags &operator ^= (Enum f)
97  {
98  m_value ^= f;
99  return *this;
100  }
102  inline LayoutFlags &operator ^= (int mask)
103  {
104  m_value ^= mask;
105  return *this;
106  }
107 
109  inline operator int () const
110  {
111  return m_value;
112  }
113 
116  {
117  LayoutFlags g;
118  g.m_value = m_value | f.m_value;
119  return g;
120  }
122  inline LayoutFlags operator | (Enum f) const
123  {
124  LayoutFlags g;
125  g.m_value = m_value | f;
126  return g;
127  }
129  inline LayoutFlags operator ^ (LayoutFlags f) const
130  {
131  LayoutFlags g;
132  g.m_value = m_value ^ f.m_value;
133  return g;
134  }
136  inline LayoutFlags operator ^ (Enum f) const
137  {
138  LayoutFlags g;
139  g.m_value = m_value ^ f;
140  return g;
141  }
143  inline LayoutFlags operator & (int mask) const
144  {
145  LayoutFlags g;
146  g.m_value = m_value & mask;
147  return g;
148  }
150  inline LayoutFlags operator & (UInt mask) const
151  {
152  LayoutFlags g;
153  g.m_value = m_value & mask;
154  return g;
155  }
157  inline LayoutFlags operator & (Enum f) const
158  {
159  LayoutFlags g;
160  g.m_value = m_value & f;
161  return g;
162  }
164  inline LayoutFlags operator ~ () const
165  {
166  LayoutFlags g;
167  g.m_value = ~m_value;
168  return g;
169  }
170 
172  inline bool operator ! () const
173  {
174  return !m_value;
175  }
176 
178  inline bool testFlag (Enum f) const
179  {
180  return (m_value & f) == f && (f != 0 || m_value == int (f));
181  }
182 
183  private:
184  int m_value;
185  };
186 
188 #define DECLARE_FLAGS(Flags, Enum)\
189  typedef LayoutFlags<Enum> Flags;
190 
192 #define DECLARE_OPERATORS_FOR_FLAGS(Flags) \
193  inline LayoutFlags<Flags::enum_type> operator | (Flags::enum_type f1, Flags::enum_type f2) \
194  { return LayoutFlags<Flags::enum_type>(f1) | f2; } \
195  inline LayoutFlags<Flags::enum_type> operator | (Flags::enum_type f1, LayoutFlags<Flags::enum_type> f2) \
196  { return f2 | f1; } DECLARE_INCOMPATIBLE_FLAGS(Flags)
197 
199 
201 
Enum enum_type
Definition: LayoutFlags.h:48
LayoutOrientation
This type is used to signify an object's orientation.
Definition: LayoutEnums.h:94
bool operator!(DgnECHostType a)
Definition: DgnECInstance.h:92
unsigned int UInt
Definition: Bentley.r.h:140
Maintains a single int value with an (int) cast overload.
Definition: LayoutFlags.h:21
LayoutFlags - Creates a "Flags" class out of an enum with constructors and operator overloading...
Definition: LayoutFlags.h:43
DgnECHostType operator|(DgnECHostType a, DgnECHostType b)
Definition: DgnECInstance.h:92
bstdmap & operator=(const bstdmap &__rhs)
Definition: stdcxx/bstdmap.h:170
LayoutFlags(const LayoutFlags &f)
Constructs a LayoutFlags object given another LayoutFlags.
Definition: LayoutFlags.h:51
#define BEGIN_BENTLEY_UIFRAMEWORK_NAMESPACE
Definition: UIFramework.h:14
#define DECLARE_FLAGS(Flags, Enum)
Creates a LayoutFlags typedef for an Enum.
Definition: LayoutFlags.h:188
AlignmentFlag
AlignmentFlag / Alignment.
Definition: LayoutEnums.h:51
#define DLLEXPORT
Definition: basedefs.h:137
LayoutFlags(Zero=0)
Constructs a LayoutFlags object given a void*.
Definition: LayoutFlags.h:55
LayoutFlag(int ai)
Constructs a LayoutFlag.
Definition: LayoutFlags.h:25
bool testFlag(Enum f) const
Tests the flag with the given Enum.
Definition: LayoutFlags.h:178
DgnECHostType operator~(DgnECHostType a)
Definition: DgnECInstance.h:92
#define END_BENTLEY_UIFRAMEWORK_NAMESPACE
Definition: UIFramework.h:15
LayoutFlags(Enum f)
Constructs a LayoutFlags object given an Enum.
Definition: LayoutFlags.h:53
DgnECHostType operator&(DgnECHostType a, DgnECHostType b)
Definition: DgnECInstance.h:92
LayoutFlags(LayoutFlag f)
Constructs a LayoutFlags object given a LayoutFlag.
Definition: LayoutFlags.h:57

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.