PCL
Settings.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/Settings.h - Released 2024-06-18T15:48:54Z
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_Settings_h
53 #define __PCL_Settings_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
60 #include <pcl/ByteArray.h>
61 #include <pcl/String.h>
62 
63 #ifndef __PCL_NO_FLAGS_SETTINGS_IO
64 # include <pcl/Flags.h>
65 #endif
66 
67 namespace pcl
68 {
69 
70 // ----------------------------------------------------------------------------
71 
105 class PCL_CLASS Settings
106 {
107 public:
108 
113  Settings() = delete;
114 
119  Settings( const Settings& ) = delete;
120 
125  Settings& operator =( const Settings& ) = delete;
126 
131  ~Settings() = delete;
132 
148  static bool Read( const IsoString& key, ByteArray& b );
149 
166  static bool ReadGlobal( const IsoString& key, ByteArray& b );
167 
183  static bool Read( const IsoString& key, String& s );
184 
202  static bool ReadGlobal( const IsoString& key, String& s );
203 
219  static bool Read( const IsoString& key, bool& b );
220 
237  static bool ReadGlobal( const IsoString& key, bool& b );
238 
254  static bool Read( const IsoString& key, int& i );
255 
272  static bool ReadGlobal( const IsoString& key, int& i );
273 
289  static bool Read( const IsoString& key, unsigned& u );
290 
308  static bool ReadGlobal( const IsoString& key, unsigned& u );
309 
325  static bool Read( const IsoString& key, double& f );
326 
343  static bool ReadGlobal( const IsoString& key, double& f );
344 
358  static bool Read( const IsoString& key, float& f )
359  {
360  double d; Read( key, d );
361  if ( LastReadOK() ) { f = float( d ); return true; }
362  return false;
363  }
364 
378  static bool ReadGlobal( const IsoString& key, float& f )
379  {
380  double d; ReadGlobal( key, d );
381  if ( LastReadOK() ) { f = float( d ); return true; }
382  return false;
383  }
384 
385 #ifndef __PCL_NO_SETTINGS_TEMPLATES
386 
399  template <typename T>
400  static bool ReadI( const IsoString& key, T& t )
401  {
402  int i; Read( key, i );
403  if ( LastReadOK() ) { t = T( i ); return true; }
404  return false;
405  }
406 
407 
420  template <typename T>
421  static bool ReadU( const IsoString& key, T& t )
422  {
423  unsigned u; Read( key, u );
424  if ( LastReadOK() ) { t = T( u ); return true; }
425  return false;
426  }
427 
428 #endif
429 
430 #ifndef __PCL_NO_FLAGS_SETTINGS_IO
431 
448  template <typename E>
449  static bool Read( const IsoString& key, Flags<E>& f )
450  {
451  return Read( key, f.m_flags );
452  }
453 
470  template <typename E>
471  static bool ReadGlobal( const IsoString& key, Flags<E>& f )
472  {
473  return ReadGlobal( key, f.m_flags );
474  }
475 
476 #endif
477 
482  static bool LastReadOK();
483 
499  static void Write( const IsoString& key, const ByteArray& b );
500 
520  static void WriteGlobal( const IsoString& key, const ByteArray& b );
521 
537  static void Write( const IsoString& key, const String& s );
538 
559  static void WriteGlobal( const IsoString& key, const String& s );
560 
576  static void Write( const IsoString& key, bool b );
577 
597  static void WriteGlobal( const IsoString& key, bool b );
598 
614  static void Write( const IsoString& key, int i );
615 
635  static void WriteGlobal( const IsoString& key, int i );
636 
652  static void Write( const IsoString& key, unsigned u );
653 
674  static void WriteGlobal( const IsoString& key, unsigned u );
675 
691  static void Write( const IsoString& key, double f );
692 
712  static void WriteGlobal( const IsoString& key, double f );
713 
727  static void Write( const IsoString& key, float f )
728  {
729  Write( key, double( f ) );
730  }
731 
745  static void WriteGlobal( const IsoString& key, float f )
746  {
747  WriteGlobal( key, double( f ) );
748  }
749 
750 #ifndef __PCL_NO_SETTINGS_TEMPLATES
751 
759  template <typename T>
760  static void WriteI( const IsoString& key, T t )
761  {
762  Write( key, int( t ) );
763  }
764 
772  template <typename T>
773  static void WriteU( const IsoString& key, T t )
774  {
775  Write( key, unsigned( t ) );
776  }
777 
778 #endif
779 
780 #ifndef __PCL_NO_FLAGS_SETTINGS_IO
781 
797  template <typename E>
798  static void Write( const IsoString& key, Flags<E> f )
799  {
800  Write( key, f.m_flags );
801  }
802 
822  template <typename E>
823  static void WriteGlobal( const IsoString& key, Flags<E> f )
824  {
825  WriteGlobal( key, f.m_flags );
826  }
827 
828 #endif
829 
836  static void Remove( const IsoString& key );
837 
850  static void RemoveGlobal( const IsoString& key );
851 
860  static bool CanReadGlobal( const IsoString& key );
861 
870  static bool CanWriteGlobal( const IsoString& key );
871 
886  static void SetGlobalKeyAccess( const IsoString& key, bool allowRead, bool allowWrite );
887 };
888 
889 // ----------------------------------------------------------------------------
890 
891 } // pcl
892 
893 #endif // __PCL_Settings_h
894 
895 // ----------------------------------------------------------------------------
896 // EOF pcl/Settings.h - Released 2024-06-18T15:48:54Z
A type-safe collection of enumerated flags.
Definition: Flags.h:85
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5425
Persistent module settings.
Definition: Settings.h:106
static void WriteGlobal(const IsoString &key, const String &s)
static void Write(const IsoString &key, float f)
Definition: Settings.h:727
static void Write(const IsoString &key, int i)
static void WriteGlobal(const IsoString &key, double f)
static void WriteGlobal(const IsoString &key, const ByteArray &b)
static void WriteGlobal(const IsoString &key, float f)
Definition: Settings.h:745
Settings()=delete
Settings(const Settings &)=delete
static bool ReadU(const IsoString &key, T &t)
Definition: Settings.h:421
static void SetGlobalKeyAccess(const IsoString &key, bool allowRead, bool allowWrite)
static bool CanReadGlobal(const IsoString &key)
static void Write(const IsoString &key, bool b)
static void WriteU(const IsoString &key, T t)
Definition: Settings.h:773
static bool Read(const IsoString &key, int &i)
static bool Read(const IsoString &key, bool &b)
static bool Read(const IsoString &key, ByteArray &b)
static void WriteGlobal(const IsoString &key, unsigned u)
static bool ReadGlobal(const IsoString &key, float &f)
Definition: Settings.h:378
static bool ReadGlobal(const IsoString &key, unsigned &u)
static bool Read(const IsoString &key, Flags< E > &f)
Definition: Settings.h:449
static void WriteI(const IsoString &key, T t)
Definition: Settings.h:760
static void WriteGlobal(const IsoString &key, int i)
static bool ReadGlobal(const IsoString &key, bool &b)
static void Write(const IsoString &key, Flags< E > f)
Definition: Settings.h:798
static bool CanWriteGlobal(const IsoString &key)
static bool Read(const IsoString &key, unsigned &u)
static void Write(const IsoString &key, const ByteArray &b)
static bool LastReadOK()
static bool Read(const IsoString &key, double &f)
static bool ReadGlobal(const IsoString &key, double &f)
static bool ReadGlobal(const IsoString &key, String &s)
static bool ReadGlobal(const IsoString &key, Flags< E > &f)
Definition: Settings.h:471
static void Remove(const IsoString &key)
static bool Read(const IsoString &key, float &f)
Definition: Settings.h:358
static bool ReadGlobal(const IsoString &key, int &i)
static void Write(const IsoString &key, unsigned u)
static void RemoveGlobal(const IsoString &key)
~Settings()=delete
static bool Read(const IsoString &key, String &s)
static void Write(const IsoString &key, const String &s)
static void Write(const IsoString &key, double f)
static bool ReadI(const IsoString &key, T &t)
Definition: Settings.h:400
static void WriteGlobal(const IsoString &key, Flags< E > f)
Definition: Settings.h:823
static bool ReadGlobal(const IsoString &key, ByteArray &b)
static void WriteGlobal(const IsoString &key, bool b)
Unicode (UTF-16) string.
Definition: String.h:8113
PCL root namespace.
Definition: AbstractImage.h:77