From 487d17f973fae24aa3b15fdf06a792634ecab2e2 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Tue, 27 Sep 2016 15:37:41 +0200 Subject: [PATCH] Add methods to get property values as strings --- .../include/CGAL/Surface_mesh/Properties.h | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h index a1553da9cf9..9d6f8d2498d 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h @@ -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 + 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 parrays_; size_t size_;