Add methods to get property values as strings

This commit is contained in:
Simon Giraudot 2016-09-27 15:37:41 +02:00
parent f88dc153cb
commit 487d17f973
1 changed files with 40 additions and 2 deletions

View File

@ -69,10 +69,12 @@ public:
/// Return the type_info of the property
virtual const std::type_info& type() = 0;
/// Get element as a string
virtual const std::string to_str(size_t i) const = 0;
/// Return the name of the property
const std::string& name() const { return name_; }
protected:
std::string name_;
@ -147,7 +149,35 @@ public: // virtual interface of Base_property_array
virtual const std::type_info& type() { return typeid(T); }
virtual const std::string to_str(size_t i) const
{
std::string out;
// Work-around to display char and uchar as integer numbers and not characters
get_string (out, data_[i]);
return out;
}
template <typename Type>
void get_string (std::string& out, const Type& t) const
{
std::ostringstream oss;
oss << t;
out = oss.str();
}
void get_string (std::string& out, const char& t) const
{
std::ostringstream oss;
oss << (int)t;
out = oss.str();
}
void get_string (std::string& out, const unsigned char& t) const
{
std::ostringstream oss;
oss << (int)t;
out = oss.str();
}
public:
/// Get pointer to array (does not work for T==bool)
@ -379,7 +409,15 @@ public:
parrays_[i]->swap(i0, i1);
}
std::string to_str (const Key& key) const
{
std::ostringstream oss;
for (std::size_t i = 0; i < parrays_.size(); ++ i)
oss << parrays_[i]->to_str((std::size_t)key) << " ";
oss << std::endl;
return oss.str();
}
private:
std::vector<Base_property_array*> parrays_;
size_t size_;