PCL
Property.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.5
6 // ----------------------------------------------------------------------------
7 // pcl/Property.h - Released 2024-01-13T15:47:58Z
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-2024 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  using data_type = value_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 
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 
269 using PropertyArray = Array<Property>;
270 
271 // ----------------------------------------------------------------------------
272 
273 } // pcl
274 
275 #endif // __PCL_Property_h
276 
277 // ----------------------------------------------------------------------------
278 // EOF pcl/Property.h - Released 2024-01-13T15:47:58Z
pcl
PCL root namespace.
Definition: AbstractImage.h:76
pcl::Property::Id
const identifier_type & Id() const
Definition: Property.h:161
pcl::Variant
Acts like a union to store instances of different data types.
Definition: Variant.h:331
pcl::operator==
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2090
PropertyDescription.h
pcl::IsoString
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5424
pcl::Property::IsValidIdentifier
static bool IsValidIdentifier(const IsoString &id)
Definition: Property.h:206
PropertyArray
Dynamic array of Property objects.
pcl::Property::Property
Property(const identifier_type &identifier, const value_type &value)
Definition: Property.h:117
pcl::Property
An identifier-value association.
Definition: Property.h:78
pcl::Property::Property
Property(const identifier_type &identifier)
Definition: Property.h:127
pcl::PropertyDescription
A structure to describe a data property.
Definition: PropertyDescription.h:77
pcl::GenericString< char16_type, CharTraits, PCL_STRING_ALLOCATOR >
pcl::Property::~Property
virtual ~Property()
Definition: Property.h:145
pcl::Property::Identifier
const identifier_type & Identifier() const
Definition: Property.h:152
pcl::Array< IsoString >
pcl::Property::SetValue
void SetValue(const value_type &value)
Definition: Property.h:178
pcl::Property::Value
const value_type & Value() const
Definition: Property.h:169
pcl::Property::IsValid
bool IsValid() const
Definition: Property.h:227
pcl::Property::Description
PropertyDescription Description() const
Definition: Property.h:196
Defs.h
pcl::Property::Type
data_type Type() const
Definition: Property.h:187
pcl::operator<
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2101