-
-
Notifications
You must be signed in to change notification settings - Fork 900
Expand file tree
/
Copy pathIfcParse.h
More file actions
136 lines (120 loc) · 6.17 KB
/
IfcParse.h
File metadata and controls
136 lines (120 loc) · 6.17 KB
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
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
/********************************************************************************
* *
* This file provides functions for loading an IFC file into memory and access *
* its entities either by ID, by an IfcSchema::Type or by reference *
* *
********************************************************************************/
#ifndef IFCPARSE_H
#define IFCPARSE_H
#include "aggregate_of_instance.h"
#include "Argument.h"
#include "ifc_parse_api.h"
#include "IfcBaseClass.h"
#include "IfcCharacterDecoder.h"
#include "FileReader.h"
#include "macros.h"
#include "storage.h"
#include <boost/dynamic_bitset.hpp>
#include <boost/shared_ptr.hpp>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
extern const char *IFCOPENSHELL_VERSION;
namespace IfcParse {
/// Provides functions to convert Tokens to binary data
/// Tokens are merely offsets to where they can be read in the file
class IFC_PARSE_API TokenFunc {
private:
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& token);
/// Returns whether the token can be interpreted as an identifier
static bool isIdentifier(const Token& token);
/// Returns whether the token can be interpreted as a syntactical operator
static bool isOperator(const Token& token);
/// Returns whether the token is a given operator
static bool isOperator(const Token& token, char character);
/// Returns whether the token can be interpreted as an enumerated value
static bool isEnumeration(const Token& token);
/// Returns whether the token can be interpreted as a datatype name
static bool isKeyword(const Token& token);
/// Returns whether the token can be interpreted as an integer
static bool isInt(const Token& token);
/// Returns whether the token can be interpreted as a boolean
static bool isBool(const Token& token);
/// Returns whether the token can be interpreted as a logical
static bool isLogical(const Token& token);
/// Returns whether the token can be interpreted as a floating point number
static bool isFloat(const Token& token);
/// Returns whether the token can be interpreted as a binary type
static bool isBinary(const Token& token);
/// Returns the token interpreted as an integer
static int asInt(const Token& token);
/// Returns the token interpreted as an identifier
static int asIdentifier(const Token& token);
/// Returns the token interpreted as an boolean (.T. or .F.)
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& token);
/// Returns the token as a floating point number
static double asFloat(const Token& token);
/// Returns the token as a string (without the dot or apostrophe)
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& token);
/// Returns the token as a string (without the dot or apostrophe)
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& token);
};
//
// Functions for creating Tokens from an arbitary file offset
// The first 4 bits are reserved for Tokens of type ()=,;$*
//
Token OperatorTokenPtr(IfcSpfLexer* tokens, size_t start, char data);
Token GeneralTokenPtr(IfcSpfLexer* tokens, size_t start, const std::string& data);
/// A stream of tokens to be read from a FileReader.
class IFC_PARSE_API IfcSpfLexer {
private:
IfcCharacterDecoder* decoder_;
size_t skipWhitespace() const;
size_t skipComment() const;
public:
std::string& GetTempString() const {
static my_thread_local std::string string;
return string;
}
FileReader* stream;
// IfcFile* file;
IfcSpfLexer(FileReader* stream);
Token Next();
~IfcSpfLexer();
void TokenString(size_t offset, std::string& result);
};
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& out, const IfcParse::IfcFile& file);
#endif