mirror of https://github.com/CGAL/cgal
Add methods to get property values as strings
This commit is contained in:
parent
f88dc153cb
commit
487d17f973
|
|
@ -69,10 +69,12 @@ public:
|
||||||
/// Return the type_info of the property
|
/// Return the type_info of the property
|
||||||
virtual const std::type_info& type() = 0;
|
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
|
/// Return the name of the property
|
||||||
const std::string& name() const { return name_; }
|
const std::string& name() const { return name_; }
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std::string name_;
|
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::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:
|
public:
|
||||||
|
|
||||||
/// Get pointer to array (does not work for T==bool)
|
/// Get pointer to array (does not work for T==bool)
|
||||||
|
|
@ -379,7 +409,15 @@ public:
|
||||||
parrays_[i]->swap(i0, i1);
|
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:
|
private:
|
||||||
std::vector<Base_property_array*> parrays_;
|
std::vector<Base_property_array*> parrays_;
|
||||||
size_t size_;
|
size_t size_;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue