Files
IfcOpenShell/src/serializers/util.h
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
2.8 KiB
C++
Raw Normal View History

/********************************************************************************
* *
* This file is part of IfcOpenShell. *
* *
* IfcOpenShell is free software: you can redistribute it and/or modify *
* it under the terms of the Lesser GNU General Public License as published by *
* the Free Software Foundation, either version 3.0 of the License, or *
* (at your option) any later version. *
* *
* IfcOpenShell is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* Lesser GNU General Public License for more details. *
* *
* You should have received a copy of the Lesser GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
#ifndef IFCCONVERT_UTIL_H
#define IFCCONVERT_UTIL_H
#include <sstream>
#include <vector>
#include <iomanip>
2025-06-11 10:39:02 +02:00
#include <limits>
2016-01-25 14:42:41 +01:00
#include <boost/shared_ptr.hpp>
namespace util {
class string_buffer {
public:
class item {
public:
virtual std::string str() const = 0;
2016-08-08 10:41:51 +02:00
virtual ~item() {};
};
class string_item : public item {
std::string s;
public:
string_item(const std::string& s) : s(s) {}
void assign(const std::string& s) { this->s = s; }
const std::string& value() const { return s; }
std::string& value() { return s; }
std::string str() const { return s; }
2016-08-08 10:41:51 +02:00
virtual ~string_item() {};
};
class float_item : public item {
double d;
public:
float_item(const double& d) : d(d) {}
void assign(const double& d) { this->d = d; }
const double& value() const { return d; }
double& value() { return d; }
std::string str() const { std::stringstream ss; ss << std::setprecision(std::numeric_limits<double>::max_digits10) << d; return ss.str(); }
2016-08-08 10:41:51 +02:00
virtual ~float_item() {};
};
private:
2016-01-25 14:42:41 +01:00
std::vector< boost::shared_ptr<item> > items;
void clear();
2016-01-25 14:42:41 +01:00
void assign(const std::vector< boost::shared_ptr<item> >& other);
public:
2016-01-25 14:42:41 +01:00
boost::shared_ptr<string_item> add(const std::string& s);
boost::shared_ptr<float_item> add(const double& d);
bool empty() const { return items.empty(); }
std::string str() const;
};
}
#endif