MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / asBinary

Method asBinary

src/ifcparse/IfcParse.cpp:465–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

463}
464
465boost::dynamic_bitset<> TokenFunc::asBinary(const Token& token) {
466 const std::string& str = asStringRef(token);
467 if (str.empty()) {
468 throw IfcException("Token is not a valid binary sequence");
469 }
470
471 std::string::const_iterator it = str.begin();
472 int n = *it - '0';
473 if ((n < 0 || n > 3) || (str.size() == 1 && n != 0)) {
474 throw IfcException("Token is not a valid binary sequence");
475 }
476
477 ++it;
478 unsigned i = ((unsigned)str.size() - 1) * 4 - n;
479 boost::dynamic_bitset<> bitset(i);
480
481 for (; it != str.end(); ++it) {
482 const std::string::value_type& c = *it;
483 int value = (c < 'A') ? (c - '0') : (c - 'A' + 10);
484 for (unsigned j = 0; j < 4; ++j) {
485 if (i-- == 0) {
486 break;
487 }
488 if ((value & (1 << (3 - j))) != 0) {
489 bitset.set(i);
490 }
491 }
492 }
493
494 return bitset;
495}
496
497std::string TokenFunc::toString(const Token& token) {
498 std::string result;

Callers

nothing calls this directly

Calls 5

emptyMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
endMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected