PCL
Property.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.4.7
6 // ----------------------------------------------------------------------------
7 // pcl/Property.h - Released 2020-12-17T15:46:29Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2020 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Property_h
53 #define __PCL_Property_h
54 
56 
57 #include <pcl/Defs.h>
58 
60 
61 namespace pcl
62 {
63 
64 // ----------------------------------------------------------------------------
65 
78 class PCL_CLASS Property
79 {
80 public:
81 
86 
91 
95  typedef value_type::data_type data_type;
96 
101  Property() = default;
102 
106  Property( const Property& ) = default;
107 
111  Property( Property&& ) = default;
112 
117  Property( const identifier_type& identifier, const value_type& value )
118  : m_id( identifier )
119  , m_value( value )
120  {
121  }
122 
127  Property( const identifier_type& identifier )
128  : m_id( identifier )
129  {
130  }
131 
135  Property& operator =( const Property& ) = default;
136 
140  Property& operator =( Property&& ) = default;
141 
145  virtual ~Property()
146  {
147  }
148 
152  const identifier_type& Identifier() const
153  {
154  return m_id;
155  }
156 
161  const identifier_type& Id() const
162  {
163  return Identifier();
164  }
165 
169  const value_type& Value() const
170  {
171  return m_value;
172  }
173 
178  void SetValue( const value_type& value )
179  {
180  m_value = value;
181  }
182 
187  data_type Type() const
188  {
189  return m_value.Type();
190  }
191 
197  {
198  return PropertyDescription( m_id, m_value.Type() );
199  }
200 
206  static bool IsValidIdentifier( const IsoString& id )
207  {
208  if ( id.IsEmpty() )
209  return false;
210  IsoStringList tokens;
211  id.Break( tokens, ':' );
212  for ( const IsoString& token : tokens )
213  if ( !token.IsValidIdentifier() )
214  return false;
215  return true;
216  }
217 
218  static bool IsValidIdentifier( const IsoString::ustring_base& id )
219  {
220  return IsValidIdentifier( IsoString( id ) );
221  }
222 
227  bool IsValid() const
228  {
229  return IsValidIdentifier( m_id ) && m_value.IsValid();
230  }
231 
239  bool operator ==( const Property& other ) const
240  {
241  return m_id == other.m_id;
242  }
243 
252  bool operator <( const Property& other ) const
253  {
254  return m_id < other.m_id;
255  }
256 
257 protected:
258 
259  identifier_type m_id;
260  value_type m_value;
261 };
262 
270 
271 // ----------------------------------------------------------------------------
272 
273 } // pcl
274 
275 #endif // __PCL_Property_h
276 
277 // ----------------------------------------------------------------------------
278 // EOF pcl/Property.h - Released 2020-12-17T15:46:29Z
const identifier_type & Identifier() const
Definition: Property.h:152
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2092
void SetValue(const value_type &value)
Definition: Property.h:178
Dynamic list of 8-bit strings.
virtual ~Property()
Definition: Property.h:145
PCL root namespace.
Definition: AbstractImage.h:76
const identifier_type & Id() const
Definition: Property.h:161
Property(const identifier_type &identifier, const value_type &value)
Definition: Property.h:117
PropertyDescription Description() const
Definition: Property.h:196
IsoString identifier_type
Definition: Property.h:85
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2103
An identifier-value association.
Definition: Property.h:78
value_type::data_type data_type
Definition: Property.h:95
A structure to describe a data property.
static bool IsValidIdentifier(const IsoString &id)
Definition: Property.h:206
Variant value_type
Definition: Property.h:90
data_type Type() const
Definition: Property.h:187
Generic dynamic array.
Definition: Array.h:99
Acts like a union to store instances of different data types.
Definition: Variant.h:331
Dynamic array of Property objects.
const value_type & Value() const
Definition: Property.h:169
bool IsValid() const
Definition: Property.h:227
Property(const identifier_type &identifier)
Definition: Property.h:127
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5397