2012-08-11 13:24:08 +00:00
|
|
|
/********************************************************************************
|
2023-09-18 16:13:44 +02:00
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
2011-05-08 11:04:32 +00:00
|
|
|
|
2011-07-11 09:33:18 +00:00
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* This file provides functions for loading an IFC file into memory and access *
|
2026-08-19 18:16:59 +05:00
|
|
|
* its entities either by ID, by an IfcSchema::Type or by reference *
|
2011-07-11 09:33:18 +00:00
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
2011-05-08 11:04:32 +00:00
|
|
|
#ifndef IFCPARSE_H
|
|
|
|
|
#define IFCPARSE_H
|
|
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
#include "argument.h"
|
2016-07-20 22:49:32 +03:00
|
|
|
#include "ifc_parse_api.h"
|
2026-01-04 10:40:02 +01:00
|
|
|
#include "express.h"
|
2026-03-31 15:32:36 +02:00
|
|
|
#include "character_decoder.h"
|
|
|
|
|
#include "file_reader.h"
|
2024-03-14 10:26:51 +01:00
|
|
|
#include "macros.h"
|
2025-08-25 12:45:10 +02:00
|
|
|
#include "storage.h"
|
2016-05-29 18:12:57 +06:00
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
#include <boost/dynamic_bitset.hpp>
|
2026-08-08 15:37:53 +02:00
|
|
|
#include <memory>
|
2023-09-17 12:30:17 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2011-05-08 11:04:32 +00:00
|
|
|
|
2025-09-30 18:11:33 +05:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
extern IFC_PARSE_API const char *IFCOPENSHELL_VERSION;
|
2024-03-14 10:26:51 +01:00
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
namespace ifcopenshell {
|
2011-05-08 11:04:32 +00:00
|
|
|
|
2026-08-22 13:12:36 +02:00
|
|
|
IFC_PARSE_API std::string encode_spf_string(const std::string& value);
|
|
|
|
|
|
|
|
|
|
IFC_PARSE_API std::string decode_spf_string(const std::string& value);
|
|
|
|
|
|
2026-09-14 07:08:48 +10:00
|
|
|
/// What a pass over the tokens has to produce. The parser needs every
|
|
|
|
|
/// value; the lazy index only needs to know where the tokens are and which
|
|
|
|
|
/// of them are instance names, so it ends strings without decoding them and
|
|
|
|
|
/// passes over numbers, enumerations and binaries. The choice is a template
|
|
|
|
|
/// parameter of spf_lexer::next(), so each pass compiles to its own loop.
|
|
|
|
|
struct full_tokens {
|
|
|
|
|
static constexpr bool decode_strings = true;
|
|
|
|
|
static constexpr bool decode_values = true;
|
|
|
|
|
};
|
|
|
|
|
struct index_tokens {
|
|
|
|
|
static constexpr bool decode_strings = false;
|
|
|
|
|
static constexpr bool decode_values = false;
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
/// A stream of tokens to be read from a file_reader.
|
2026-03-27 20:45:13 +01:00
|
|
|
template <typename Reader>
|
2026-03-31 15:32:36 +02:00
|
|
|
class IFC_PARSE_API spf_lexer {
|
2023-09-17 12:30:17 +02:00
|
|
|
private:
|
2026-03-31 15:32:36 +02:00
|
|
|
character_decoder<Reader>* decoder_;
|
2026-08-08 13:58:39 +02:00
|
|
|
ifcopenshell::logger& logger_;
|
2026-08-19 18:16:59 +05:00
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
size_t skip_whitespace() const;
|
|
|
|
|
size_t skip_comment() const;
|
2023-09-17 12:30:17 +02:00
|
|
|
|
2026-03-26 15:49:28 +01:00
|
|
|
mutable std::vector<std::unique_ptr<std::array<std::string, 16>>> stringpool_;
|
|
|
|
|
mutable size_t pool_index = 0;
|
|
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
public:
|
2026-08-19 18:16:59 +05:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
spf_lexer(const spf_lexer&) = delete;
|
|
|
|
|
spf_lexer& operator=(const spf_lexer&) = delete;
|
|
|
|
|
|
2026-03-31 15:32:36 +02:00
|
|
|
std::string& get_temp_string() const;
|
|
|
|
|
void reset_pool() const {
|
2026-03-26 15:49:28 +01:00
|
|
|
pool_index = 0;
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
2026-03-31 15:32:36 +02:00
|
|
|
void pop_pool_entry() {
|
2026-03-26 15:49:28 +01:00
|
|
|
if (pool_index > 0) {
|
|
|
|
|
--pool_index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 20:45:13 +01:00
|
|
|
Reader* stream;
|
2026-03-31 15:32:36 +02:00
|
|
|
// file* file;
|
2026-08-08 13:58:39 +02:00
|
|
|
spf_lexer(Reader* stream, ifcopenshell::logger& logger = ifcopenshell::logger::root());
|
2026-09-14 07:08:48 +10:00
|
|
|
// The next token. With index_tokens a string, number, enumeration or
|
|
|
|
|
// binary comes back as Token_LITERAL (Token_STRING for a string) with
|
|
|
|
|
// only its position; names, keywords and operators are always read.
|
|
|
|
|
template <typename Policy = full_tokens>
|
2026-03-31 15:32:36 +02:00
|
|
|
token next();
|
|
|
|
|
~spf_lexer();
|
2026-03-26 15:49:28 +01:00
|
|
|
// void TokenString(size_t offset, std::string& result);
|
2023-09-17 12:30:17 +02:00
|
|
|
};
|
|
|
|
|
|
2026-08-08 07:42:45 +02:00
|
|
|
IFC_PARSE_API std::vector<express::base> traverse(const express::base& instance, int max_depth = -1);
|
2023-09-17 12:30:17 +02:00
|
|
|
|
2026-08-08 07:42:45 +02:00
|
|
|
IFC_PARSE_API std::vector<express::base> traverse_breadth_first(const express::base& instance, int max_depth = -1);
|
2026-03-31 15:32:36 +02:00
|
|
|
} // namespace ifcopenshell
|
2023-09-17 12:30:17 +02:00
|
|
|
|
2026-03-31 18:23:13 +02:00
|
|
|
IFC_PARSE_API std::ostream& operator<<(std::ostream& stream, const ifcopenshell::file& file);
|
2012-08-11 13:24:08 +00:00
|
|
|
|
2011-05-08 11:04:32 +00:00
|
|
|
#endif
|