Parameter.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006-2011, SRI International (R)
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as published by
00006  * the Free Software Foundation, either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #pragma once
00019 
00020 #ifndef __OpenKarto_Parameter_h__
00021 #define __OpenKarto_Parameter_h__
00022 
00023 #include <OpenKarto/String.h>
00024 #include <OpenKarto/Geometry.h>
00025 #include <OpenKarto/Event.h>
00026 #include <OpenKarto/SmartPointer.h>
00027 #include <OpenKarto/Meta.h>
00028 
00029 namespace karto
00030 {
00031 
00033 
00034 
00038 
00043   enum ParameterFlags
00044   {
00048     ParameterFlag_Read = 0x01,
00052     ParameterFlag_Write = 0x02,
00056     ParameterFlag_Hidden = 0x08,
00060     ParameterFlag_System = 0x10
00061   };
00062 
00066 
00071   class KARTO_EXPORT ParameterDescription : public Referenced
00072   {
00073   public:
00080     ParameterDescription(const karto::String& rName, const karto::String& rDisplayName = "", const karto::String& rDescription = "");
00081     virtual ~ParameterDescription();
00082 
00083   public:
00088     inline const karto::String& GetName() const
00089     {
00090       return m_Name;
00091     }
00092 
00097     inline const karto::String& GetDisplayName() const
00098     {
00099       return m_DisplayName;
00100     }
00101 
00106     inline const karto::String& GetDescription() const
00107     {
00108       return m_Description;
00109     }
00110 
00115     inline kt_int32s GetFlags() const
00116     {
00117       return m_Flags;
00118     }
00119 
00124     inline void SetFlags(kt_int32s flags)
00125     {
00126       m_Flags = flags;
00127     }
00128 
00134     const karto::String& GetFieldName(kt_int32u index) const
00135     {
00136       if (index >= 4)
00137       {
00138         assert(index < 4);
00139         throw karto::Exception("ParameterDescription::GetFieldName() - Invalid argument, index must be [0;3]");
00140       }
00141 
00142       return m_FieldNames[index]; 
00143     }
00144 
00152     void SetFieldNames(const karto::String& rX = "X", const karto::String& rY = "Y", const karto::String& rZ = "Z", const karto::String& rW = "W") 
00153     { 
00154       m_FieldNames[0] = rX; 
00155       m_FieldNames[1] = rY; 
00156       m_FieldNames[2] = rZ; 
00157       m_FieldNames[3] = rW; 
00158     }
00159 
00164     kt_int32s GetNumberOfDecimalPlaces() const
00165     {
00166       return m_nDecimalPlaces;
00167     }
00168 
00173     void SetNumberOfDecimalPlaces(kt_int32s decimalPlaces)
00174     {
00175       m_nDecimalPlaces = decimalPlaces;
00176     }
00177 
00178   private:
00182     karto::String m_Name;
00183     
00187     karto::String m_DisplayName;
00188 
00192     karto::String m_Description;
00193 
00198     karto::String m_FieldNames[4];
00199 
00203     kt_int32s m_Flags;
00204 
00208     kt_int32s m_nDecimalPlaces;
00209   };
00210 
00214 
00215   class ParameterSet;
00216 
00220   class KARTO_EXPORT AbstractParameter : public Referenced
00221   {
00222     KARTO_RTTI();
00223 
00224   public:
00230     AbstractParameter(ParameterDescription* pDescription, ParameterSet* pParameterSet = NULL);
00231 
00232   protected:
00233     //@cond EXCLUDE
00237     virtual ~AbstractParameter();
00238     //@endcond
00239 
00240   public:
00244     BasicEvent<EventArguments> Changed;
00245 
00246   public:
00251     inline const karto::String& GetName() const
00252     {
00253       return m_pDescription->GetName();
00254     }
00255 
00260     inline const karto::String& GetDisplayName() const
00261     {
00262       return m_pDescription->GetDisplayName();
00263     }
00264 
00269     inline const karto::String& GetDescription() const
00270     {
00271       return m_pDescription->GetDescription();
00272     }
00273 
00278     inline kt_int32s GetFlags() const
00279     {
00280       return m_pDescription->GetFlags();
00281     }
00282 
00287     inline const ParameterDescription* GetParameterDescription() const 
00288     {
00289       return m_pDescription;
00290     }
00291 
00296     inline ParameterDescription* GetParameterDescription() 
00297     {
00298       return m_pDescription;
00299     }
00300 
00305     virtual const karto::String GetValueAsString() const = 0;
00306 
00311     virtual void SetValueFromString(const karto::String& rStringValue) = 0;
00312 
00316     virtual void SetToDefaultValue() = 0;
00317 
00318   protected:
00322     virtual void InitializeParameters();
00323 
00324   private:
00325     // restrict the following functions
00326     AbstractParameter(const AbstractParameter&);
00327     const AbstractParameter& operator=(const AbstractParameter&);
00328 
00329   private:
00330     karto::SmartPointer<ParameterDescription> m_pDescription;
00331     ParameterSet* m_pParameterSet;
00332   };
00333 
00337   KARTO_TYPE(AbstractParameter);
00338 
00342   typedef List<SmartPointer<AbstractParameter> > ParameterList;
00343 
00347 
00348   struct ParameterSetPrivate;
00349 
00353   class KARTO_EXPORT ParameterSet : public Referenced
00354   {
00355   public:
00359     ParameterSet();
00360 
00361   protected:
00362     //@cond EXCLUDE
00366     virtual ~ParameterSet();
00367     //@endcond
00368 
00369   public:
00375     void AddParameter(AbstractParameter* pParameter);
00376 
00381     void RemoveParameter(AbstractParameter* pParameter);
00382 
00388     AbstractParameter* GetParameter(const karto::String& rParameterName) const;
00389 
00395     AbstractParameter* GetParameter(const karto::String& rParameterName);
00396 
00400     void Clear();
00401 
00406     const ParameterList& GetParameters() const;
00407 
00412     ParameterList& GetParameters();
00413 
00414   private:
00415     // restrict the following functions
00416     ParameterSet(const ParameterSet&);
00417     const ParameterSet& operator=(const ParameterSet&);
00418 
00419   private:
00420     ParameterSetPrivate* m_pPrivate;
00421   }; // class ParameterSet
00422 
00426   typedef SmartPointer<ParameterSet> ParameterSetPtr;
00427 
00431 
00435   template<typename T>
00436   class Parameter : public AbstractParameter
00437   {
00438     KARTO_RTTI();
00439 
00440   public:
00446     Parameter(ParameterDescription* pDescription, const T& rValue)
00447       : AbstractParameter(pDescription)
00448       , m_Value(rValue)
00449     {
00450       InitializeParameters();
00451     }
00452 
00461     Parameter(ParameterSet* pParameterSet, const karto::String& rName, const karto::String& rDisplayName, const karto::String& rDescription, const T& rValue)
00462       : AbstractParameter(new ParameterDescription(rName, rDisplayName, rDescription), pParameterSet)
00463       , m_Value(rValue)
00464     {
00465       InitializeParameters();
00466     }
00467 
00468   protected:
00469     //@cond EXCLUDE
00473     virtual ~Parameter()
00474     {
00475     }
00476     //@endcond
00477 
00478   public:
00483     virtual const T& GetValue() const
00484     {
00485       return m_Value;
00486     }
00487 
00492     virtual void SetValue(const T& rValue)
00493     {
00494       kt_bool changed = !CompareValue(rValue);
00495 
00496       if (changed)
00497       {
00498         m_Value = rValue;
00499 
00500         Changed.Notify(this, EventArguments::Empty());
00501       }
00502     }
00503 
00508     virtual T& GetDefaultValue()
00509     {
00510       return m_DefaultValue;
00511     }
00512 
00517     virtual void SetDefaultValue(const T& rValue)
00518     {
00519       m_DefaultValue = rValue;
00520     }
00521 
00526     virtual const karto::String GetValueAsString() const
00527     {
00528       return karto::StringHelper::ToString(m_Value);
00529     }
00530 
00535     virtual void SetValueFromString(const karto::String& rStringValue)
00536     {
00537       T value;
00538       if (karto::StringHelper::FromString(rStringValue, value))
00539       {
00540         SetValue(value);
00541       }
00542     }
00543 
00547     virtual void SetToDefaultValue()
00548     {
00549       SetValue(m_DefaultValue);
00550     }
00551 
00552   protected:
00556     virtual void InitializeParameters()
00557     {
00558       SetDefaultValue(GetValue());
00559     }
00560 
00566     kt_bool CompareValue(const T& rValue)
00567     {
00568       return m_Value == rValue;
00569     }
00570 
00571   private:
00572     // restrict the following functions
00573     Parameter(const Parameter&);
00574     const Parameter& operator=(const Parameter&);
00575 
00576   protected:
00580     T m_Value;
00581 
00582   private:
00586     T m_DefaultValue;
00587   };
00588 
00592   KARTO_TYPE(Parameter<kt_bool>);
00593 
00597   KARTO_TYPE(Parameter<kt_char>);
00598 
00602   KARTO_TYPE(Parameter<kt_int8s>);
00603 
00607   KARTO_TYPE(Parameter<kt_int8u>);
00608 
00612   KARTO_TYPE(Parameter<kt_int16s>);
00613 
00617   KARTO_TYPE(Parameter<kt_int16u>);
00618 
00622   KARTO_TYPE(Parameter<kt_int32s>);
00623 
00627   KARTO_TYPE(Parameter<kt_int32u>);
00628 
00632   KARTO_TYPE(Parameter<kt_int64s>);
00633 
00637   KARTO_TYPE(Parameter<kt_int64u>);
00638 
00642   KARTO_TYPE(Parameter<kt_float>);
00643 
00647   KARTO_TYPE(Parameter<kt_double>);
00648 
00652   KARTO_TYPE(Parameter<karto::String>);
00653 
00657   KARTO_TYPE(Parameter<karto::Size2<kt_int32s> >);
00658 
00662   KARTO_TYPE(Parameter<karto::Size2<kt_int32u> >);
00663 
00667   KARTO_TYPE(Parameter<karto::Size2<kt_double> >);
00668 
00672   KARTO_TYPE(Parameter<karto::Vector2i>);
00673 
00677   KARTO_TYPE(Parameter<karto::Vector3i>);
00678 
00682   KARTO_TYPE(Parameter<karto::Vector4i>);
00683 
00687   KARTO_TYPE(Parameter<karto::Vector2<kt_int32u> >);
00688 
00692   KARTO_TYPE(Parameter<karto::Vector3iu>);
00693 
00697   KARTO_TYPE(Parameter<karto::Vector4iu>);
00698 
00702   KARTO_TYPE(Parameter<karto::Vector2<kt_double> >);
00703 
00707   KARTO_TYPE(Parameter<karto::Vector3d>);
00708 
00712   KARTO_TYPE(Parameter<karto::Vector4d>);
00713 
00717   KARTO_TYPE(Parameter<karto::Quaternion>);
00718 
00722   KARTO_TYPE(Parameter<karto::Color>);
00723 
00727   KARTO_TYPE(Parameter<karto::Pose2>);
00728 
00732   KARTO_TYPE(Parameter<karto::Pose3>);
00733 
00737   KARTO_TYPE(Parameter<karto::gps::PointGps>);
00738 
00742 
00743   struct ParameterEnumPrivate;
00744 
00748   class KARTO_EXPORT ParameterEnum : public Parameter<kt_int64s>
00749   {
00750     KARTO_RTTI();
00751 
00752   public:
00761     ParameterEnum(ParameterSet* pParameterSet, const karto::String& rName, const karto::String& rDisplayName, const karto::String& rDescription, kt_int64s value);
00762 
00763   protected:
00764     //@cond EXCLUDE
00768     virtual ~ParameterEnum();
00769     //@endcond
00770 
00771   public:
00777     virtual const karto::String GetValueAsString() const;
00778 
00784     virtual void SetValueFromString(const karto::String& rStringValue);
00785 
00786   public:
00792     void DefineEnumValue(const String& rName, kt_int64s value);
00793 
00798     const EnumPairList GetEnumValues() const;
00799 
00800   private:
00801     ParameterEnumPrivate* m_pPrivate;
00802   }; // class ParameterEnum
00803 
00807   KARTO_TYPE(ParameterEnum);
00808 
00810 }
00811 
00812 #endif // __OpenKarto_Parameter_h__


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Sun Apr 2 2017 03:53:08