0

Hi all. I wanted to run this class by some experienced programmers to see if I have any obvious errors and to get any advice otherwise.

I created a test suite and everything seems to function properly so I'm interested in feedback on overall class design, choice of data types, const correctness, not-so-obvious gotcha!s, etc. Thanks!

```
#ifndef _UTILITY_NAMEVALUEPAIR_H_
#define _UTILITY_NAMEVALUEPAIR_H_
#include <sstream>
using std::ostringstream;
#include <string>
using std::string;
namespace Utility
{
template<typename T>
class NameValuePair
{
public:
static const float Version;
NameValuePair(const string&, const T&);
NameValuePair(const NameValuePair<T>&);
virtual ~NameValuePair();
virtual const NameValuePair<T>& operator =(const NameValuePair<T>&);
virtual bool operator ==(const NameValuePair<T>&) const;
virtual bool operator !=(const NameValuePair<T>&) const;
virtual const string& getName() const;
virtual void setName(const string&);
virtual const T& getValue() const;
virtual void setValue(const T&);
virtual const string ToString() const;
private:
string _name;
T _value;
NameValuePair(){};
};
// Version
template <typename T>
const float NameValuePair<T>::Version = 0.1f;
// Life Cycle
template <typename T>
NameValuePair<T>::NameValuePair(const string& name, const T& value)
{
_name = name;
_value = value;
}
template <typename T>
NameValuePair<T>::NameValuePair(const NameValuePair<T>& pair)
{
_name = pair._name;
_value = pair._value;
}
template <typename T>
NameValuePair<T>::~NameValuePair()
{
}
// Operators
template <typename T>
const NameValuePair<T>& NameValuePair<T>::operator =(const NameValuePair<T>& rhs)
{
if (rhs != *this)
{
_name = rhs._name;
_value = rhs._value;
}
return *this;
}
template <typename T>
bool NameValuePair<T>::operator ==(const NameValuePair<T>& rhs) const
{
return ((_name == rhs._name) && (_value == rhs._value));
}
template <typename T>
bool NameValuePair<T>::operator !=(const NameValuePair<T>& rhs) const
{
return !(*this == rhs);
}
// Properties (getter/setters)
// Name
template <typename T>
const string& NameValuePair<T>::getName() const
{
return _name;
}
template <typename T>
void NameValuePair<T>::setName(const string& name)
{
_name = name;
}
// Value
template <typename T>
const T& NameValuePair<T>::getValue() const
{
return _value;
}
template <typename T>
void NameValuePair<T>::setValue(const T& value)
{
_value = value;
}
// Public Methods
template <typename T>
const string NameValuePair<T>::ToString() const
{
ostringstream stringBuilder;
stringBuilder << _name << "=" << _value;
string returnString = stringBuilder.str();
return returnString;
}
}
#endif
```