-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathIddObject.cpp
More file actions
843 lines (682 loc) · 25.3 KB
/
IddObject.cpp
File metadata and controls
843 lines (682 loc) · 25.3 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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
/***********************************************************************************************************************
* OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
* See also https://openstudio.net/license
***********************************************************************************************************************/
#include "IddObject.hpp"
#include "IddObject_Impl.hpp"
#include "ExtensibleIndex.hpp"
#include "IddRegex.hpp"
#include <utilities/idd/IddFactory.hxx>
#include <utilities/idd/IddEnums.hxx>
#include "IddKey.hpp"
#include "CommentRegex.hpp"
#include "../core/Assert.hpp"
#include "../core/ASCIIStrings.hpp"
#include <boost/lexical_cast.hpp>
using std::string;
using std::vector;
using boost::regex;
using boost::smatch;
using boost::regex_replace;
using boost::replace_all;
namespace openstudio {
namespace detail {
// CONSTRUCTORS
/// default constructor for serialization
IddObject_Impl::IddObject_Impl() : m_name("Catchall"), m_type(IddObjectType::Catchall) {
m_properties.extensible = true;
m_properties.numExtensible = 1;
m_properties.hasURL = false;
OptionalIddField oField = IddField::load("Object Type", "A1, \\field Object Type \n \\type alpha", m_name);
m_fields.push_back(*oField);
oField = IddField::load("Generic Data Field", "A2; \\field Generic Data Field \n \\type alpha \n \\begin-extensible", m_name);
OS_ASSERT(oField);
m_extensibleFields.push_back(*oField);
}
// GETTERS
std::string IddObject_Impl::name() const {
return m_name;
}
IddObjectType IddObject_Impl::type() const {
return m_type;
}
std::string IddObject_Impl::group() const {
return m_group;
}
const IddObjectProperties& IddObject_Impl::properties() const {
return m_properties;
}
const IddFieldVector& IddObject_Impl::nonextensibleFields() const {
return m_fields;
}
const IddFieldVector& IddObject_Impl::extensibleGroup() const {
return m_extensibleFields;
}
boost::optional<IddField> IddObject_Impl::getField(unsigned index) const {
OptionalIddField field;
// is index in the regular fields
if (index < m_fields.size()) {
field = m_fields[index];
} else if (!m_extensibleFields.empty()) {
// if not subtract out fields size and mod by number of extensible fields
index = index - m_fields.size();
index = index % m_extensibleFields.size();
field = m_extensibleFields[index];
}
return field;
}
boost::optional<IddField> IddObject_Impl::getField(const std::string& fieldName) const {
OptionalIddField result;
// look in fields
for (const IddField& field : m_fields) {
if (boost::iequals(field.name(), fieldName)) {
result = field;
break;
}
}
// look in extensible fields
if (!result) {
for (const IddField& field : m_extensibleFields) {
if (boost::iequals(field.name(), fieldName)) {
result = field;
break;
}
}
}
return result;
}
boost::optional<int> IddObject_Impl::getFieldIndex(const std::string& fieldName) const {
OptionalInt result;
int index = 0;
// look in fields
for (const IddField& field : m_fields) {
if (boost::iequals(field.name(), fieldName)) {
result = index;
break;
}
++index;
}
// look in extensible fields
if (!result) {
for (const IddField& field : m_extensibleFields) {
if (boost::iequals(field.name(), fieldName)) {
result = index;
break;
}
++index;
}
}
return result;
}
// SETTERS
void IddObject_Impl::insertHandleField() {
if (!hasHandleField()) {
std::stringstream fieldText;
fieldText << " A1, \\field Handle" << '\n' << " \\type handle" << '\n' << " \\required-field";
IddField handleField = IddField::load("Handle", fieldText.str(), m_name).get();
auto it = m_fields.insert(m_fields.begin(), handleField);
++it;
for (auto itEnd = m_fields.end(); it != itEnd; ++it) {
it->incrementFieldId(); // by default, applies only to 'A'-type fields
}
it = m_extensibleFields.begin();
for (auto itEnd = m_extensibleFields.end(); it != itEnd; ++it) {
it->incrementFieldId(); // by default, applies only to 'A'-type fields
}
++m_properties.minFields;
if (m_properties.maxFields) {
unsigned newMaxFields = m_properties.maxFields.get() + 1;
m_properties.maxFields = newMaxFields;
}
}
}
// QUERIES
unsigned IddObject_Impl::numFields() const {
return m_fields.size();
}
unsigned IddObject_Impl::numFieldsInDefaultObject() const {
unsigned result = m_properties.minFields;
// check for non-extensible required fields
unsigned index = result;
unsigned n = numFields();
while (index < n) {
if (m_fields[index].properties().required) {
result = index + 1;
}
++index;
}
// do not pre-create extensible groups, so user can directly call
// .pushExtensibleGroup, without preceding it with a .clearExtensibleGroups.
if (result > n) {
result = n;
}
return result;
}
bool IddObject_Impl::isVersionObject() const {
return (type() == IddObjectType::Version) || (type() == IddObjectType::OS_Version) || (boost::regex_match(name(), iddRegex::versionObjectName()));
}
bool IddObject_Impl::isNonextensibleField(unsigned index) const {
if (index < m_fields.size()) {
return true;
}
return false;
}
bool IddObject_Impl::isExtensibleField(unsigned index) const {
if ((index >= m_fields.size()) && (m_properties.extensible)) {
return true;
}
return false;
}
bool IddObject_Impl::hasHandleField() const {
return ((!m_fields.empty()) && (m_fields[0].properties().type == IddFieldType::HandleType));
}
bool IddObject_Impl::hasNameField() const {
if (m_nameFieldCache) {
return m_nameFieldCache->first;
}
unsigned index = 0;
if (hasHandleField()) {
index = 1;
}
bool result = ((m_fields.size() > index) && (m_fields[index].isNameField()));
m_nameFieldCache = std::pair<bool, unsigned>(result, index);
return result;
}
boost::optional<unsigned> IddObject_Impl::nameFieldIndex() const {
if (hasNameField()) {
return m_nameFieldCache->second;
}
return boost::none;
}
bool IddObject_Impl::isRequiredField(unsigned index) const {
OptionalIddField iddField = getField(index);
if (iddField) {
return iddField->properties().required;
}
return false;
}
bool IddObject_Impl::hasURL() const {
return m_properties.hasURL;
}
ExtensibleIndex IddObject_Impl::extensibleIndex(unsigned index) const {
if (!isExtensibleField(index)) {
LOG_AND_THROW("Field " << index << " is not an extensible field in IddObject " << name() << ".");
}
ExtensibleIndex result(0, 0);
result.field = (index - m_fields.size()) % m_properties.numExtensible;
result.group = (index - result.field - m_fields.size()) / m_properties.numExtensible;
return result;
}
unsigned IddObject_Impl::index(ExtensibleIndex extensibleIndex) const {
if (!m_properties.extensible) {
LOG_AND_THROW("IddObject " << name() << " does not have extensible fields.");
}
if (extensibleIndex.field >= m_properties.numExtensible) {
LOG_AND_THROW("IddObject " << name() << " only has " << m_properties.numExtensible
<< " fields in its extensible group. Therefore, a ExtensibleIndex.field of " << extensibleIndex.field
<< " is invalid.");
}
return m_fields.size() + extensibleIndex.group * m_properties.numExtensible + extensibleIndex.field;
}
std::vector<std::string> IddObject_Impl::references() const {
std::vector<std::string> result;
if (OptionalUnsigned index = nameFieldIndex()) {
result = m_fields[*index].properties().references;
// To ensure uniqueness of name within a given class, we add a fake reference by class
// https://github.com/NREL/OpenStudio/issues/3079
//if (result.empty()) {
std::string ref = name();
result.push_back(ref + "UniqueNames");
//}
} else {
std::string n = name();
if (n == "OS:PortList") {
result.push_back("ConnectionObject");
result.push_back("PortLists");
} else if (n == "OS:Connection") {
result.push_back("ConnectionNames");
}
}
return result;
}
std::set<std::string> IddObject_Impl::objectLists() const {
std::set<std::string> result;
for (const IddField& field : m_fields) {
const IddFieldProperties& properties = field.properties();
result.insert(properties.objectLists.begin(), properties.objectLists.end());
}
for (const IddField& field : m_extensibleFields) {
const IddFieldProperties& properties = field.properties();
result.insert(properties.objectLists.begin(), properties.objectLists.end());
}
return result;
}
std::set<std::string> IddObject_Impl::objectLists(unsigned index) const {
std::set<std::string> result;
if (isNonextensibleField(index)) {
const IddFieldProperties& properties = m_fields[index].properties();
result.insert(properties.objectLists.begin(), properties.objectLists.end());
} else if (isExtensibleField(index)) {
ExtensibleIndex eIndex = extensibleIndex(index);
const IddFieldProperties& properties = m_extensibleFields[eIndex.field].properties();
result.insert(properties.objectLists.begin(), properties.objectLists.end());
}
return result;
}
UnsignedVector IddObject_Impl::objectListFields() const {
UnsignedVector result;
for (unsigned index = 0; index < m_fields.size(); ++index) {
if (m_fields[index].isObjectListField()) {
result.push_back(index);
}
}
for (unsigned index = 0; index < m_extensibleFields.size(); ++index) {
if (m_extensibleFields[index].isObjectListField()) {
result.push_back(m_fields.size() + index);
}
}
return result;
}
std::vector<unsigned> IddObject_Impl::urlFields() const {
UnsignedVector result;
for (unsigned index = 0; index < m_fields.size(); ++index) {
if (m_fields[index].properties().type == IddFieldType::URLType) {
result.push_back(index);
}
}
for (unsigned index = 0; index < m_extensibleFields.size(); ++index) {
if (m_extensibleFields[index].properties().type == IddFieldType::URLType) {
result.push_back(m_fields.size() + index);
}
}
return result;
}
bool IddObject_Impl::operator==(const IddObject_Impl& other) const {
if (this == &other) {
return true;
}
if (m_type != other.m_type) {
return false;
}
if (m_name != other.m_name) {
return false;
}
if (m_group != other.m_group) {
return false;
}
if (m_properties != other.m_properties) {
return false;
}
if (m_fields != other.m_fields) {
return false;
}
if (m_extensibleFields != other.m_extensibleFields) {
return false;
}
return true;
}
// SERIALIZATION
std::shared_ptr<IddObject_Impl> IddObject_Impl::load(const std::string& name, const std::string& group, const std::string& text,
IddObjectType type) {
std::shared_ptr<IddObject_Impl> result;
result = std::shared_ptr<IddObject_Impl>(new IddObject_Impl(name, group, type));
try {
result->parse(text);
} catch (...) {
return {};
}
return result;
}
/// print
std::ostream& IddObject_Impl::print(std::ostream& os) const {
if (m_fields.empty() && m_extensibleFields.empty()) {
os << m_name << ";" << '\n';
m_properties.print(os);
os << '\n';
} else {
os << m_name << "," << '\n';
m_properties.print(os);
bool extensibleFields = !m_extensibleFields.empty();
for (auto it = m_fields.begin(), itend = m_fields.end(); it != itend; ++it) {
if (extensibleFields) {
it->print(os, false); // don't print ; just yet
} else {
it->print(os, (it == itend - 1));
}
}
for (auto it = m_extensibleFields.begin(), itend = m_extensibleFields.end(); it != itend; ++it) {
it->print(os, (it == itend - 1));
}
os << '\n';
}
return os;
}
// PRIVATE
IddObject_Impl::IddObject_Impl(const string& name, const string& group, IddObjectType type) : m_name(name), m_group(group), m_type(type) {}
void IddObject_Impl::parse(const std::string& text) {
smatch matches;
if (boost::regex_search(text, matches, iddRegex::objectAndFields())) {
// find and parse the object text
string objectText(matches[1].first, matches[1].second);
parseObject(objectText);
// find and parse the fields text
string fieldsText(matches[2].first, matches[2].second);
parseFields(fieldsText);
} else if (boost::regex_match(text, iddRegex::objectNoFields())) {
// there are no fields in this object, it is all object text
parseObject(text);
} else {
// error
LOG_AND_THROW("Unexpected pattern '" << text << "' found in object '" << m_name << "'");
}
// remove existing extensible fields and add them the the extensible list
if (m_properties.extensible) {
makeExtensible();
}
}
void IddObject_Impl::makeExtensible() {
// number of fields in extensible group
unsigned numExtensible = m_properties.numExtensible;
// check that numExtensible > 0
if (numExtensible == 0) {
LOG(Error, "Extensible length 0 in object '" << m_name << "'");
return;
}
// find the begin extensible field, there should be only one
auto extensibleBegin = m_fields.end();
for (auto it = m_fields.begin(), itend = m_fields.end(); it != itend; ++it) {
if (it->properties().beginExtensible) {
extensibleBegin = it;
break;
}
}
// no extensible begin found
if (extensibleBegin == m_fields.end()) {
LOG(Error, "No begin-extensible field detected in object '" << m_name << "'");
return;
}
// extensible begin is too close to the end of the field list
if ((extensibleBegin + numExtensible) > m_fields.end()) {
LOG(Error, "Extensible fields begin too close to end of fields in object '" << m_name << "'");
return;
}
// copy extensible fields
m_extensibleFields = IddFieldVector(extensibleBegin, extensibleBegin + numExtensible);
// remove all the extensible fields from the field list
m_fields.resize(extensibleBegin - m_fields.begin());
// regexs that match extensible fields
std::string replace;
// replace names of extensible fields so they do not contain numbers
// e.g. "Vertex 1 X-coordinate" -> "Vertex X-coordinate"
for (IddField& extensibleField : m_extensibleFields) {
std::string extensibleFieldName = extensibleField.name();
extensibleFieldName = regex_replace(extensibleFieldName, iddRegex::numberAndPrecedingSpace(), replace, boost::format_first_only);
openstudio::ascii_trim(extensibleFieldName);
extensibleField.setName(extensibleFieldName);
}
// figure out numExtensibleGroupsRequired
if (m_properties.minFields > 0) {
unsigned minFields = m_properties.minFields;
if (minFields > m_fields.size()) {
double numerator(minFields - (unsigned)m_fields.size());
double denominator(numExtensible);
m_properties.numExtensibleGroupsRequired = unsigned(std::ceil(numerator / denominator));
}
}
}
void IddObject_Impl::parseObject(const std::string& text) {
// find the object name and the property text
smatch matches;
string propertiesText;
if (boost::regex_search(text, matches, iddRegex::line())) {
std::string objectName = string(matches[1].first, matches[1].second);
openstudio::ascii_trim(objectName);
if (!boost::equals(m_name, objectName)) {
LOG_AND_THROW("Object name '" << objectName << "' does not match expected '" << m_name << "'");
}
propertiesText = string(matches[2].first, matches[2].second);
openstudio::ascii_trim(propertiesText);
} else {
LOG_AND_THROW("Could not determine object name from text '" << text << "'");
}
while (boost::regex_search(propertiesText, matches, iddRegex::metaDataComment())) {
string thisProperty(matches[1].first, matches[1].second);
openstudio::ascii_trim(thisProperty);
parseProperty(thisProperty);
propertiesText = string(matches[2].first, matches[2].second);
openstudio::ascii_trim(propertiesText);
}
if (!((boost::regex_match(propertiesText, commentRegex::whitespaceOnlyBlock()))
|| (boost::regex_match(propertiesText, iddRegex::commentOnlyLine())))) {
LOG_AND_THROW("Could not process properties text '" << propertiesText << "' in object '" << m_name << "'");
}
}
void IddObject_Impl::parseProperty(const std::string& text) {
smatch matches;
if (boost::regex_search(text, matches, iddRegex::memoProperty())) {
string memo(matches[1].first, matches[1].second);
openstudio::ascii_trim(memo);
if (m_properties.memo.empty()) {
m_properties.memo = memo;
} else {
m_properties.memo += "\n" + memo;
}
} else if (boost::regex_match(text, iddRegex::uniqueProperty())) {
m_properties.unique = true;
} else if (boost::regex_match(text, iddRegex::requiredObjectProperty())) {
m_properties.required = true;
} else if (boost::regex_match(text, iddRegex::obsoleteProperty())) {
m_properties.obsolete = true;
} else if (boost::regex_match(text, iddRegex::hasurlProperty())) {
m_properties.hasURL = true;
} else if (boost::regex_search(text, matches, iddRegex::extensibleProperty())) {
m_properties.extensible = true;
string numExtensible(matches[1].first, matches[1].second);
m_properties.numExtensible = boost::lexical_cast<unsigned>(numExtensible);
} else if (boost::regex_search(text, matches, iddRegex::formatProperty())) {
string format(matches[1].first, matches[1].second);
openstudio::ascii_trim(format);
m_properties.format = format;
} else if (boost::regex_search(text, matches, iddRegex::minFieldsProperty())) {
string minFields(matches[1].first, matches[1].second);
m_properties.minFields = boost::lexical_cast<unsigned>(minFields);
} else if (boost::regex_search(text, matches, iddRegex::maxFieldsProperty())) {
string maxFields(matches[1].first, matches[1].second);
m_properties.maxFields = boost::lexical_cast<unsigned>(maxFields);
} else {
// error, unknown property
LOG_AND_THROW("Unknown property text '" << text << "' in object '" << m_name << "'");
}
}
void IddObject_Impl::parseFields(const std::string& text) {
static const boost::regex field_start("[AN][0-9]+[\\s]*[,;]");
auto begin = text.begin();
const auto end = text.end();
boost::match_results<std::string::const_iterator> matches;
if (boost::regex_search(begin, end, matches, field_start)) {
begin = matches[0].first;
if (begin != text.begin()) {
LOG_AND_THROW("Could not process field text '" << text << "' in object ', start is not where expected" << m_name << "'");
}
} else {
return;
}
std::string::const_iterator field_end;
while (begin != end) {
if (boost::regex_search(begin + 1, end, matches, field_start)) {
field_end = matches[0].first;
} else {
field_end = end;
}
// take the text of the last field
string fieldText(begin, field_end);
begin = field_end;
string fieldName;
// peak ahead to find the field name for indexing in map
smatch nameMatches;
if (boost::regex_search(fieldText, nameMatches, iddRegex::name())) {
fieldName = string(nameMatches[1].first, nameMatches[1].second);
openstudio::ascii_trim(fieldName);
} else if (boost::regex_search(fieldText, nameMatches, iddRegex::field())) {
// if no explicit field name, use the type and number
string fieldTypeChar(nameMatches[1].first, nameMatches[1].second);
openstudio::ascii_trim(fieldTypeChar);
string fieldTypeNumber(nameMatches[2].first, nameMatches[2].second);
openstudio::ascii_trim(fieldTypeNumber);
fieldName = fieldTypeChar + fieldTypeNumber;
} else {
// cannot find the field name
LOG_AND_THROW("Cannot determine field name from text '" << fieldText << "'");
}
// construct the field
OptionalIddField oField = IddField::load(fieldName, fieldText, m_name);
if (!oField) {
LOG_AND_THROW("Cannot parse IddField text '" << fieldText << "'.");
}
// construct a new object and put it in the object list and object map
m_fields.push_back(*oField);
}
}
} // namespace detail
// CONSTRUCTORS
IddObject::IddObject() : m_impl(std::shared_ptr<detail::IddObject_Impl>(new detail::IddObject_Impl())) {}
IddObject::IddObject(const IddObject& other) = default;
// GETTERS
std::string IddObject::name() const {
return m_impl->name();
}
IddObjectType IddObject::type() const {
return m_impl->type();
}
std::string IddObject::group() const {
return m_impl->group();
}
const IddObjectProperties& IddObject::properties() const {
return m_impl->properties();
}
const IddFieldVector& IddObject::nonextensibleFields() const {
return m_impl->nonextensibleFields();
}
const IddFieldVector& IddObject::extensibleGroup() const {
return m_impl->extensibleGroup();
}
boost::optional<IddField> IddObject::getField(unsigned index) const {
return m_impl->getField(index);
}
boost::optional<IddField> IddObject::getField(const std::string& fieldName) const {
return m_impl->getField(fieldName);
}
boost::optional<int> IddObject::getFieldIndex(const std::string& fieldName) const {
return m_impl->getFieldIndex(fieldName);
}
// SETTERS
void IddObject::insertHandleField() {
return m_impl->insertHandleField();
}
// QUERIES
unsigned IddObject::numFields() const {
return m_impl->numFields();
}
unsigned IddObject::numFieldsInDefaultObject() const {
return m_impl->numFieldsInDefaultObject();
}
bool IddObject::isVersionObject() const {
return m_impl->isVersionObject();
}
bool IddObject::isNonextensibleField(unsigned index) const {
return m_impl->isNonextensibleField(index);
}
bool IddObject::isExtensibleField(unsigned index) const {
return m_impl->isExtensibleField(index);
}
bool IddObject::hasHandleField() const {
return m_impl->hasHandleField();
}
bool IddObject::hasNameField() const {
return m_impl->hasNameField();
}
boost::optional<unsigned> IddObject::nameFieldIndex() const {
return m_impl->nameFieldIndex();
}
bool IddObject::isRequiredField(unsigned index) const {
return m_impl->isRequiredField(index);
}
bool IddObject::hasURL() const {
return m_impl->hasURL();
}
ExtensibleIndex IddObject::extensibleIndex(unsigned index) const {
return m_impl->extensibleIndex(index);
}
unsigned IddObject::index(ExtensibleIndex extensibleIndex) const {
return m_impl->index(extensibleIndex);
}
std::vector<std::string> IddObject::references() const {
return m_impl->references();
}
std::set<std::string> IddObject::objectLists() const {
return m_impl->objectLists();
}
std::set<std::string> IddObject::objectLists(unsigned index) const {
return m_impl->objectLists(index);
}
std::vector<unsigned> IddObject::objectListFields() const {
return m_impl->objectListFields();
}
std::vector<unsigned> IddObject::urlFields() const {
return m_impl->urlFields();
}
bool IddObject::operator==(const IddObject& other) const {
return (*m_impl == *(other.m_impl));
}
bool IddObject::operator!=(const IddObject& other) const {
return !(*this == other);
}
// SERIALIZATION
boost::optional<IddObject> IddObject::load(const std::string& name, const std::string& group, const std::string& text, IddObjectType type) {
std::shared_ptr<detail::IddObject_Impl> p = detail::IddObject_Impl::load(name, group, text, type);
if (p) {
return IddObject(p);
} else {
return boost::none;
}
}
boost::optional<IddObject> IddObject::load(const std::string& name, const std::string& group, const std::string& text) {
return load(name, group, text, IddObjectType(IddObjectType::UserCustom));
}
std::ostream& IddObject::print(std::ostream& os) const {
return m_impl->print(os);
}
// PRIVATE
IddObject::IddObject(const std::shared_ptr<detail::IddObject_Impl>& impl) : m_impl(impl) {}
// NON-MEMBER FUNCTIONS
std::ostream& operator<<(std::ostream& os, const IddObject& iddObject) {
return iddObject.print(os);
}
IddObjectTypeVector getIddObjectTypeVector(const IddObjectVector& objects) {
IddObjectTypeVector result;
for (const IddObject& object : objects) {
result.push_back(object.type());
}
return result;
}
IddObjectTypeSet getIddObjectTypeSet(const IddObjectVector& objects) {
IddObjectTypeSet result;
for (const IddObject& object : objects) {
result.insert(object.type());
}
return result;
}
std::vector<std::string> getIddKeyNames(const IddObject& object, unsigned index) {
StringVector result;
OptionalIddField oIddField = object.getField(index);
if (!oIddField) {
return result;
}
IddField iddField = *oIddField;
IddKeyVector keys = iddField.keys();
for (const IddKey& key : keys) {
result.push_back(key.name());
}
return result;
}
} // namespace openstudio