00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Name_Value_Pair.h 00006 * 00007 * Name_Value_Pair.h,v 1.5 2006/03/14 06:14:34 jtc Exp 00008 * 00009 * @author Jonathan Pollack <pollack_j@ociweb.com> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef NAME_VALUE_PAIR_H 00014 #define NAME_VALUE_PAIR_H 00015 #include /**/ "ace/pre.h" 00016 00017 #include "orbsvcs/Notify/Property.h" 00018 #include "orbsvcs/Notify/Property_Boolean.h" 00019 #include "orbsvcs/Notify/notify_serv_export.h" 00020 00021 #include "ace/SString.h" 00022 #include "ace/Vector_T.h" 00023 00024 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00025 #pragma once 00026 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00027 00028 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00029 00030 namespace TAO_Notify 00031 { 00032 /** 00033 * \brief Name/Value Pair 00034 * 00035 * Associates a name (character string) with a value (encoded into a character string) 00036 * For use in managing properties. 00037 */ 00038 class TAO_Notify_Serv_Export NVP { 00039 public: 00040 /// Construct an undefined name/value (to allow use in collections) 00041 NVP(); 00042 /// Construct from a property containing a short value. 00043 explicit NVP(const TAO_Notify_Property_Short& p); 00044 /// Construct from a property containing a long value. 00045 explicit NVP(const TAO_Notify_Property_Long& p); 00046 /// Construct from a property containing a time value 00047 explicit NVP(const TAO_Notify_Property_Time& p); 00048 /// Construct from a property containing a boolean value 00049 explicit NVP(const TAO_Notify_Property_Boolean& p); 00050 00051 /// Construct from name and long value. 00052 NVP(const char * n, CORBA::Long v); 00053 /// Construct from name and string value. 00054 NVP(const char * n, const char * v); 00055 /// Construct from name and string value. 00056 NVP(const char * n, const ACE_CString & v); 00057 00058 /// Assignment operator 00059 bool operator==(const NVP& rhs) const; 00060 /// Comparison operator compares only name (not value) 00061 bool operator!=(const NVP& rhs) const; 00062 ACE_CString name; 00063 ACE_CString value; 00064 }; 00065 00066 /** 00067 * \brief Collection of Name/Value Pairs 00068 */ 00069 class TAO_Notify_Serv_Export NVPList { 00070 public: 00071 /// Find the NVP with the same name as the property, copy the value. 00072 void load(TAO_Notify_Property_Short& p) const; 00073 /// Find the NVP with the same name as the property, copy the value. 00074 void load(TAO_Notify_Property_Long& p) const; 00075 /// Find the NVP with the same name as the property, copy the value. 00076 void load(TAO_Notify_Property_Time& p) const; 00077 /// Find the NVP with the same name as the property, copy the value. 00078 void load(TAO_Notify_Property_Boolean& p) const; 00079 /// Find the NVP with specified name, copy the value to a string. 00080 bool load(const char * n, CORBA::Long& v) const; 00081 /// Find the NVP with specified name, copy the value to a long. 00082 bool load(const char * n, ACE_CString& v) const; 00083 /// add a new name/value pair. 00084 void push_back(const NVP& v); 00085 /// size of the collection. 00086 size_t size() const; 00087 /// access NVP via numeric index. 00088 const NVP& operator[](size_t ndx) const; 00089 /// low level access: find 00090 bool find (const char * name, ACE_CString& val) const; 00091 /// low level access: use this when you don't need a CString 00092 bool find (const char * name, const char *& val) const; 00093 00094 private: 00095 ACE_Vector<NVP> list_; 00096 }; 00097 } // namespace TAO_Notify 00098 00099 TAO_END_VERSIONED_NAMESPACE_DECL 00100 00101 #include /**/ "ace/post.h" 00102 #endif /* NAME_VALUE_PAIR_H */