ifcparse: fix clang-tidy warning readability-identifier-length

This commit is contained in:
Dirk Olbrich
2023-11-06 20:29:00 +01:00
committed by Thomas Krijnen
parent eea9a14722
commit 47a2971c65
25 changed files with 651 additions and 625 deletions
+2 -2
View File
@@ -38,7 +38,7 @@ class IfcBaseClass;
IFC_PARSE_API const char* ArgumentTypeToString(ArgumentType argument_type);
/// Returns false when the string `s` contains character outside of {'0', '1'}
IFC_PARSE_API bool valid_binary_string(const std::string& s);
IFC_PARSE_API bool valid_binary_string(const std::string& string);
} // namespace IfcUtil
class IFC_PARSE_API Argument {
@@ -65,7 +65,7 @@ class IFC_PARSE_API Argument {
virtual unsigned int size() const = 0;
virtual IfcUtil::ArgumentType type() const = 0;
virtual Argument* operator[](unsigned int i) const = 0;
virtual Argument* operator[](unsigned int index) const = 0;
virtual std::string toString(bool upper = false) const = 0;
virtual ~Argument(){};
+12 -12
View File
@@ -61,11 +61,11 @@ class IFC_PARSE_API IfcBaseInterface {
if (is_null(this)) {
return static_cast<T*>(0);
}
auto t = dynamic_cast<T*>(this);
if (do_throw && !t) {
auto type = dynamic_cast<T*>(this);
if (do_throw && !type) {
raise_error_on_concrete_class<T>();
}
return t;
return type;
}
template <class T>
@@ -73,11 +73,11 @@ class IFC_PARSE_API IfcBaseInterface {
if (is_null(this)) {
return static_cast<const T*>(0);
}
auto t = dynamic_cast<const T*>(this);
if (do_throw && !t) {
auto type = dynamic_cast<const T*>(this);
if (do_throw && !type) {
raise_error_on_concrete_class<T>();
}
return t;
return type;
}
};
@@ -96,13 +96,13 @@ class IFC_PARSE_API IfcBaseClass : public virtual IfcBaseInterface {
public:
IfcBaseClass() : identity_(counter_++),
data_(0) {}
IfcBaseClass(IfcEntityInstanceData* d) : identity_(counter_++),
data_(d) {}
IfcBaseClass(IfcEntityInstanceData* data) : identity_(counter_++),
data_(data) {}
virtual ~IfcBaseClass() { delete data_; }
const IfcEntityInstanceData& data() const { return *data_; }
IfcEntityInstanceData& data() { return *data_; }
void data(IfcEntityInstanceData* d);
void data(IfcEntityInstanceData* data);
virtual const IfcParse::declaration& declaration() const = 0;
@@ -125,7 +125,7 @@ class IFC_PARSE_API IfcLateBoundEntity : public IfcBaseClass {
class IFC_PARSE_API IfcBaseEntity : public IfcBaseClass {
public:
IfcBaseEntity() : IfcBaseClass() {}
IfcBaseEntity(IfcEntityInstanceData* d) : IfcBaseClass(d) {}
IfcBaseEntity(IfcEntityInstanceData* data) : IfcBaseClass(data) {}
virtual const IfcParse::entity& declaration() const = 0;
@@ -137,14 +137,14 @@ class IFC_PARSE_API IfcBaseEntity : public IfcBaseClass {
template <typename T>
T get_value(const std::string& name, const T& default_value) const;
boost::shared_ptr<aggregate_of_instance> get_inverse(const std::string& a) const;
boost::shared_ptr<aggregate_of_instance> get_inverse(const std::string& name) const;
};
// TODO: Investigate whether these should be template classes instead
class IFC_PARSE_API IfcBaseType : public IfcBaseClass {
public:
IfcBaseType() : IfcBaseClass() {}
IfcBaseType(IfcEntityInstanceData* d) : IfcBaseClass(d) {}
IfcBaseType(IfcEntityInstanceData* data) : IfcBaseClass(data) {}
virtual const IfcParse::declaration& declaration() const = 0;
};
+38 -36
View File
@@ -71,8 +71,8 @@
using namespace IfcParse;
using namespace IfcWrite;
IfcCharacterDecoder::IfcCharacterDecoder(IfcParse::IfcSpfStream* f) {
stream_ = f;
IfcCharacterDecoder::IfcCharacterDecoder(IfcParse::IfcSpfStream* stream) {
stream_ = stream;
codepage_ = 0;
}
@@ -205,35 +205,35 @@ class pure_impure_helper {
static std::string empty;
return empty;
}
auto it = std::max_element(builder_.begin(), builder_.end());
if (*it <= 0x7e) {
std::string r(builder_.begin(), builder_.end());
return r;
auto iter = std::max_element(builder_.begin(), builder_.end());
if (*iter <= 0x7e) {
std::string result(builder_.begin(), builder_.end());
return result;
}
return IfcUtil::convert_utf8(builder_);
}
if (mode == IfcParse::IfcCharacterDecoder::SUBSTITUTE) {
std::string r;
r.reserve(builder_.size());
std::transform(builder_.begin(), builder_.end(), std::back_inserter(r), [&substitution_character](wchar_t c) {
if (c >= 0x20 && c <= 0x7e) {
return (char)c;
std::string result;
result.reserve(builder_.size());
std::transform(builder_.begin(), builder_.end(), std::back_inserter(result), [&substitution_character](wchar_t character) {
if (character >= 0x20 && character <= 0x7e) {
return (char)character;
}
return substitution_character;
});
return r;
return result;
}
if (mode == IfcParse::IfcCharacterDecoder::ESCAPE) {
std::stringstream str;
str << std::hex << std::setw(4) << std::setfill('0');
std::for_each(builder_.begin(), builder_.end(), [&str](wchar_t c) {
if (c >= 0x20 && c <= 0x7e) {
str.put((char)c);
std::stringstream stream;
stream << std::hex << std::setw(4) << std::setfill('0');
std::for_each(builder_.begin(), builder_.end(), [&stream](wchar_t character) {
if (character >= 0x20 && character <= 0x7e) {
stream.put((char)character);
} else {
str << "\\u" << c;
stream << "\\u" << character;
}
});
return str.str();
return stream.str();
}
throw IfcParse::IfcException("Invalid conversion mode");
}
@@ -334,20 +334,20 @@ IfcCharacterEncoder::operator std::string() {
bool in_extended = false;
for (auto it = str_.begin(); it != str_.end(); ++it) {
auto ch = *it;
const bool within_spf_range = ch >= 0x20 && ch <= 0x7e;
auto character = *it;
const bool within_spf_range = character >= 0x20 && character <= 0x7e;
if (in_extended && within_spf_range) {
oss << "\\X0\\";
} else if (!in_extended && !within_spf_range) {
oss << "\\X" << num_bytes_str << "\\";
}
if (within_spf_range) {
oss.put((char)ch);
if (ch == '\\' || ch == '\'') {
oss.put((char)ch);
oss.put((char)character);
if (character == '\\' || character == '\'') {
oss.put((char)character);
}
} else {
oss << std::hex << std::setw(num_bytes * 2) << std::uppercase << std::setfill('0') << (int)ch;
oss << std::hex << std::setw(num_bytes * 2) << std::uppercase << std::setfill('0') << (int)character;
}
in_extended = !within_spf_range;
}
@@ -374,13 +374,14 @@ def _():
"{%s}" % ",".join(_())
*/
std::wstring::value_type IfcUtil::convert_codepage(int codepage, int c) {
std::wstring::value_type IfcUtil::convert_codepage(int codepage, int character) {
if (codepage < 1 || codepage > 16 || codepage == 12) {
throw IfcParse::IfcException("Invalid codepage");
}
if (c < 0 || c > 255) {
if (character < 0 || character > 255) {
throw IfcParse::IfcException("Invalid character ordinal");
}
// NOLINTBEGIN(readability-magic-numbers)
static std::array<std::array<wchar_t, 256>, 16> codepage_data = {{{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}},
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 260, 728, 321, 164, 317, 346, 167, 168, 352, 350, 356, 377, 173, 381, 379, 176, 261, 731, 322, 180, 318, 347, 711, 184, 353, 351, 357, 378, 733, 382, 380, 340, 193, 194, 258, 196, 313, 262, 199, 268, 201, 280, 203, 282, 205, 206, 270, 272, 323, 327, 211, 212, 336, 214, 215, 344, 366, 218, 368, 220, 221, 354, 223, 341, 225, 226, 259, 228, 314, 263, 231, 269, 233, 281, 235, 283, 237, 238, 271, 273, 324, 328, 243, 244, 337, 246, 247, 345, 367, 250, 369, 252, 253, 355, 729}},
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 294, 728, 163, 164, 0, 292, 167, 168, 304, 350, 286, 308, 173, 0, 379, 176, 295, 178, 179, 180, 181, 293, 183, 184, 305, 351, 287, 309, 189, 0, 380, 192, 193, 194, 0, 196, 266, 264, 199, 200, 201, 202, 203, 204, 205, 206, 207, 0, 209, 210, 211, 212, 288, 214, 215, 284, 217, 218, 219, 220, 364, 348, 223, 224, 225, 226, 0, 228, 267, 265, 231, 232, 233, 234, 235, 236, 237, 238, 239, 0, 241, 242, 243, 244, 289, 246, 247, 285, 249, 250, 251, 252, 365, 349, 729}},
@@ -397,19 +398,20 @@ std::wstring::value_type IfcUtil::convert_codepage(int codepage, int c) {
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 7682, 7683, 163, 266, 267, 7690, 167, 7808, 169, 7810, 7691, 7922, 173, 174, 376, 7710, 7711, 288, 289, 7744, 7745, 182, 7766, 7809, 7767, 7811, 7776, 7923, 7812, 7813, 7777, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 372, 209, 210, 211, 212, 213, 214, 7786, 216, 217, 218, 219, 220, 221, 374, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 373, 241, 242, 243, 244, 245, 246, 7787, 248, 249, 250, 251, 252, 253, 375, 255}},
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 8364, 165, 352, 167, 353, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 381, 181, 182, 183, 382, 185, 186, 187, 338, 339, 376, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}},
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 260, 261, 321, 8364, 8222, 352, 167, 353, 169, 536, 171, 377, 173, 378, 379, 176, 177, 268, 322, 381, 8221, 182, 183, 382, 269, 537, 187, 338, 339, 376, 380, 192, 193, 194, 258, 196, 262, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 272, 323, 210, 211, 212, 336, 214, 346, 368, 217, 218, 219, 220, 280, 538, 223, 224, 225, 226, 259, 228, 263, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 273, 324, 242, 243, 244, 337, 246, 347, 369, 249, 250, 251, 252, 281, 539, 255}}}};
auto r = codepage_data[codepage - 1][c];
if (r == 0) {
// NOLINTEND(readability-magic-numbers)
auto result = codepage_data[codepage - 1][character];
if (result == 0) {
throw IfcParse::IfcException("Character not defined");
}
return r;
return result;
}
std::string IfcUtil::convert_utf8(const std::wstring& s) {
return std::wstring_convert<std::codecvt_utf8<std::wstring::value_type>>().to_bytes(s);
std::string IfcUtil::convert_utf8(const std::wstring& string) {
return std::wstring_convert<std::codecvt_utf8<std::wstring::value_type>>().to_bytes(string);
}
std::wstring IfcUtil::convert_utf8(const std::string& s) {
return std::wstring_convert<std::codecvt_utf8<std::wstring::value_type>>().from_bytes(s);
std::wstring IfcUtil::convert_utf8(const std::string& string) {
return std::wstring_convert<std::codecvt_utf8<std::wstring::value_type>>().from_bytes(string);
}
#ifdef _MSC_VER
@@ -423,8 +425,8 @@ std::u32string IfcUtil::convert_utf8_to_utf32(const std::string& s) {
#else
std::u32string IfcUtil::convert_utf8_to_utf32(const std::string& s) {
return std::wstring_convert<std::codecvt_utf8<std::u32string::value_type>, std::u32string::value_type>().from_bytes(s);
std::u32string IfcUtil::convert_utf8_to_utf32(const std::string& string) {
return std::wstring_convert<std::codecvt_utf8<std::u32string::value_type>, std::u32string::value_type>().from_bytes(string);
}
#endif
+5 -5
View File
@@ -32,10 +32,10 @@
#include <string>
namespace IfcUtil {
std::wstring::value_type convert_codepage(int codepage, int c);
std::string convert_utf8(const std::wstring& s);
std::wstring convert_utf8(const std::string& s);
std::u32string convert_utf8_to_utf32(const std::string& s);
std::wstring::value_type convert_codepage(int codepage, int index);
std::string convert_utf8(const std::wstring& string);
std::wstring convert_utf8(const std::string& string);
std::u32string convert_utf8_to_utf32(const std::string& string);
} // namespace IfcUtil
namespace IfcParse {
@@ -53,7 +53,7 @@ class IFC_PARSE_API IfcCharacterDecoder {
};
static ConversionMode mode;
static char substitution_character;
IfcCharacterDecoder(IfcParse::IfcSpfStream* file);
IfcCharacterDecoder(IfcParse::IfcSpfStream* stream);
~IfcCharacterDecoder();
// Only advances the underlying token stream read pointer
// to the next token.
+6 -6
View File
@@ -44,10 +44,10 @@ class IFC_PARSE_API IfcEntityInstanceData {
public:
IfcEntityInstanceData(const IfcParse::declaration* type,
IfcParse::IfcFile* file_,
IfcParse::IfcFile* file,
unsigned id = 0,
unsigned offset_in_file = 0)
: file(file_),
: file(file),
id_(id),
type_(type),
attributes_(0),
@@ -69,16 +69,16 @@ class IFC_PARSE_API IfcEntityInstanceData {
void load() const;
IfcEntityInstanceData(const IfcEntityInstanceData& e);
IfcEntityInstanceData(const IfcEntityInstanceData& data);
virtual ~IfcEntityInstanceData();
boost::shared_ptr<aggregate_of_instance> getInverse(const IfcParse::declaration* type, int attribute_index) const;
Argument* getArgument(size_t i) const;
Argument* getArgument(size_t index) const;
// NB: This makes a copy of the argument if make_copy is set
void setArgument(size_t i, Argument* a, IfcUtil::ArgumentType attr_type = IfcUtil::Argument_UNKNOWN, bool make_copy = false);
void setArgument(size_t ibdex, Argument* argument, IfcUtil::ArgumentType attr_type = IfcUtil::Argument_UNKNOWN, bool make_copy = false);
virtual size_t getArgumentCount() const {
if (type_ == 0) {
@@ -104,7 +104,7 @@ class IFC_PARSE_API IfcEntityInstanceData {
// NB: const ommitted for lazy loading
Argument**& attributes() const { return attributes_; }
unsigned set_id(boost::optional<unsigned> i = boost::none);
unsigned set_id(boost::optional<unsigned> id = boost::none);
};
#endif
+6 -6
View File
@@ -39,8 +39,8 @@ class IFC_PARSE_API IfcException : public std::exception {
std::string message_;
public:
IfcException(const std::string& m)
: message_(m) {}
IfcException(const std::string& message)
: message_(message) {}
virtual ~IfcException() throw() {}
virtual const char* what() const throw() {
return message_.c_str();
@@ -49,8 +49,8 @@ class IFC_PARSE_API IfcException : public std::exception {
class IFC_PARSE_API IfcAttributeOutOfRangeException : public IfcException {
public:
IfcAttributeOutOfRangeException(const std::string& e)
: IfcException(e) {}
IfcAttributeOutOfRangeException(const std::string& exception)
: IfcException(exception) {}
~IfcAttributeOutOfRangeException() throw() {}
};
@@ -66,9 +66,9 @@ class IFC_PARSE_API IfcInvalidTokenException : public IfcException {
" invalid " + expected_type) {}
IfcInvalidTokenException(
int token_start,
char c)
char character)
: IfcException(
std::string("Unexpected '") + std::string(1, c) + "' at offset " +
std::string("Unexpected '") + std::string(1, character) + "' at offset " +
boost::lexical_cast<std::string>(token_start)) {}
~IfcInvalidTokenException() throw() {}
};
+11 -11
View File
@@ -87,8 +87,8 @@ class IFC_PARSE_API IfcFile {
public:
type_iterator() : entities_by_type_t::const_iterator(){};
type_iterator(const entities_by_type_t::const_iterator& it)
: entities_by_type_t::const_iterator(it){};
type_iterator(const entities_by_type_t::const_iterator& iter)
: entities_by_type_t::const_iterator(iter){};
entities_by_type_t::key_type const* operator->() const {
return &entities_by_type_t::const_iterator::operator->()->first;
@@ -151,7 +151,7 @@ class IFC_PARSE_API IfcFile {
void setDefaultHeaderValues();
void initialize_(IfcParse::IfcSpfStream* f);
void initialize_(IfcParse::IfcSpfStream* stream);
void build_inverses_(IfcUtil::IfcBaseClass*);
@@ -171,13 +171,13 @@ class IFC_PARSE_API IfcFile {
IfcParse::IfcSpfStream* stream;
#ifdef USE_MMAP
IfcFile(const std::string& fn, bool mmap = false);
IfcFile(const std::string& path, bool mmap = false);
#else
IfcFile(const std::string& fn);
IfcFile(const std::string& path);
#endif
IfcFile(std::istream& fn, int len);
IfcFile(void* data, int len);
IfcFile(IfcParse::IfcSpfStream* f);
IfcFile(std::istream& stream, int length);
IfcFile(void* data, int length);
IfcFile(IfcParse::IfcSpfStream* stream);
IfcFile(const IfcParse::schema_definition* schema = IfcParse::schema_by_name("IFC4"));
/// Deleting the file will also delete all new instances that were added to the file (via memory allocation)
@@ -230,10 +230,10 @@ class IFC_PARSE_API IfcFile {
/// Returns all entities in the file that match the positional argument.
/// NOTE: This also returns subtypes of the requested type, for example:
/// IfcWall will also return IfcWallStandardCase entities
aggregate_of_instance::ptr instances_by_type(const std::string& t);
aggregate_of_instance::ptr instances_by_type(const std::string& type);
/// Returns all entities in the file that match the positional argument.
aggregate_of_instance::ptr instances_by_type_excl_subtypes(const std::string& t);
aggregate_of_instance::ptr instances_by_type_excl_subtypes(const std::string& type);
/// Returns all entities in the file that reference the id
aggregate_of_instance::ptr instances_by_reference(int id);
@@ -275,7 +275,7 @@ class IFC_PARSE_API IfcFile {
void recalculate_id_counter();
IfcUtil::IfcBaseClass* addEntity(IfcUtil::IfcBaseClass* entity, int id = -1);
void addEntities(aggregate_of_instance::ptr es);
void addEntities(aggregate_of_instance::ptr entities);
void batch() { batch_mode_ = true; }
void unbatch() {
+34 -33
View File
@@ -32,46 +32,47 @@
static const char* chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_$";
// Converts an unsigned integer into a base64 string of length l
std::string base64(unsigned v, int l) {
std::string r;
r.reserve(l);
while (v != 0U) {
r.push_back(chars[v % 64]);
v /= 64;
std::string base64(unsigned value, int length) {
const int BASE64 = 64;
std::string result;
result.reserve(length);
while (value != 0U) {
result.push_back(chars[value % BASE64]);
value /= BASE64;
}
while ((int)r.size() != l) {
r.push_back('0');
while ((int)result.size() != length) {
result.push_back('0');
}
std::reverse(r.begin(), r.end());
return r;
std::reverse(result.begin(), result.end());
return result;
}
// Converts a base64 string into an unsigned integer
unsigned from_base64(const std::string& s) {
std::string::size_type zeros = s.find_first_not_of('0');
unsigned r = 0;
unsigned from_base64(const std::string& string) {
std::string::size_type zeros = string.find_first_not_of('0');
unsigned result = 0;
if (zeros != std::string::npos) {
for (std::string::const_iterator i = s.begin() + zeros; i != s.end(); ++i) {
r *= 64;
const char* c = strchr(chars, *i);
if (c == nullptr) {
for (std::string::const_iterator i = string.begin() + zeros; i != string.end(); ++i) {
result *= 64;
const char* character = strchr(chars, *i);
if (character == nullptr) {
throw IfcParse::IfcException("Failed to decode GlobalId");
}
r += (unsigned)(c - chars);
result += (unsigned)(character - chars);
}
}
return r;
return result;
}
// Compresses the UUID byte array into a base64 representation
std::string compress(unsigned char* v) {
std::string r;
r.reserve(22);
r += base64(v[0], 2);
std::string compress(unsigned char* value) {
std::string result;
result.reserve(22);
result += base64(value[0], 2);
for (unsigned i = 1; i < 16; i += 3) {
r += base64((v[i] << 16) + (v[i + 1] << 8) + v[i + 2], 4);
result += base64((value[i] << 16) + (value[i + 1] << 8) + value[i + 2], 4);
}
return r;
return result;
}
// Expands the base64 representation into a UUID byte array
@@ -110,20 +111,20 @@ IfcParse::IfcGlobalId::IfcGlobalId() {
#endif
}
IfcParse::IfcGlobalId::IfcGlobalId(const std::string& s)
: string_data_(s) {
std::vector<unsigned char> v;
expand(string_data_, v);
std::copy(v.begin(), v.end(), uuid_data_.begin());
IfcParse::IfcGlobalId::IfcGlobalId(const std::string& string)
: string_data_(string) {
std::vector<unsigned char> result;
expand(string_data_, result);
std::copy(result.begin(), result.end(), uuid_data_.begin());
#if BOOST_VERSION < 104400
formatted_string = boost::lexical_cast<std::string>(uuid_data);
formatted_string_ = boost::lexical_cast<std::string>(uuid_data_);
#else
formatted_string_ = boost::uuids::to_string(uuid_data_);
#endif
#ifndef NDEBUG
const std::string test_string = compress(&uuid_data.data[0]);
if (string_data != test_string) {
const std::string test_string = compress(&uuid_data_.data[0]);
if (string_data_ != test_string) {
Logger::Message(Logger::LOG_ERROR, "Internal error generating GlobalId");
}
#endif
+7 -7
View File
@@ -63,11 +63,11 @@ typename Schema::IfcLocalPlacement* IfcHierarchyHelper<Schema>::addLocalPlacemen
double xx,
double xy,
double xz) {
typename Schema::IfcLocalPlacement* lp = new typename Schema::IfcLocalPlacement(parent,
addPlacement3d(ox, oy, oz, zx, zy, zz, xx, xy, xz));
typename Schema::IfcLocalPlacement* local_placement = new typename Schema::IfcLocalPlacement(parent,
addPlacement3d(ox, oy, oz, zx, zy, zz, xx, xy, xz));
addEntity(lp);
return lp;
addEntity(local_placement);
return local_placement;
}
template <typename Schema>
@@ -995,9 +995,9 @@ void push_back_to_maybe_optional(boost::optional<boost::shared_ptr<T>>& t, U* u)
template <typename Schema>
typename Schema::IfcGeometricRepresentationContext* IfcHierarchyHelper<Schema>::getRepresentationContext(const std::string& s) {
typename std::map<std::string, typename Schema::IfcGeometricRepresentationContext*>::const_iterator it = contexts_.find(s);
if (it != contexts_.end()) {
return it->second;
typename std::map<std::string, typename Schema::IfcGeometricRepresentationContext*>::const_iterator iter = contexts_.find(s);
if (iter != contexts_.end()) {
return iter->second;
}
typename Schema::IfcProject* project = getSingle<typename Schema::IfcProject>();
if (!project) {
+2 -1
View File
@@ -451,7 +451,8 @@ class IFC_PARSE_API IfcHierarchyHelper : public IfcParse::IfcFile {
attr->set(owner_hist);
data->setArgument(1, attr);
}
int relating_index = 4, related_index = 5;
int relating_index = 4;
int related_index = 5;
if (T::Class().name() == "IfcRelContainedInSpatialStructure") {
// IfcRelContainedInSpatialStructure has attributes reversed.
std::swap(relating_index, related_index);
+38 -38
View File
@@ -42,8 +42,8 @@ std::string get_time(bool with_milliseconds = false) {
if (with_milliseconds) {
auto now_chrono = std::chrono::system_clock::now();
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now_chrono.time_since_epoch()) % 1000;
oss << '.' << std::setfill('0') << std::setw(3) << ms.count();
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now_chrono.time_since_epoch()) % 1000;
oss << '.' << std::setfill('0') << std::setw(3) << milliseconds.count();
}
return oss.str();
@@ -61,33 +61,33 @@ template <>
const std::array<std::basic_string<wchar_t>, 5> severity_strings<wchar_t>::value = {L"Performance", L"Debug", L"Notice", L"Warning", L"Error"};
template <typename T>
void plain_text_message(T& os, const boost::optional<IfcUtil::IfcBaseClass*>& current_product, Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseInterface* instance) {
os << "[" << severity_strings<typename T::char_type>::value[type] << "] ";
os << "[" << get_time(type <= Logger::LOG_PERF).c_str() << "] ";
void plain_text_message(T& out, const boost::optional<IfcUtil::IfcBaseClass*>& current_product, Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseInterface* instance) {
out << "[" << severity_strings<typename T::char_type>::value[type] << "] ";
out << "[" << get_time(type <= Logger::LOG_PERF).c_str() << "] ";
if (current_product) {
std::string global_id = *((IfcUtil::IfcBaseEntity*)*current_product)->get("GlobalId");
os << "{" << global_id.c_str() << "} ";
out << "{" << global_id.c_str() << "} ";
}
os << message.c_str() << std::endl;
out << message.c_str() << std::endl;
if (instance) {
std::string instance_string = instance->data().toString();
if (instance_string.size() > 259) {
instance_string = instance_string.substr(0, 256) + "...";
}
os << instance_string.c_str() << std::endl;
out << instance_string.c_str() << std::endl;
}
}
template <typename T>
std::basic_string<T> string_as(const std::string& s) {
std::basic_string<T> v;
v.assign(s.begin(), s.end());
return v;
std::basic_string<T> string_as(const std::string& string) {
std::basic_string<T> result;
result.assign(string.begin(), string.end());
return result;
}
template <typename T>
void json_message(T& os, const boost::optional<IfcUtil::IfcBaseClass*>& current_product, Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseInterface* instance) {
boost::property_tree::basic_ptree<std::basic_string<typename T::char_type>, std::basic_string<typename T::char_type>> pt;
void json_message(T& out, const boost::optional<IfcUtil::IfcBaseClass*>& current_product, Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseInterface* instance) {
boost::property_tree::basic_ptree<std::basic_string<typename T::char_type>, std::basic_string<typename T::char_type>> property_tree;
// @todo this is crazy
static const typename T::char_type time_string[] = {'t', 'i', 'm', 'e', 0};
@@ -96,18 +96,18 @@ void json_message(T& os, const boost::optional<IfcUtil::IfcBaseClass*>& current_
static const typename T::char_type message_string[] = {'m', 'e', 's', 's', 'a', 'g', 'e', 0};
static const typename T::char_type instance_string[] = {'i', 'n', 's', 't', 'a', 'n', 'c', 'e', 0};
pt.put(level_string, severity_strings<typename T::char_type>::value[type]);
property_tree.put(level_string, severity_strings<typename T::char_type>::value[type]);
if (current_product) {
pt.put(product_string, string_as<typename T::char_type>((**current_product).data().toString()));
property_tree.put(product_string, string_as<typename T::char_type>((**current_product).data().toString()));
}
pt.put(message_string, string_as<typename T::char_type>(message));
property_tree.put(message_string, string_as<typename T::char_type>(message));
if (instance) {
pt.put(instance_string, string_as<typename T::char_type>(instance->data().toString()));
property_tree.put(instance_string, string_as<typename T::char_type>(instance->data().toString()));
}
pt.put(time_string, string_as<typename T::char_type>(get_time()));
property_tree.put(time_string, string_as<typename T::char_type>(get_time()));
boost::property_tree::write_json(os, pt, false);
boost::property_tree::write_json(out, property_tree, false);
}
} // namespace
@@ -122,27 +122,27 @@ void Logger::SetProduct(boost::optional<const IfcUtil::IfcBaseClass*> product) {
current_product_ = product;
}
void Logger::SetOutput(std::ostream* l1, std::ostream* l2) {
void Logger::SetOutput(std::ostream* stream1, std::ostream* stream2) {
wlog1_ = wlog2_ = 0;
log1_ = l1;
log2_ = l2;
log1_ = stream1;
log2_ = stream2;
if (log2_ == nullptr) {
log2_ = &log_stream_;
}
}
void Logger::SetOutput(std::wostream* l1, std::wostream* l2) {
void Logger::SetOutput(std::wostream* stream1, std::wostream* stream2) {
log1_ = log2_ = 0;
wlog1_ = l1;
wlog2_ = l2;
wlog1_ = stream1;
wlog2_ = stream2;
if (wlog2_ == nullptr) {
log2_ = &log_stream_;
}
}
void Logger::Message(Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseInterface* instance) {
static std::mutex m;
std::lock_guard<std::mutex> lk(m);
static std::mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
if (type == LOG_PERF) {
if (!first_timepoint_) {
@@ -209,32 +209,32 @@ std::string Logger::GetLog() {
void Logger::PrintPerformanceStats() {
std::vector<std::pair<double, std::string>> items;
for (auto& p : performance_statistics_) {
items.push_back({p.second, p.first});
for (auto& stat : performance_statistics_) {
items.push_back({stat.second, stat.first});
}
std::sort(items.begin(), items.end());
std::reverse(items.begin(), items.end());
size_t max_size = 0;
for (auto& p : items) {
if (p.second.size() > max_size) {
max_size = p.second.size();
for (auto& item : items) {
if (item.second.size() > max_size) {
max_size = item.second.size();
}
}
for (auto& p : items) {
auto s = p.second + std::string(max_size - p.second.size(), ' ') + ": " + std::to_string(p.first);
Message(LOG_PERF, s);
for (auto& item : items) {
auto message = item.second + std::string(max_size - item.second.size(), ' ') + ": " + std::to_string(item.first);
Message(LOG_PERF, message);
}
}
void Logger::Verbosity(Logger::Severity v) { verbosity_ = v; }
void Logger::Verbosity(Logger::Severity severity) { verbosity_ = severity; }
Logger::Severity Logger::Verbosity() { return verbosity_; }
Logger::Severity Logger::MaxSeverity() { return max_severity_; }
void Logger::OutputFormat(Format f) { format_ = f; }
void Logger::OutputFormat(Format format) { format_ = format; }
Logger::Format Logger::OutputFormat() { return format_; }
std::ostream* Logger::log1_ = 0;
+5 -5
View File
@@ -70,23 +70,23 @@ class IFC_PARSE_API Logger {
static void SetProduct(boost::optional<const IfcUtil::IfcBaseClass*> product);
/// Determines to what stream respectively progress and errors are logged
static void SetOutput(std::wostream* l1, std::wostream* l2);
static void SetOutput(std::wostream* stream1, std::wostream* stream2);
/// Determines to what stream respectively progress and errors are logged
static void SetOutput(std::ostream* l1, std::ostream* l2);
static void SetOutput(std::ostream* stream1, std::ostream* stream2);
/// Determines the types of log messages to get logged
static void Verbosity(Severity v);
static void Verbosity(Severity severity);
static Severity Verbosity();
static Severity MaxSeverity();
/// Determines output format: plain text or sequence of JSON objects
static void OutputFormat(Format f);
static void OutputFormat(Format format);
static Format OutputFormat();
/// Log a message to the output stream
static void Message(Severity type, const std::string& message, const IfcUtil::IfcBaseInterface* instance = 0);
static void Message(Severity type, const std::exception& message, const IfcUtil::IfcBaseInterface* instance = 0);
static void Message(Severity type, const std::exception& exception, const IfcUtil::IfcBaseInterface* instance = 0);
static void Notice(const std::string& message, const IfcUtil::IfcBaseInterface* instance = 0) { Message(LOG_NOTICE, message, instance); }
static void Warning(const std::string& message, const IfcUtil::IfcBaseInterface* instance = 0) { Message(LOG_WARNING, message, instance); }
+183 -161
View File
@@ -106,16 +106,16 @@ void init_locale() {
// Opens the file and gets the filesize
//
#ifdef USE_MMAP
IfcSpfStream::IfcSpfStream(const std::string& fn, bool mmap)
IfcSpfStream::IfcSpfStream(const std::string& path, bool mmap)
#else
IfcSpfStream::IfcSpfStream(const std::string& fn)
IfcSpfStream::IfcSpfStream(const std::string& path)
#endif
: stream_(0),
buffer_(0),
valid(false),
eof(false) {
#ifdef _MSC_VER
std::wstring fn_ws = IfcUtil::path::from_utf8(fn);
std::wstring fn_ws = IfcUtil::path::from_utf8(path);
const wchar_t* fn_wide = fn_ws.c_str();
#ifdef USE_MMAP
@@ -132,10 +132,10 @@ IfcSpfStream::IfcSpfStream(const std::string& fn)
#ifdef USE_MMAP
if (mmap) {
mfs = boost::iostreams::mapped_file_source(fn);
mfs = boost::iostreams::mapped_file_source(path);
} else {
#endif
stream_ = fopen(fn.c_str(), "rb");
stream_ = fopen(path.c_str(), "rb");
#ifdef USE_MMAP
}
#endif
@@ -174,28 +174,28 @@ IfcSpfStream::IfcSpfStream(const std::string& fn)
#endif
}
IfcSpfStream::IfcSpfStream(std::istream& f, int l)
IfcSpfStream::IfcSpfStream(std::istream& stream, int length)
: stream_(0),
buffer_(0) {
eof = false;
size = l;
size = length;
char* buffer_rw = new char[size];
f.read(buffer_rw, size);
stream.read(buffer_rw, size);
buffer_ = buffer_rw;
valid = f.gcount() == size;
valid = stream.gcount() == size;
ptr_ = 0;
len_ = l;
len_ = length;
}
IfcSpfStream::IfcSpfStream(void* data, int l)
IfcSpfStream::IfcSpfStream(void* data, int length)
: stream_(0),
buffer_(0) {
eof = false;
size = l;
size = length;
buffer_ = (char*)data;
valid = true;
ptr_ = 0;
len_ = l;
len_ = length;
}
IfcSpfStream::~IfcSpfStream() {
@@ -218,8 +218,8 @@ void IfcSpfStream::Close() {
//
// Seeks an arbitrary position in the file
//
void IfcSpfStream::Seek(unsigned int o) {
ptr_ = o;
void IfcSpfStream::Seek(unsigned int offset) {
ptr_ = offset;
if (ptr_ >= len_) {
throw IfcException("Reading outside of file limits");
}
@@ -236,8 +236,8 @@ char IfcSpfStream::Peek() {
//
// Returns the character at specified offset
//
char IfcSpfStream::Read(unsigned int o) {
return buffer_[o];
char IfcSpfStream::Read(unsigned int offset) {
return buffer_[offset];
}
//
@@ -262,10 +262,10 @@ void IfcSpfStream::Inc() {
}
}
IfcSpfLexer::IfcSpfLexer(IfcParse::IfcSpfStream* s, IfcParse::IfcFile* f) {
file = f;
stream = s;
decoder_ = new IfcCharacterDecoder(s);
IfcSpfLexer::IfcSpfLexer(IfcParse::IfcSpfStream* stream_, IfcParse::IfcFile* file_) {
file = file_;
stream = stream_;
decoder_ = new IfcCharacterDecoder(stream_);
}
IfcSpfLexer::~IfcSpfLexer() {
@@ -273,42 +273,42 @@ IfcSpfLexer::~IfcSpfLexer() {
}
unsigned int IfcSpfLexer::skipWhitespace() {
unsigned int n = 0;
unsigned int index = 0;
while (!stream->eof) {
char c = stream->Peek();
if ((c == ' ' || c == '\r' || c == '\n' || c == '\t')) {
char character = stream->Peek();
if ((character == ' ' || character == '\r' || character == '\n' || character == '\t')) {
stream->Inc();
++n;
++index;
} else {
break;
}
}
return n;
return index;
}
unsigned int IfcSpfLexer::skipComment() {
char c = stream->Peek();
if (c != '/') {
char character = stream->Peek();
if (character != '/') {
return 0;
}
stream->Inc();
c = stream->Peek();
if (c != '*') {
character = stream->Peek();
if (character != '*') {
stream->Seek(stream->Tell() - 1);
return 0;
}
unsigned int n = 2;
char p = 0;
unsigned int index = 2;
char intermediate = 0;
while (!stream->eof) {
c = stream->Peek();
character = stream->Peek();
stream->Inc();
++n;
if (c == '/' && p == '*') {
++index;
if (character == '/' && intermediate == '*') {
break;
}
p = c;
intermediate = character;
}
return n;
return index;
}
//
@@ -328,10 +328,16 @@ Token IfcSpfLexer::Next() {
}
unsigned int pos = stream->Tell();
char c = stream->Peek();
char character = stream->Peek();
// If the cursor is at [()=,;$*] we know token consists of single char
if (c == '(' || c == ')' || c == '=' || c == ',' || c == ';' || c == '$' || c == '*') {
if (character == '(' ||
character == ')' ||
character == '=' ||
character == ',' ||
character == ';' ||
character == '$' ||
character == '*') {
stream->Inc();
return OperatorTokenPtr(this, pos, pos + 1);
}
@@ -341,15 +347,20 @@ Token IfcSpfLexer::Next() {
while (!stream->eof) {
// Read character and increment pointer if not starting a new token
c = stream->Peek();
if ((len != 0) && (c == '(' || c == ')' || c == '=' || c == ',' || c == ';' || c == '/')) {
character = stream->Peek();
if ((len != 0) && (character == '(' ||
character == ')' ||
character == '=' ||
character == ',' ||
character == ';' ||
character == '/')) {
break;
}
stream->Inc();
len++;
// If a string is encountered defer processing to the IfcCharacterDecoder
if (c == '\'') {
if (character == '\'') {
decoder_->skip();
}
}
@@ -384,20 +395,28 @@ char IfcSpfStream::peek_at(unsigned int local_ptr) {
void IfcSpfLexer::TokenString(unsigned int offset, std::string& buffer) {
buffer.clear();
while (!stream->is_eof_at(offset)) {
char c = stream->peek_at(offset);
if (!buffer.empty() && (c == '(' || c == ')' || c == '=' || c == ',' || c == ';' || c == '/')) {
char character = stream->peek_at(offset);
if (!buffer.empty() && (character == '(' ||
character == ')' ||
character == '=' ||
character == ',' ||
character == ';' ||
character == '/')) {
break;
}
stream->increment_at(offset);
if (c == ' ' || c == '\r' || c == '\n' || c == '\t') {
if (character == ' ' ||
character == '\r' ||
character == '\n' ||
character == '\t') {
continue;
}
if (c == '\'') {
if (character == '\'') {
// todo, make decoder use local offset ptr
buffer = decoder_->get(offset);
break;
}
buffer.push_back(c);
buffer.push_back(character);
}
}
@@ -405,11 +424,14 @@ void IfcSpfLexer::TokenString(unsigned int offset, std::string& buffer) {
inline void RemoveTokenSeparators(IfcSpfStream* stream, unsigned start, unsigned end, std::string& oDestination) {
oDestination.clear();
for (unsigned i = start; i < end; i++) {
char c = stream->Read(i);
if (c == ' ' || c == '\r' || c == '\n' || c == '\t') {
char character = stream->Read(i);
if (character == ' ' ||
character == '\r' ||
character == '\n' ||
character == '\t') {
continue;
}
oDestination += c;
oDestination += character;
}
}
@@ -498,110 +520,110 @@ Token IfcParse::GeneralTokenPtr(IfcSpfLexer* lexer, unsigned start, unsigned end
}
Token IfcParse::NoneTokenPtr() { return Token(); }
bool TokenFunc::isOperator(const Token& t) {
return t.type == Token_OPERATOR;
bool TokenFunc::isOperator(const Token& token) {
return token.type == Token_OPERATOR;
}
bool TokenFunc::isOperator(const Token& t, char op) {
return t.type == Token_OPERATOR && t.value_char == op;
bool TokenFunc::isOperator(const Token& token, char character) {
return token.type == Token_OPERATOR && token.value_char == character;
}
bool TokenFunc::isIdentifier(const Token& t) {
return t.type == Token_IDENTIFIER;
bool TokenFunc::isIdentifier(const Token& token) {
return token.type == Token_IDENTIFIER;
}
bool TokenFunc::isString(const Token& t) {
return t.type == Token_STRING;
bool TokenFunc::isString(const Token& token) {
return token.type == Token_STRING;
}
bool TokenFunc::isEnumeration(const Token& t) {
return t.type == Token_ENUMERATION || t.type == Token_BOOL;
bool TokenFunc::isEnumeration(const Token& token) {
return token.type == Token_ENUMERATION || token.type == Token_BOOL;
}
bool TokenFunc::isBinary(const Token& t) {
return t.type == Token_BINARY;
bool TokenFunc::isBinary(const Token& token) {
return token.type == Token_BINARY;
}
bool TokenFunc::isKeyword(const Token& t) {
return t.type == Token_KEYWORD;
bool TokenFunc::isKeyword(const Token& token) {
return token.type == Token_KEYWORD;
}
bool TokenFunc::isInt(const Token& t) {
return t.type == Token_INT;
bool TokenFunc::isInt(const Token& token) {
return token.type == Token_INT;
}
bool TokenFunc::isBool(const Token& t) {
bool TokenFunc::isBool(const Token& token) {
// Bool and logical share the same storage type, just logical unknown is stored as 2.
return t.type == Token_BOOL && t.value_int != 2;
return token.type == Token_BOOL && token.value_int != 2;
}
bool TokenFunc::isLogical(const Token& t) {
return t.type == Token_BOOL;
bool TokenFunc::isLogical(const Token& token) {
return token.type == Token_BOOL;
}
bool TokenFunc::isFloat(const Token& t) {
bool TokenFunc::isFloat(const Token& token) {
#ifdef PERMISSIVE_FLOAT
/// NB: We are being more permissive here then allowed by the standard
return t.type == Token_FLOAT || t.type == Token_INT;
return token.type == Token_FLOAT || token.type == Token_INT;
#else
return t.type == Token_FLOAT;
return token.type == Token_FLOAT;
#endif
}
int TokenFunc::asInt(const Token& t) {
if (t.type != Token_INT) {
throw IfcInvalidTokenException(t.startPos, toString(t), "integer");
int TokenFunc::asInt(const Token& token) {
if (token.type != Token_INT) {
throw IfcInvalidTokenException(token.startPos, toString(token), "integer");
}
return t.value_int;
return token.value_int;
}
int TokenFunc::asIdentifier(const Token& t) {
if (t.type != Token_IDENTIFIER) {
throw IfcInvalidTokenException(t.startPos, toString(t), "instance name");
int TokenFunc::asIdentifier(const Token& token) {
if (token.type != Token_IDENTIFIER) {
throw IfcInvalidTokenException(token.startPos, toString(token), "instance name");
}
return t.value_int;
return token.value_int;
}
bool TokenFunc::asBool(const Token& t) {
if (t.type != Token_BOOL) {
throw IfcInvalidTokenException(t.startPos, toString(t), "boolean");
bool TokenFunc::asBool(const Token& token) {
if (token.type != Token_BOOL) {
throw IfcInvalidTokenException(token.startPos, toString(token), "boolean");
}
return t.value_int == 1;
return token.value_int == 1;
}
boost::logic::tribool TokenFunc::asLogical(const Token& t) {
if (t.type != Token_BOOL) {
throw IfcInvalidTokenException(t.startPos, toString(t), "boolean");
boost::logic::tribool TokenFunc::asLogical(const Token& token) {
if (token.type != Token_BOOL) {
throw IfcInvalidTokenException(token.startPos, toString(token), "boolean");
}
if (t.value_int == 0) {
if (token.value_int == 0) {
return false;
}
if (t.value_int == 1) {
if (token.value_int == 1) {
return true;
}
return boost::logic::indeterminate;
}
double TokenFunc::asFloat(const Token& t) {
double TokenFunc::asFloat(const Token& token) {
#ifdef PERMISSIVE_FLOAT
if (t.type == Token_INT) {
if (token.type == Token_INT) {
/// NB: We are being more permissive here then allowed by the standard
return t.value_int;
return token.value_int;
} // ----> continues beyond preprocessor directive
#endif
if (t.type == Token_FLOAT) {
return t.value_double;
if (token.type == Token_FLOAT) {
return token.value_double;
}
throw IfcInvalidTokenException(t.startPos, toString(t), "real");
throw IfcInvalidTokenException(token.startPos, toString(token), "real");
}
const std::string& TokenFunc::asStringRef(const Token& t) {
if (t.type == Token_NONE) {
const std::string& TokenFunc::asStringRef(const Token& token) {
if (token.type == Token_NONE) {
throw IfcParse::IfcException("Null token encountered, premature end of file?");
}
std::string& str = t.lexer->GetTempString();
t.lexer->TokenString(t.startPos, str);
if ((isString(t) || isEnumeration(t) || isBinary(t)) && !str.empty()) {
std::string& str = token.lexer->GetTempString();
token.lexer->TokenString(token.startPos, str);
if ((isString(token) || isEnumeration(token) || isBinary(token)) && !str.empty()) {
//remove start+end characters in-place
str.erase(str.end() - 1);
str.erase(str.begin());
@@ -609,15 +631,15 @@ const std::string& TokenFunc::asStringRef(const Token& t) {
return str;
}
std::string TokenFunc::asString(const Token& t) {
if (isString(t) || isEnumeration(t) || isBinary(t)) {
return asStringRef(t);
std::string TokenFunc::asString(const Token& token) {
if (isString(token) || isEnumeration(token) || isBinary(token)) {
return asStringRef(token);
}
throw IfcInvalidTokenException(t.startPos, toString(t), "string");
throw IfcInvalidTokenException(token.startPos, toString(token), "string");
}
boost::dynamic_bitset<> TokenFunc::asBinary(const Token& t) {
const std::string& str = asStringRef(t);
boost::dynamic_bitset<> TokenFunc::asBinary(const Token& token) {
const std::string& str = asStringRef(token);
if (str.size() < 1) {
throw IfcException("Token is not a valid binary sequence");
}
@@ -648,19 +670,19 @@ boost::dynamic_bitset<> TokenFunc::asBinary(const Token& t) {
return bitset;
}
std::string TokenFunc::toString(const Token& t) {
std::string TokenFunc::toString(const Token& token) {
std::string result;
t.lexer->TokenString(t.startPos, result);
token.lexer->TokenString(token.startPos, result);
return result;
}
TokenArgument::TokenArgument(const Token& t) {
token = t;
TokenArgument::TokenArgument(const Token& tok) {
token = tok;
}
EntityArgument::EntityArgument(const Token& t) {
IfcParse::IfcFile* file = t.lexer->file;
IfcEntityInstanceData* data = read(0, file, t.startPos);
EntityArgument::EntityArgument(const Token& token) {
IfcParse::IfcFile* file = token.lexer->file;
IfcEntityInstanceData* data = read(0, file, token.startPos);
// Data needs to be loaded, for the tokens
// to be consumed and parsing to continue.
data->load();
@@ -687,12 +709,12 @@ class vector_or_array {
size_(size),
index_(0) {}
void push_back(const T& t) {
void push_back(const T& type) {
// @todo this should log a warning when the size is exceeded
if (array_ && index_ < size_) {
array_[index_++] = t;
array_[index_++] = type;
} else if (vector_) {
vector_->push_back(t);
vector_->push_back(type);
}
}
@@ -755,9 +777,9 @@ size_t IfcParse::IfcFile::load(unsigned entity_instance_name, const IfcParse::en
if (TokenFunc::isKeyword(next)) {
try {
auto* ea = new EntityArgument(next);
addEntity(((IfcUtil::IfcBaseClass*)*ea));
filler.push_back(ea);
auto* entity = new EntityArgument(next);
addEntity(((IfcUtil::IfcBaseClass*)*entity));
filler.push_back(entity);
} catch (IfcException& e) {
Logger::Message(Logger::LOG_ERROR, e.what());
}
@@ -1069,26 +1091,26 @@ void IfcParse::IfcFile::register_inverse(unsigned id_from, const IfcParse::entit
}
void IfcParse::IfcFile::unregister_inverse(unsigned id_from, const IfcParse::entity* from_entity, IfcUtil::IfcBaseClass* inst, int attribute_index) {
const auto* e = from_entity;
while (e != nullptr) {
std::vector<int>& ids = byref_[{inst->data().id(), e->index_in_schema(), attribute_index}];
std::vector<int>::iterator it = std::find(ids.begin(), ids.end(), id_from);
if (it == ids.end()) {
const auto* entity = from_entity;
while (entity != nullptr) {
std::vector<int>& ids = byref_[{inst->data().id(), entity->index_in_schema(), attribute_index}];
std::vector<int>::iterator iter = std::find(ids.begin(), ids.end(), id_from);
if (iter == ids.end()) {
// @todo inverses also need to be populated when multiple instances are added to a new file.
// throw IfcParse::IfcException("Instance not found among inverses");
} else {
ids.erase(it);
ids.erase(iter);
}
e = e->supertype();
entity = entity->supertype();
}
std::vector<int>& ids = byref_excl_[inst->data().id()];
std::vector<int>::iterator it = std::find(ids.begin(), ids.end(), id_from);
if (it == ids.end()) {
std::vector<int>::iterator iter = std::find(ids.begin(), ids.end(), id_from);
if (iter == ids.end()) {
// @todo inverses also need to be populated when multiple instances are added to a new file.
// throw IfcParse::IfcException("Instance not found among inverses");
} else {
ids.erase(it);
ids.erase(iter);
}
}
@@ -1158,15 +1180,15 @@ unsigned IfcEntityInstanceData::set_id(boost::optional<unsigned> i) {
// Returns the entities of Entity type that have this entity in their ArgumentList
//
aggregate_of_instance::ptr IfcEntityInstanceData::getInverse(const IfcParse::declaration* type, int attribute_index) const {
static std::mutex m;
std::lock_guard<std::mutex> lk(m);
static std::mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
return file->getInverse(id_, type, attribute_index);
}
void IfcEntityInstanceData::load() const {
static std::recursive_mutex m;
std::lock_guard<std::recursive_mutex> lk(m);
static std::recursive_mutex mtx;
std::lock_guard<std::recursive_mutex> lockk(mtx);
Argument** tmp_data = nullptr;
@@ -1221,19 +1243,19 @@ IfcUtil::ArgumentType get_argument_type(const IfcParse::declaration* decl, size_
}
} // namespace
IfcEntityInstanceData::IfcEntityInstanceData(const IfcEntityInstanceData& e) {
IfcEntityInstanceData::IfcEntityInstanceData(const IfcEntityInstanceData& data) {
file = 0;
type_ = e.type_;
type_ = data.type_;
id_ = 0;
const size_t count = e.getArgumentCount();
const size_t count = data.getArgumentCount();
// In order not to have the instance read from file
attributes_ = new Argument*[count];
for (unsigned int i = 0; i < count; ++i) {
attributes_[i] = 0;
this->setArgument(i, e.getArgument(i), get_argument_type(e.type(), i), true);
this->setArgument(i, data.getArgument(i), get_argument_type(data.type(), i), true);
}
}
@@ -1548,17 +1570,17 @@ IfcFile::IfcFile(const std::string& fn, bool mmap) {
initialize_(new IfcSpfStream(fn, mmap));
}
#else
IfcFile::IfcFile(const std::string& fn) {
initialize_(new IfcSpfStream(fn));
IfcFile::IfcFile(const std::string& path) {
initialize_(new IfcSpfStream(path));
}
#endif
IfcFile::IfcFile(std::istream& f, int len) {
initialize_(new IfcSpfStream(f, len));
IfcFile::IfcFile(std::istream& stream, int length) {
initialize_(new IfcSpfStream(stream, length));
}
IfcFile::IfcFile(void* data, int len) {
initialize_(new IfcSpfStream(data, len));
IfcFile::IfcFile(void* data, int length) {
initialize_(new IfcSpfStream(data, length));
}
IfcFile::IfcFile(IfcParse::IfcSpfStream* s) {
@@ -1844,18 +1866,18 @@ void traversal_visitor::operator()(IfcUtil::IfcBaseClass* inst, int /* index */)
aggregate_of_instance::ptr IfcParse::traverse(IfcUtil::IfcBaseClass* instance, int max_level) {
std::set<IfcUtil::IfcBaseClass*> visited;
traversal_recorder r(0);
traverse_(instance, visited, r, 0, max_level);
return r.get_list();
traversal_recorder recorder(0);
traverse_(instance, visited, recorder, 0, max_level);
return recorder.get_list();
}
// I'm cheating this isn't breadth-first, but rather we record visited instances
// keeping track of their rank and return a list ordered by rank. Is this equivalent?
aggregate_of_instance::ptr IfcParse::traverse_breadth_first(IfcUtil::IfcBaseClass* instance, int max_level) {
std::set<IfcUtil::IfcBaseClass*> visited;
traversal_recorder r(1);
traverse_(instance, visited, r, 0, max_level);
return r.get_list();
traversal_recorder recorder(1);
traverse_(instance, visited, recorder, 0, max_level);
return recorder.get_list();
}
/// @note: for backwards compatibility
@@ -1868,8 +1890,8 @@ aggregate_of_instance::ptr IfcFile::traverse_breadth_first(IfcUtil::IfcBaseClass
return IfcParse::traverse_breadth_first(instance, max_level);
}
void IfcFile::addEntities(aggregate_of_instance::ptr es) {
for (aggregate_of_instance::it i = es->begin(); i != es->end(); ++i) {
void IfcFile::addEntities(aggregate_of_instance::ptr entities) {
for (aggregate_of_instance::it i = entities->begin(); i != entities->end(); ++i) {
addEntity(*i);
}
}
@@ -2463,24 +2485,24 @@ struct id_instance_pair_sorter {
};
} // namespace
std::ostream& operator<<(std::ostream& os, const IfcParse::IfcFile& f) {
f.header().write(os);
std::ostream& operator<<(std::ostream& out, const IfcParse::IfcFile& file) {
file.header().write(out);
typedef std::vector<std::pair<unsigned int, IfcUtil::IfcBaseClass*>> vector_t;
vector_t sorted(f.begin(), f.end());
vector_t sorted(file.begin(), file.end());
std::sort(sorted.begin(), sorted.end(), id_instance_pair_sorter());
for (vector_t::const_iterator it = sorted.begin(); it != sorted.end(); ++it) {
const IfcUtil::IfcBaseClass* e = it->second;
if (e->declaration().as_entity() != nullptr) {
os << e->data().toString(true) << ";" << std::endl;
out << e->data().toString(true) << ";" << std::endl;
}
}
os << "ENDSEC;" << std::endl;
os << "END-ISO-10303-21;" << std::endl;
out << "ENDSEC;" << std::endl;
out << "END-ISO-10303-21;" << std::endl;
return os;
return out;
}
std::string IfcFile::createTimestamp() const {
@@ -2520,8 +2542,8 @@ std::vector<int> IfcFile::get_inverse_indices(int instance_id) {
auto refs = instances_by_reference(instance_id);
for (const auto& r : *refs) {
auto it = mapping.find(r->data().id());
for (const auto& ref : *refs) {
auto it = mapping.find(ref->data().id());
if (it == mapping.end() || it->second.empty()) {
throw IfcException("Internal error");
}
+32 -32
View File
@@ -88,51 +88,51 @@ struct Token {
/// Tokens are merely offsets to where they can be read in the file
class IFC_PARSE_API TokenFunc {
private:
static bool startsWith(const Token& t, char c);
static bool startsWith(const Token& token, char character);
public:
/// Returns the offset at which the token is read from the file
// static unsigned int Offset(const Token& t);
/// Returns whether the token can be interpreted as a string
static bool isString(const Token& t);
static bool isString(const Token& token);
/// Returns whether the token can be interpreted as an identifier
static bool isIdentifier(const Token& t);
static bool isIdentifier(const Token& token);
/// Returns whether the token can be interpreted as a syntactical operator
static bool isOperator(const Token& t);
static bool isOperator(const Token& token);
/// Returns whether the token is a given operator
static bool isOperator(const Token& t, char op);
static bool isOperator(const Token& token, char character);
/// Returns whether the token can be interpreted as an enumerated value
static bool isEnumeration(const Token& t);
static bool isEnumeration(const Token& token);
/// Returns whether the token can be interpreted as a datatype name
static bool isKeyword(const Token& t);
static bool isKeyword(const Token& token);
/// Returns whether the token can be interpreted as an integer
static bool isInt(const Token& t);
static bool isInt(const Token& token);
/// Returns whether the token can be interpreted as a boolean
static bool isBool(const Token& t);
static bool isBool(const Token& token);
/// Returns whether the token can be interpreted as a logical
static bool isLogical(const Token& t);
static bool isLogical(const Token& token);
/// Returns whether the token can be interpreted as a floating point number
static bool isFloat(const Token& t);
static bool isFloat(const Token& token);
/// Returns whether the token can be interpreted as a binary type
static bool isBinary(const Token& t);
static bool isBinary(const Token& token);
/// Returns the token interpreted as an integer
static int asInt(const Token& t);
static int asInt(const Token& token);
/// Returns the token interpreted as an identifier
static int asIdentifier(const Token& t);
static int asIdentifier(const Token& token);
/// Returns the token interpreted as an boolean (.T. or .F.)
static bool asBool(const Token& t);
static bool asBool(const Token& token);
/// Returns the token interpreted as an logical (.T. or .F. or .U.)
static boost::logic::tribool asLogical(const Token& t);
static boost::logic::tribool asLogical(const Token& token);
/// Returns the token as a floating point number
static double asFloat(const Token& t);
static double asFloat(const Token& token);
/// Returns the token as a string (without the dot or apostrophe)
static std::string asString(const Token& t);
static std::string asString(const Token& token);
/// Returns the token as a string in internal buffer (for optimization purposes)
static const std::string& asStringRef(const Token& t);
static const std::string& asStringRef(const Token& token);
/// Returns the token as a string (without the dot or apostrophe)
static boost::dynamic_bitset<> asBinary(const Token& t);
static boost::dynamic_bitset<> asBinary(const Token& token);
/// Returns a string representation of the token (including the dot or apostrophe)
static std::string toString(const Token& t);
static std::string toString(const Token& token);
};
//
@@ -152,12 +152,12 @@ class IFC_PARSE_API IfcSpfLexer {
public:
std::string& GetTempString() const {
static my_thread_local std::string s;
return s;
static my_thread_local std::string string;
return string;
}
IfcSpfStream* stream;
IfcFile* file;
IfcSpfLexer(IfcSpfStream* s, IfcFile* f);
IfcSpfLexer(IfcSpfStream* stream, IfcFile* file);
Token Next();
~IfcSpfLexer();
void TokenString(unsigned int offset, std::string& result);
@@ -178,7 +178,7 @@ class IFC_PARSE_API ArgumentList : public Argument {
list_(new Argument* [size_] { 0 }) {}
~ArgumentList();
void read(IfcSpfLexer* t, std::vector<unsigned int>& ids);
void read(IfcSpfLexer* lexer, std::vector<unsigned int>& ids);
IfcUtil::ArgumentType type() const;
@@ -195,7 +195,7 @@ class IFC_PARSE_API ArgumentList : public Argument {
bool isNull() const;
unsigned int size() const;
Argument* operator[](unsigned int i) const;
Argument* operator[](unsigned int index) const;
std::string toString(bool upper = false) const;
@@ -221,7 +221,7 @@ class IFC_PARSE_API NullArgument : public Argument {
class IFC_PARSE_API TokenArgument : public Argument {
public:
Token token;
TokenArgument(const Token& t);
TokenArgument(const Token& token);
IfcUtil::ArgumentType type() const;
@@ -236,7 +236,7 @@ class IFC_PARSE_API TokenArgument : public Argument {
bool isNull() const;
unsigned int size() const;
Argument* operator[](unsigned int i) const;
Argument* operator[](unsigned int index) const;
std::string toString(bool upper = false) const;
};
@@ -248,7 +248,7 @@ class IFC_PARSE_API EntityArgument : public Argument {
IfcUtil::IfcBaseClass* entity_;
public:
EntityArgument(const Token& t);
EntityArgument(const Token& token);
~EntityArgument();
IfcUtil::ArgumentType type() const;
@@ -258,17 +258,17 @@ class IFC_PARSE_API EntityArgument : public Argument {
bool isNull() const;
unsigned int size() const;
Argument* operator[](unsigned int i) const;
Argument* operator[](unsigned int index) const;
std::string toString(bool upper = false) const;
};
IFC_PARSE_API IfcEntityInstanceData* read(unsigned int i, IfcFile* t, boost::optional<unsigned> offset = boost::none);
IFC_PARSE_API IfcEntityInstanceData* read(unsigned int index, IfcFile* file, boost::optional<unsigned> offset = boost::none);
IFC_PARSE_API aggregate_of_instance::ptr traverse(IfcUtil::IfcBaseClass* instance, int max_level = -1);
IFC_PARSE_API aggregate_of_instance::ptr traverse_breadth_first(IfcUtil::IfcBaseClass* instance, int max_level = -1);
} // namespace IfcParse
IFC_PARSE_API std::ostream& operator<<(std::ostream& os, const IfcParse::IfcFile& f);
IFC_PARSE_API std::ostream& operator<<(std::ostream& out, const IfcParse::IfcFile& file);
#endif
+19 -19
View File
@@ -56,53 +56,53 @@
#include "Ifc4x3_add2.h"
#endif
double IfcParse::IfcSIPrefixToValue(const std::string& v) {
if (v == "EXA") {
double IfcParse::IfcSIPrefixToValue(const std::string& prefix) {
if (prefix == "EXA") {
return 1.e18;
}
if (v == "PETA") {
if (prefix == "PETA") {
return 1.e15;
}
if (v == "TERA") {
if (prefix == "TERA") {
return 1.e12;
}
if (v == "GIGA") {
if (prefix == "GIGA") {
return 1.e9;
}
if (v == "MEGA") {
if (prefix == "MEGA") {
return 1.e6;
}
if (v == "KILO") {
if (prefix == "KILO") {
return 1.e3;
}
if (v == "HECTO") {
if (prefix == "HECTO") {
return 1.e2;
}
if (v == "DECA") {
if (prefix == "DECA") {
return 1.e1;
}
if (v == "DECI") {
if (prefix == "DECI") {
return 1.e-1;
}
if (v == "CENTI") {
if (prefix == "CENTI") {
return 1.e-2;
}
if (v == "MILLI") {
if (prefix == "MILLI") {
return 1.e-3;
}
if (v == "MICRO") {
if (prefix == "MICRO") {
return 1.e-6;
}
if (v == "NANO") {
if (prefix == "NANO") {
return 1.e-9;
}
if (v == "PICO") {
if (prefix == "PICO") {
return 1.e-12;
}
if (v == "FEMTO") {
if (prefix == "FEMTO") {
return 1.e-15;
}
if (v == "ATTO") {
if (prefix == "ATTO") {
return 1.e-18;
}
return 1.;
@@ -119,8 +119,8 @@ double IfcParse::get_SI_equivalent(typename Schema::IfcNamedUnit* named_unit) {
typename Schema::IfcUnit* component = factor->UnitComponent();
if (component->declaration().is(Schema::IfcSIUnit::Class())) {
si_unit = component->template as<typename Schema::IfcSIUnit>();
typename Schema::IfcValue* v = factor->ValueComponent();
scale = *v->data().getArgument(0);
typename Schema::IfcValue* value = factor->ValueComponent();
scale = *value->data().getArgument(0);
}
} else if (named_unit->declaration().is(Schema::IfcSIUnit::Class())) {
si_unit = named_unit->template as<typename Schema::IfcSIUnit>();
+12 -12
View File
@@ -62,7 +62,7 @@
bool IfcParse::declaration::is(const std::string& name) const {
const std::string* name_ptr = &name;
if (std::any_of(name.begin(), name.end(), [](char c) { return std::islower(c); })) {
if (std::any_of(name.begin(), name.end(), [](char character) { return std::islower(character); })) {
temp_string_() = name;
boost::to_upper(temp_string_());
name_ptr = &temp_string_();
@@ -76,9 +76,9 @@ bool IfcParse::declaration::is(const std::string& name) const {
return this->as_entity()->supertype()->is(name);
}
if (this->as_type_declaration() != nullptr) {
const IfcParse::named_type* nt = this->as_type_declaration()->declared_type()->as_named_type();
if (nt != nullptr) {
return nt->is(name);
const IfcParse::named_type* named_type = this->as_type_declaration()->declared_type()->as_named_type();
if (named_type != nullptr) {
return named_type->is(name);
}
}
@@ -94,9 +94,9 @@ bool IfcParse::declaration::is(const IfcParse::declaration& decl) const {
return this->as_entity()->supertype()->is(decl);
}
if (this->as_type_declaration() != nullptr) {
const IfcParse::named_type* nt = this->as_type_declaration()->declared_type()->as_named_type();
if (nt != nullptr) {
return nt->is(decl);
const IfcParse::named_type* named_type = this->as_type_declaration()->declared_type()->as_named_type();
if (named_type != nullptr) {
return named_type->is(decl);
}
}
@@ -159,8 +159,8 @@ IfcUtil::IfcBaseClass* IfcParse::schema_definition::instantiate(IfcEntityInstanc
return new IfcUtil::IfcLateBoundEntity(data->type(), data);
}
void IfcParse::register_schema(schema_definition* s) {
schemas.insert({boost::to_upper_copy(s->name()), s});
void IfcParse::register_schema(schema_definition* schema) {
schemas.insert({boost::to_upper_copy(schema->name()), schema});
}
const IfcParse::schema_definition* IfcParse::schema_by_name(const std::string& name) {
@@ -202,11 +202,11 @@ const IfcParse::schema_definition* IfcParse::schema_by_name(const std::string& n
Ifc4x3_add2::get_schema();
#endif
std::map<std::string, const IfcParse::schema_definition*>::const_iterator it = schemas.find(boost::to_upper_copy(name));
if (it == schemas.end()) {
std::map<std::string, const IfcParse::schema_definition*>::const_iterator iter = schemas.find(boost::to_upper_copy(name));
if (iter == schemas.end()) {
throw IfcParse::IfcException("No schema named " + name);
}
return it->second;
return iter->second;
}
std::vector<std::string> IfcParse::schema_names() {
+24 -24
View File
@@ -147,8 +147,8 @@ class IFC_PARSE_API declaration {
mutable const schema_definition* schema_;
std::string& temp_string_() const {
static my_thread_local std::string s;
return s;
static my_thread_local std::string string;
return string;
}
public:
@@ -226,14 +226,14 @@ class IFC_PARSE_API enumeration_type : public declaration {
return enumeration_items_[i].c_str();
}
size_t lookup_enum_offset(const std::string& s) const {
size_t i = 0;
for (auto it = enumeration_items_.begin(); it != enumeration_items_.end(); ++it, ++i) {
if (s == *it) {
return i;
size_t lookup_enum_offset(const std::string& string) const {
size_t index = 0;
for (auto it = enumeration_items_.begin(); it != enumeration_items_.end(); ++it, ++index) {
if (string == *it) {
return index;
}
}
throw IfcParse::IfcException("Unable to find keyword in schema: " + s);
throw IfcParse::IfcException("Unable to find keyword in schema: " + string);
}
virtual const enumeration_type* as_enumeration_type() const { return this; }
@@ -404,10 +404,10 @@ class IFC_PARSE_API entity : public declaration {
if (index > -1) {
index += current->attributes().size();
} else {
std::vector<const attribute*>::const_iterator it;
it = std::find(current->attributes().begin(), current->attributes().end(), attr);
if (it != current->attributes().end()) {
index = std::distance(current->attributes().begin(), it);
std::vector<const attribute*>::const_iterator iter;
iter = std::find(current->attributes().begin(), current->attributes().end(), attr);
if (iter != current->attributes().end()) {
index = std::distance(current->attributes().begin(), iter);
}
}
} while ((current = current->supertype_) != 0);
@@ -422,10 +422,10 @@ class IFC_PARSE_API entity : public declaration {
if (index > -1) {
index += current->attributes().size();
} else {
std::vector<const attribute*>::const_iterator it;
it = std::find_if(current->attributes().begin(), current->attributes().end(), cmp);
if (it != current->attributes().end()) {
index = std::distance(current->attributes().begin(), it);
std::vector<const attribute*>::const_iterator iter;
iter = std::find_if(current->attributes().begin(), current->attributes().end(), cmp);
if (iter != current->attributes().end()) {
index = std::distance(current->attributes().begin(), iter);
}
}
} while ((current = current->supertype_) != 0);
@@ -464,16 +464,16 @@ class IFC_PARSE_API schema_definition {
class declaration_by_index_sort {
public:
bool operator()(const declaration* a, const declaration* b) {
return a->index_in_schema() < b->index_in_schema();
bool operator()(const declaration* lhs, const declaration* rhs) {
return lhs->index_in_schema() < rhs->index_in_schema();
}
};
instance_factory* factory_;
std::string& temp_string_() const {
static my_thread_local std::string s;
return s;
static my_thread_local std::string string;
return string;
}
public:
@@ -483,16 +483,16 @@ class IFC_PARSE_API schema_definition {
const declaration* declaration_by_name(const std::string& name) const {
const std::string* name_ptr = &name;
if (std::any_of(name.begin(), name.end(), [](char c) { return std::islower(c); })) {
if (std::any_of(name.begin(), name.end(), [](char character) { return std::islower(character); })) {
temp_string_() = name;
boost::to_upper(temp_string_());
name_ptr = &temp_string_();
}
std::vector<const declaration*>::const_iterator it = std::lower_bound(declarations_.begin(), declarations_.end(), *name_ptr, declaration_by_name_cmp());
if (it == declarations_.end() || (**it).name_uc() != *name_ptr) {
std::vector<const declaration*>::const_iterator iter = std::lower_bound(declarations_.begin(), declarations_.end(), *name_ptr, declaration_by_name_cmp());
if (iter == declarations_.end() || (**iter).name_uc() != *name_ptr) {
throw IfcParse::IfcException("Entity with name '" + name + "' not found in schema '" + name_ + "'");
}
return *it;
return *iter;
}
const declaration* declaration_by_name(int name) const {
+15 -15
View File
@@ -113,21 +113,21 @@ bool IfcSpfHeader::tryRead() {
}
}
void IfcSpfHeader::write(std::ostream& os) const {
os << ISO_10303_21 << ";"
<< "\n";
os << HEADER << ";"
<< "\n";
os << file_description().toString(true) << ";"
<< "\n";
os << file_name().toString(true) << ";"
<< "\n";
os << file_schema().toString(true) << ";"
<< "\n";
os << ENDSEC << ";"
<< "\n";
os << DATA << ";"
<< "\n";
void IfcSpfHeader::write(std::ostream& out) const {
out << ISO_10303_21 << ";"
<< "\n";
out << HEADER << ";"
<< "\n";
out << file_description().toString(true) << ";"
<< "\n";
out << file_name().toString(true) << ";"
<< "\n";
out << file_schema().toString(true) << ";"
<< "\n";
out << ENDSEC << ";"
<< "\n";
out << DATA << ";"
<< "\n";
}
const FileDescription& IfcSpfHeader::file_description() const {
+10 -10
View File
@@ -36,16 +36,16 @@ class IFC_PARSE_API HeaderEntity : public IfcEntityInstanceData {
HeaderEntity(const char* const datatype, size_t size, IfcParse::IfcFile* file);
virtual ~HeaderEntity();
void setValue(unsigned int i, const std::string& s) {
void setValue(unsigned int index, const std::string& string) {
IfcWrite::IfcWriteArgument* argument = new IfcWrite::IfcWriteArgument;
argument->set(s);
setArgument(i, argument);
argument->set(string);
setArgument(index, argument);
}
void setValue(unsigned int i, const std::vector<std::string>& s) {
void setValue(unsigned int index, const std::vector<std::string>& strings) {
IfcWrite::IfcWriteArgument* argument = new IfcWrite::IfcWriteArgument;
argument->set(s);
setArgument(i, argument);
argument->set(strings);
setArgument(index, argument);
}
public:
@@ -54,9 +54,9 @@ class IFC_PARSE_API HeaderEntity : public IfcEntityInstanceData {
}
std::string toString(bool upper = false) const {
std::stringstream ss;
ss << datatype_ << IfcEntityInstanceData::toString(upper);
return ss.str();
std::stringstream stream;
stream << datatype_ << IfcEntityInstanceData::toString(upper);
return stream.str();
}
};
@@ -139,7 +139,7 @@ class IFC_PARSE_API IfcSpfHeader {
void read();
bool tryRead();
void write(std::ostream& os) const;
void write(std::ostream& out) const;
const FileDescription& file_description() const;
const FileName& file_name() const;
+4 -4
View File
@@ -54,12 +54,12 @@ class IFC_PARSE_API IfcSpfStream {
bool eof;
unsigned int size;
#ifdef USE_MMAP
IfcSpfStream(const std::string& fn, bool mmap = false);
IfcSpfStream(const std::string& path, bool mmap = false);
#else
IfcSpfStream(const std::string& fn);
IfcSpfStream(const std::string& path);
#endif
IfcSpfStream(std::istream& f, int len);
IfcSpfStream(void* data, int len);
IfcSpfStream(std::istream& stream, int length);
IfcSpfStream(void* data, int length);
~IfcSpfStream();
/// Returns the character at the cursor
char Peek();
+18 -18
View File
@@ -61,14 +61,14 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/optional.hpp>
void aggregate_of_instance::push(IfcUtil::IfcBaseClass* l) {
if (l != nullptr) {
list_.push_back(l);
void aggregate_of_instance::push(IfcUtil::IfcBaseClass* instance) {
if (instance != nullptr) {
list_.push_back(instance);
}
}
void aggregate_of_instance::push(const aggregate_of_instance::ptr& l) {
if (l) {
for (it i = l->begin(); i != l->end(); ++i) {
void aggregate_of_instance::push(const aggregate_of_instance::ptr& instance) {
if (instance) {
for (it i = instance->begin(); i != instance->end(); ++i) {
if (*i != nullptr) {
list_.push_back(*i);
}
@@ -86,9 +86,9 @@ bool aggregate_of_instance::contains(IfcUtil::IfcBaseClass* instance) const {
return std::find(list_.begin(), list_.end(), instance) != list_.end();
}
void aggregate_of_instance::remove(IfcUtil::IfcBaseClass* instance) {
std::vector<IfcUtil::IfcBaseClass*>::iterator it;
while ((it = std::find(list_.begin(), list_.end(), instance)) != list_.end()) {
list_.erase(it);
std::vector<IfcUtil::IfcBaseClass*>::iterator iter;
while ((iter = std::find(list_.begin(), list_.end(), instance)) != list_.end()) {
list_.erase(iter);
}
}
@@ -168,8 +168,8 @@ const char* IfcUtil::ArgumentTypeToString(ArgumentType argument_type) {
return argument_type_string[static_cast<int>(argument_type)];
}
bool IfcUtil::valid_binary_string(const std::string& s) {
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
bool IfcUtil::valid_binary_string(const std::string& str) {
for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
if (*it != '0' && *it != '1') {
return false;
}
@@ -205,20 +205,20 @@ Argument* IfcUtil::IfcBaseEntity::get(const std::string& name) const {
aggregate_of_instance::ptr IfcUtil::IfcBaseEntity::get_inverse(const std::string& name) const {
const std::vector<const IfcParse::inverse_attribute*> attrs = declaration().as_entity()->all_inverse_attributes();
std::vector<const IfcParse::inverse_attribute*>::const_iterator it = attrs.begin();
for (; it != attrs.end(); ++it) {
if ((*it)->name() == name) {
std::vector<const IfcParse::inverse_attribute*>::const_iterator iter = attrs.begin();
for (; iter != attrs.end(); ++iter) {
if ((*iter)->name() == name) {
return data().getInverse(
(*it)->entity_reference(),
(int)(*it)->entity_reference()->attribute_index((*it)->attribute_reference()));
(*iter)->entity_reference(),
(int)(*iter)->entity_reference()->attribute_index((*iter)->attribute_reference()));
}
}
throw IfcParse::IfcException(name + " not found on " + declaration().name());
}
void IfcUtil::IfcBaseClass::data(IfcEntityInstanceData* d) {
void IfcUtil::IfcBaseClass::data(IfcEntityInstanceData* data) {
delete data_;
data_ = d;
data_ = data;
}
IfcUtil::ArgumentType IfcUtil::make_aggregate(IfcUtil::ArgumentType elem_type) {
+66 -66
View File
@@ -57,17 +57,17 @@ class StringBuilderVisitor : public boost::static_visitor<void> {
StringBuilderVisitor(const StringBuilderVisitor&); //N/A
StringBuilderVisitor& operator=(const StringBuilderVisitor&); //N/A
std::ostringstream& data;
std::ostringstream& data_;
template <typename T>
void serialize(const std::vector<T>& i) {
data << "(";
data_ << "(";
for (typename std::vector<T>::const_iterator it = i.begin(); it != i.end(); ++it) {
if (it != i.begin()) {
data << ",";
data_ << ",";
}
data << *it;
data_ << *it;
}
data << ")";
data_ << ")";
}
// The REAL token definition from the IFC SPF standard does not necessarily match
// the output of the C++ ostream formatting operation.
@@ -115,25 +115,25 @@ class StringBuilderVisitor : public boost::static_visitor<void> {
return oss.str();
}
bool upper;
bool upper_;
public:
StringBuilderVisitor(std::ostringstream& stream, bool upper = false)
: data(stream),
upper(upper) {}
void operator()(const boost::blank& /*i*/) { data << "$"; }
void operator()(const IfcWriteArgument::Derived& /*i*/) { data << "*"; }
void operator()(const int& i) { data << i; }
void operator()(const bool& i) { data << (i ? ".T." : ".F."); }
void operator()(const boost::logic::tribool& i) { data << (i ? ".T." : (boost::logic::indeterminate(i) ? ".U." : ".F.")); }
void operator()(const double& i) { data << format_double(i); }
void operator()(const boost::dynamic_bitset<>& i) { data << format_binary(i); }
: data_(stream),
upper_(upper) {}
void operator()(const boost::blank& /*i*/) { data_ << "$"; }
void operator()(const IfcWriteArgument::Derived& /*i*/) { data_ << "*"; }
void operator()(const int& i) { data_ << i; }
void operator()(const bool& i) { data_ << (i ? ".T." : ".F."); }
void operator()(const boost::logic::tribool& i) { data_ << (i ? ".T." : (boost::logic::indeterminate(i) ? ".U." : ".F.")); }
void operator()(const double& i) { data_ << format_double(i); }
void operator()(const boost::dynamic_bitset<>& i) { data_ << format_binary(i); }
void operator()(const std::string& i) {
std::string s = i;
if (upper) {
data << static_cast<std::string>(IfcCharacterEncoder(s));
if (upper_) {
data_ << static_cast<std::string>(IfcCharacterEncoder(s));
} else {
data << '\'' << s << '\'';
data_ << '\'' << s << '\'';
}
}
void operator()(const std::vector<int>& i);
@@ -141,85 +141,85 @@ class StringBuilderVisitor : public boost::static_visitor<void> {
void operator()(const std::vector<std::string>& i);
void operator()(const std::vector<boost::dynamic_bitset<>>& i);
void operator()(const IfcWriteArgument::EnumerationReference& i) {
data << "." << i.enumeration_value << ".";
data_ << "." << i.enumeration_value << ".";
}
void operator()(const IfcUtil::IfcBaseClass* const& i) {
const IfcEntityInstanceData& e = i->data();
if (e.type()->as_entity() == nullptr) {
data << e.toString(upper);
data_ << e.toString(upper_);
} else {
data << "#" << e.id();
data_ << "#" << e.id();
}
}
void operator()(const aggregate_of_instance::ptr& i) {
data << "(";
data_ << "(";
for (aggregate_of_instance::it it = i->begin(); it != i->end(); ++it) {
if (it != i->begin()) {
data << ",";
data_ << ",";
}
(*this)(*it);
}
data << ")";
data_ << ")";
}
void operator()(const std::vector<std::vector<int>>& i);
void operator()(const std::vector<std::vector<double>>& i);
void operator()(const aggregate_of_aggregate_of_instance::ptr& i) {
data << "(";
data_ << "(";
for (aggregate_of_aggregate_of_instance::outer_it outer_it = i->begin(); outer_it != i->end(); ++outer_it) {
if (outer_it != i->begin()) {
data << ",";
data_ << ",";
}
data << "(";
data_ << "(";
for (aggregate_of_aggregate_of_instance::inner_it inner_it = outer_it->begin(); inner_it != outer_it->end(); ++inner_it) {
if (inner_it != outer_it->begin()) {
data << ",";
data_ << ",";
}
(*this)(*inner_it);
}
data << ")";
data_ << ")";
}
data << ")";
data_ << ")";
}
void operator()(const IfcWriteArgument::empty_aggregate_t&) const { data << "()"; }
void operator()(const IfcWriteArgument::empty_aggregate_of_aggregate_t&) const { data << "()"; }
operator std::string() { return data.str(); }
void operator()(const IfcWriteArgument::empty_aggregate_t&) const { data_ << "()"; }
void operator()(const IfcWriteArgument::empty_aggregate_of_aggregate_t&) const { data_ << "()"; }
operator std::string() { return data_.str(); }
};
template <>
void StringBuilderVisitor::serialize(const std::vector<std::string>& i) {
data << "(";
data_ << "(";
for (std::vector<std::string>::const_iterator it = i.begin(); it != i.end(); ++it) {
if (it != i.begin()) {
data << ",";
data_ << ",";
}
std::string s = IfcCharacterEncoder(*it);
data << s;
std::string encoder = IfcCharacterEncoder(*it);
data_ << encoder;
}
data << ")";
data_ << ")";
}
template <>
void StringBuilderVisitor::serialize(const std::vector<double>& i) {
data << "(";
data_ << "(";
for (std::vector<double>::const_iterator it = i.begin(); it != i.end(); ++it) {
if (it != i.begin()) {
data << ",";
data_ << ",";
}
data << format_double(*it);
data_ << format_double(*it);
}
data << ")";
data_ << ")";
}
template <>
void StringBuilderVisitor::serialize(const std::vector<boost::dynamic_bitset<>>& i) {
data << "(";
data_ << "(";
for (std::vector<boost::dynamic_bitset<>>::const_iterator it = i.begin(); it != i.end(); ++it) {
if (it != i.begin()) {
data << ",";
data_ << ",";
}
data << format_binary(*it);
data_ << format_binary(*it);
}
data << ")";
data_ << ")";
}
void StringBuilderVisitor::operator()(const std::vector<int>& i) { serialize(i); }
@@ -227,24 +227,24 @@ void StringBuilderVisitor::operator()(const std::vector<double>& i) { serialize(
void StringBuilderVisitor::operator()(const std::vector<std::string>& i) { serialize(i); }
void StringBuilderVisitor::operator()(const std::vector<boost::dynamic_bitset<>>& i) { serialize(i); }
void StringBuilderVisitor::operator()(const std::vector<std::vector<int>>& i) {
data << "(";
data_ << "(";
for (std::vector<std::vector<int>>::const_iterator it = i.begin(); it != i.end(); ++it) {
if (it != i.begin()) {
data << ",";
data_ << ",";
}
serialize(*it);
}
data << ")";
data_ << ")";
}
void StringBuilderVisitor::operator()(const std::vector<std::vector<double>>& i) {
data << "(";
data_ << "(";
for (std::vector<std::vector<double>>::const_iterator it = i.begin(); it != i.end(); ++it) {
if (it != i.begin()) {
data << ",";
data_ << ",";
}
serialize(*it);
}
data << ")";
data_ << ")";
}
IfcWriteArgument::operator int() const { return as<int>(); }
@@ -272,13 +272,13 @@ Argument* IfcWriteArgument::operator[](unsigned int /*i*/) const { throw IfcPars
std::string IfcWriteArgument::toString(bool upper) const {
std::ostringstream str;
str.imbue(std::locale::classic());
StringBuilderVisitor v(str, upper);
container_.apply_visitor(v);
return v;
StringBuilderVisitor visitor(str, upper);
container_.apply_visitor(visitor);
return visitor;
}
unsigned int IfcWriteArgument::size() const {
SizeVisitor v;
const int size = container_.apply_visitor(v);
SizeVisitor visitor;
const int size = container_.apply_visitor(visitor);
if (size == -1) {
throw IfcParse::IfcException("Invalid cast");
}
@@ -290,27 +290,27 @@ IfcUtil::ArgumentType IfcWriteArgument::type() const {
}
// Overload to detect null values
void IfcWriteArgument::set(const aggregate_of_instance::ptr& v) {
if (v) {
container_ = v;
void IfcWriteArgument::set(const aggregate_of_instance::ptr& value) {
if (value) {
container_ = value;
} else {
container_ = boost::blank();
}
}
// Overload to detect null values
void IfcWriteArgument::set(const aggregate_of_aggregate_of_instance::ptr& v) {
if (v) {
container_ = v;
void IfcWriteArgument::set(const aggregate_of_aggregate_of_instance::ptr& value) {
if (value) {
container_ = value;
} else {
container_ = boost::blank();
}
}
// Overload to detect null values
void IfcWriteArgument::set(IfcUtil::IfcBaseInterface* const& v) {
if (v != nullptr) {
container_ = v->as<IfcUtil::IfcBaseClass>();
void IfcWriteArgument::set(IfcUtil::IfcBaseInterface* const& value) {
if (value != nullptr) {
container_ = value->as<IfcUtil::IfcBaseClass>();
} else {
container_ = boost::blank();
}
+6 -6
View File
@@ -128,18 +128,18 @@ class IFC_PARSE_API IfcWriteArgument : public Argument {
template <typename T>
typename boost::disable_if<boost::is_base_of<IfcUtil::IfcBaseInterface, typename boost::remove_pointer<T>::type>, void>::type
set(const T& t) {
container_ = t;
set(const T& type) {
container_ = type;
}
// Overload to detect null values
void set(const aggregate_of_instance::ptr& v);
void set(const aggregate_of_instance::ptr& value);
// Overload to detect null values
void set(const aggregate_of_aggregate_of_instance::ptr& v);
void set(const aggregate_of_aggregate_of_instance::ptr& value);
// Overload to detect null values
void set(IfcUtil::IfcBaseInterface* const& v);
void set(IfcUtil::IfcBaseInterface* const& value);
operator int() const;
operator bool() const;
@@ -161,7 +161,7 @@ class IFC_PARSE_API IfcWriteArgument : public Argument {
operator aggregate_of_aggregate_of_instance::ptr() const;
bool isNull() const;
Argument* operator[](unsigned int i) const;
Argument* operator[](unsigned int index) const;
std::string toString(bool upper = false) const;
unsigned int size() const;
IfcUtil::ArgumentType type() const;
+42 -42
View File
@@ -34,23 +34,23 @@ class IFC_PARSE_API aggregate_of_instance {
public:
typedef boost::shared_ptr<aggregate_of_instance> ptr;
typedef std::vector<IfcUtil::IfcBaseClass*>::const_iterator it;
void push(IfcUtil::IfcBaseClass* l);
void push(const ptr& l);
void push(IfcUtil::IfcBaseClass* instance);
void push(const ptr& instance);
it begin();
it end();
IfcUtil::IfcBaseClass* operator[](int i);
IfcUtil::IfcBaseClass* operator[](int index);
unsigned int size() const;
void reserve(unsigned capacity);
bool contains(IfcUtil::IfcBaseClass*) const;
template <class U>
typename U::list::ptr as() {
typename U::list::ptr r(new typename U::list);
typename U::list::ptr result(new typename U::list);
for (it i = begin(); i != end(); ++i) {
if ((*i)->as<U>()) {
r->push((*i)->as<U>());
result->push((*i)->as<U>());
}
}
return r;
return result;
}
void remove(IfcUtil::IfcBaseClass*);
aggregate_of_instance::ptr filtered(const std::set<const IfcParse::declaration*>& entities);
@@ -64,14 +64,14 @@ class aggregate_of {
public:
typedef boost::shared_ptr<aggregate_of<T>> ptr;
typedef typename std::vector<T*>::const_iterator it;
void push(T* t) {
if (t) {
list_.push_back(t);
void push(T* type) {
if (type) {
list_.push_back(type);
}
}
void push(ptr t) {
if (t) {
for (typename T::list::it it = t->begin(); it != t->end(); ++it) {
void push(ptr instance) {
if (instance) {
for (typename T::list::it it = instance->begin(); it != instance->end(); ++it) {
push(*it);
}
}
@@ -80,28 +80,28 @@ class aggregate_of {
it end() { return list_.end(); }
unsigned int size() const { return (unsigned int)list_.size(); }
aggregate_of_instance::ptr generalize() {
aggregate_of_instance::ptr r(new aggregate_of_instance());
aggregate_of_instance::ptr result(new aggregate_of_instance());
for (it i = begin(); i != end(); ++i) {
r->push((*i)->template as<IfcUtil::IfcBaseClass>());
result->push((*i)->template as<IfcUtil::IfcBaseClass>());
}
return r;
return result;
}
bool contains(T* t) const { return std::find(list_.begin(), list_.end(), t) != list_.end(); }
bool contains(T* type) const { return std::find(list_.begin(), list_.end(), type) != list_.end(); }
template <class U>
typename U::list::ptr as() {
typename U::list::ptr r(new typename U::list);
typename U::list::ptr result(new typename U::list);
const bool all = !U::Class().as_entity();
for (it i = begin(); i != end(); ++i) {
if (all || (*i)->declaration().is(U::Class())) {
r->push((U*)*i);
result->push((U*)*i);
}
}
return r;
return result;
}
void remove(T* t) {
typename std::vector<T*>::iterator it;
while ((it = std::find(list_.begin(), list_.end(), t)) != list_.end()) {
list_.erase(it);
void remove(T* type) {
typename std::vector<T*>::iterator iter;
while ((iter = std::find(list_.begin(), list_.end(), type)) != list_.end()) {
list_.erase(iter);
}
}
};
@@ -116,16 +116,16 @@ class IFC_PARSE_API aggregate_of_aggregate_of_instance {
typedef boost::shared_ptr<aggregate_of_aggregate_of_instance> ptr;
typedef std::vector<std::vector<IfcUtil::IfcBaseClass*>>::const_iterator outer_it;
typedef std::vector<IfcUtil::IfcBaseClass*>::const_iterator inner_it;
void push(const std::vector<IfcUtil::IfcBaseClass*>& l) {
list_.push_back(l);
void push(const std::vector<IfcUtil::IfcBaseClass*>& instance) {
list_.push_back(instance);
}
void push(const aggregate_of_instance::ptr& l) {
if (l) {
std::vector<IfcUtil::IfcBaseClass*> li;
for (std::vector<IfcUtil::IfcBaseClass*>::const_iterator jt = l->begin(); jt != l->end(); ++jt) {
li.push_back(*jt);
void push(const aggregate_of_instance::ptr& instance) {
if (instance) {
std::vector<IfcUtil::IfcBaseClass*> list;
for (std::vector<IfcUtil::IfcBaseClass*>::const_iterator iter = instance->begin(); iter != instance->end(); ++iter) {
list.push_back(*iter);
}
push(li);
push(list);
}
}
outer_it begin() const { return list_.begin(); }
@@ -149,7 +149,7 @@ class IFC_PARSE_API aggregate_of_aggregate_of_instance {
}
template <class U>
typename aggregate_of_aggregate_of<U>::ptr as() {
typename aggregate_of_aggregate_of<U>::ptr r(new aggregate_of_aggregate_of<U>);
typename aggregate_of_aggregate_of<U>::ptr result(new aggregate_of_aggregate_of<U>);
const bool all = !U::Class().as_entity();
for (outer_it outer = begin(); outer != end(); ++outer) {
const std::vector<IfcUtil::IfcBaseClass*>& from = *outer;
@@ -159,9 +159,9 @@ class IFC_PARSE_API aggregate_of_aggregate_of_instance {
to.push_back((U*)*inner);
}
}
r->push(to);
result->push(to);
}
return r;
return result;
}
};
@@ -173,7 +173,7 @@ class aggregate_of_aggregate_of {
typedef typename boost::shared_ptr<aggregate_of_aggregate_of<T>> ptr;
typedef typename std::vector<std::vector<T*>>::const_iterator outer_it;
typedef typename std::vector<T*>::const_iterator inner_it;
void push(const std::vector<T*>& t) { list_.push_back(t); }
void push(const std::vector<T*>& type) { list_.push_back(type); }
outer_it begin() { return list_.begin(); }
outer_it end() { return list_.end(); }
int size() const { return (int)list_.size(); }
@@ -184,26 +184,26 @@ class aggregate_of_aggregate_of {
}
return accum;
}
bool contains(T* t) const {
for (outer_it it = begin(); it != end(); ++it) {
const std::vector<T*>& inner = *it;
if (std::find(inner.begin(), inner.end(), t) != inner.end()) {
bool contains(T* type) const {
for (outer_it iter = begin(); iter != end(); ++iter) {
const std::vector<T*>& inner = *iter;
if (std::find(inner.begin(), inner.end(), type) != inner.end()) {
return true;
}
}
return false;
}
aggregate_of_aggregate_of_instance::ptr generalize() {
aggregate_of_aggregate_of_instance::ptr r(new aggregate_of_aggregate_of_instance());
aggregate_of_aggregate_of_instance::ptr result(new aggregate_of_aggregate_of_instance());
for (outer_it outer = begin(); outer != end(); ++outer) {
const std::vector<T*>& from = *outer;
std::vector<IfcUtil::IfcBaseClass*> to;
for (inner_it inner = from.begin(); inner != from.end(); ++inner) {
to.push_back(*inner);
}
r->push(to);
result->push(to);
}
return r;
return result;
}
};
+54 -54
View File
@@ -91,64 +91,64 @@ class stack_node {
public:
static stack_node instance(const std::string& id_in_file, IfcUtil::IfcBaseClass* inst) {
stack_node n;
n.type_ = node_instance;
n.inst_ = inst;
n.id_in_file_ = id_in_file;
return n;
stack_node node;
node.type_ = node_instance;
node.inst_ = inst;
node.id_in_file_ = id_in_file;
return node;
}
static stack_node instance_attribute(IfcUtil::IfcBaseClass* inst, int idx) {
stack_node n;
n.type_ = node_instance_attribute;
n.inst_ = inst;
n.idx_ = idx;
return n;
stack_node node;
node.type_ = node_instance_attribute;
node.inst_ = inst;
node.idx_ = idx;
return node;
}
static stack_node aggregate(IfcUtil::IfcBaseClass* inst, int idx) {
stack_node n;
n.type_ = node_aggregate;
n.inst_ = inst;
n.idx_ = idx;
return n;
stack_node node;
node.type_ = node_aggregate;
node.inst_ = inst;
node.idx_ = idx;
return node;
}
static stack_node aggregate_element(const IfcParse::parameter_type* aggregate_elem_type, int idx) {
stack_node n;
n.type_ = node_aggregate_element;
n.idx_ = idx;
n.aggregate_elem_type_ = aggregate_elem_type;
return n;
stack_node node;
node.type_ = node_aggregate_element;
node.idx_ = idx;
node.aggregate_elem_type_ = aggregate_elem_type;
return node;
}
static stack_node inverse(IfcUtil::IfcBaseClass* inst, const IfcParse::inverse_attribute* inv) {
stack_node n;
n.type_ = node_inverse;
n.inst_ = inst;
n.inv_ = inv;
return n;
stack_node node;
node.type_ = node_inverse;
node.inst_ = inst;
node.inv_ = inv;
return node;
}
static stack_node select(IfcUtil::IfcBaseClass* inst, int idx) {
stack_node n;
n.type_ = node_select;
n.inst_ = inst;
n.idx_ = idx;
return n;
stack_node node;
node.type_ = node_select;
node.inst_ = inst;
node.idx_ = idx;
return node;
}
static stack_node header() {
stack_node n;
n.type_ = node_header;
return n;
stack_node node;
node.type_ = node_header;
return node;
};
static stack_node header_entry(const std::string& tagname) {
stack_node n;
n.type_ = node_header_entry;
n.tagname_ = tagname;
return n;
stack_node node;
node.type_ = node_header_entry;
node.tagname_ = tagname;
return node;
};
node_type ntype() const { return type_; }
@@ -161,19 +161,19 @@ class stack_node {
const IfcParse::parameter_type* aggregate_elem_type() const { return aggregate_elem_type_; }
std::string repr() const {
std::stringstream ss;
std::stringstream stream;
static const char* const node_type_names[] = {"empty", "inst", "attr", "aggr", "agelem", "inv", "sel", "head", "hdentry"};
ss << "[" << node_type_names[type_] << "] ";
stream << "[" << node_type_names[type_] << "] ";
if (inst_ != nullptr) {
ss << inst_->declaration().name() << " ";
stream << inst_->declaration().name() << " ";
}
if (type_ == node_aggregate) {
ss << "{" << aggregate_elements.size() << " elems} ";
stream << "{" << aggregate_elements.size() << " elems} ";
}
if (idx_ != -1) {
ss << idx_ << " ";
stream << idx_ << " ";
}
return ss.str();
return stream.str();
}
};
@@ -190,7 +190,7 @@ template <typename T>
std::vector<T> split(const std::string& value) {
std::vector<std::string> strs;
boost::split(
strs, value, [](char c) { return c == ' '; }, boost::token_compress_on);
strs, value, [](char character) { return character == ' '; }, boost::token_compress_on);
std::vector<T> r(strs.size());
boost::copy(strs | boost::adaptors::transformed([](const std::string& s) {
return boost::lexical_cast<T>(s);
@@ -209,13 +209,13 @@ Argument* parse_attribute_value(const IfcParse::parameter_type* ty, const std::s
} else if (cpp_type == IfcUtil::Argument_ENUMERATION) {
const auto* enum_type = ty->as_named_type()->declared_type()->as_enumeration_type();
std::vector<std::string>::const_iterator it = std::find(
std::vector<std::string>::const_iterator iter = std::find(
enum_type->enumeration_items().begin(),
enum_type->enumeration_items().end(),
boost::to_upper_copy(value));
if (it != enum_type->enumeration_items().end()) {
v->set(IfcWrite::IfcWriteArgument::EnumerationReference(it - enum_type->enumeration_items().begin(), it->c_str()));
if (iter != enum_type->enumeration_items().end()) {
v->set(IfcWrite::IfcWriteArgument::EnumerationReference(iter - enum_type->enumeration_items().begin(), iter->c_str()));
}
} else if (cpp_type == IfcUtil::Argument_INT) {
v->set(boost::lexical_cast<int>(value));
@@ -248,12 +248,12 @@ static void end_element(void* user, const xmlChar* tag) {
if (!state->stack.empty() && state->stack.back().ntype() == stack_node::node_aggregate) {
const auto& back = state->stack.back();
auto& elems = state->stack.back().aggregate_elements;
auto* li = new IfcParse::ArgumentList(elems.size());
auto* list = new IfcParse::ArgumentList(elems.size());
size_t i = 0;
for (auto& elem : elems) {
li->arguments()[i++] = elem;
list->arguments()[i++] = elem;
}
back.inst()->data().attributes()[back.idx()] = li;
back.inst()->data().attributes()[back.idx()] = list;
}
if (state->dialect == ifcxml_dialect_ifc2x3 && state->stack.back().ntype() == stack_node::node_instance) {
@@ -274,14 +274,14 @@ static void end_element(void* user, const xmlChar* tag) {
}
}
static void process_characters(void* user, const xmlChar* ch, int len) {
static void process_characters(void* user, const xmlChar* character, int len) {
ifcxml_parse_state* state = (ifcxml_parse_state*)user;
if (state->file == nullptr) {
return;
}
std::string txt((char*)ch, len);
std::string txt((char*)character, len);
stack_node::node_type state_type = stack_node::stack_empty;
if (!state->stack.empty()) {
@@ -348,8 +348,8 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
std::cout << "stack:" << std::endl;
{
int i = 1;
for (auto& n : state->stack) {
std::cout << " " << (i++) << ":" << n.repr() << std::endl;
for (auto& node : state->stack) {
std::cout << " " << (i++) << ":" << node.repr() << std::endl;
}
}
std::cout << std::string(state->stack.size(), ' ') << "<" << tagname << ">";