@@ -704,109 +704,75 @@ emscripten::val ReadValue(uint32_t modelID, webifc::parsing::IfcTokenType t)
704704 }
705705}
706706
707- emscripten::val& GetArgs (uint32_t modelID, emscripten::val& arguments )
707+ emscripten::val GetArgs (uint32_t modelID, bool inObject= false )
708708{
709709 auto loader = models[modelID].GetLoader ();
710- std::stack<emscripten::val> valueStack;
711- std::stack<int > valuePosition;
712-
713- valueStack.push (arguments);
714- valuePosition.push (0 );
715-
710+ auto arguments = emscripten::val::array ();
711+ size_t size = 0 ;
716712 bool endOfLine = false ;
717713 while (!loader->IsAtEnd () && !endOfLine)
718714 {
719715 webifc::parsing::IfcTokenType t = loader->GetTokenType ();
720716
721- auto & topValue = valueStack.top ();
722- auto & topPosition = valuePosition.top ();
723-
724717 switch (t)
725718 {
726- case webifc::parsing::IfcTokenType::LINE_END:
727- {
728- endOfLine = true ;
729- break ;
730- }
731- case webifc::parsing::IfcTokenType::EMPTY:
732- {
733- topValue.set (topPosition++, emscripten::val::null ());
734-
735- break ;
736- }
737- case webifc::parsing::IfcTokenType::SET_BEGIN:
738- {
739- auto newValue = emscripten::val::array ();
740-
741- valueStack.push (newValue);
742- valuePosition.push (0 );
743-
744- break ;
745- }
746- case webifc::parsing::IfcTokenType::SET_END:
747- {
748- if (valueStack.size () == 1 )
719+ case webifc::parsing::IfcTokenType::LINE_END:
749720 {
750- // this is a pop just before endline, so ignore
751721 endOfLine = true ;
722+ break ;
752723 }
753- else
724+ case webifc::parsing::IfcTokenType::EMPTY:
754725 {
755- auto topCopy = valueStack.top ();
756-
757- valueStack.pop ();
758- valuePosition.pop ();
759- auto & parent = valueStack.top ();
760- int & parentCount = valuePosition.top ();
761- parent.set (parentCount++, topCopy);
726+ arguments.set (size++,emscripten::val::null ());
727+ break ;
762728 }
763-
764- break ;
765- }
766- case webifc::parsing::IfcTokenType::LABEL:
767- {
768- // read label
769- auto obj = emscripten::val::object ();
770- obj.set (" type" , emscripten::val (static_cast <uint32_t >(webifc::parsing::IfcTokenType::LABEL)));
771- loader->StepBack ();
772- auto s=loader->GetStringArgument ();
773- auto typeCode = schemaManager.IfcTypeToTypeCode (s);
774- obj.set (" typecode" , emscripten::val (typeCode));
775- // read set open
776- loader->GetTokenType ();
777-
778- // read value following label
779- webifc::parsing::IfcTokenType t = loader->GetTokenType ();
780- loader->StepBack ();
781- obj.set (" value" , ReadValue (modelID,t));
782-
783- // read set close
784- loader->GetTokenType ();
785-
786- topValue.set (topPosition++, obj);
787-
788- break ;
789- }
790- case webifc::parsing::IfcTokenType::STRING:
791- case webifc::parsing::IfcTokenType::ENUM:
792- case webifc::parsing::IfcTokenType::REAL:
793- case webifc::parsing::IfcTokenType::REF:
794- {
795-
796- auto obj = emscripten::val::object ();
797- loader->StepBack ();
798- obj.set (" type" , emscripten::val (static_cast <uint32_t >(t)));
799- obj.set (" value" , ReadValue (modelID,t));
800-
801- topValue.set (topPosition++, obj);
802-
803- break ;
804- }
805- default :
806- break ;
729+ case webifc::parsing::IfcTokenType::SET_BEGIN:
730+ {
731+ arguments.set (size++,GetArgs (modelID));
732+ break ;
733+ }
734+ case webifc::parsing::IfcTokenType::SET_END:
735+ {
736+ endOfLine = true ;
737+ break ;
738+ }
739+ case webifc::parsing::IfcTokenType::LABEL:
740+ {
741+ // read label
742+ auto obj = emscripten::val::object ();
743+ obj.set (" type" , emscripten::val (static_cast <uint32_t >(webifc::parsing::IfcTokenType::LABEL)));
744+ loader->StepBack ();
745+ auto s=loader->GetStringArgument ();
746+ auto typeCode = schemaManager.IfcTypeToTypeCode (s);
747+ obj.set (" typecode" , emscripten::val (typeCode));
748+ // read set open
749+ loader->GetTokenType ();
750+ obj.set (" value" , GetArgs (modelID,true ));
751+ arguments.set (size++, obj);
752+ break ;
753+ }
754+ case webifc::parsing::IfcTokenType::STRING:
755+ case webifc::parsing::IfcTokenType::ENUM:
756+ case webifc::parsing::IfcTokenType::REAL:
757+ case webifc::parsing::IfcTokenType::REF:
758+ {
759+ loader->StepBack ();
760+ emscripten::val obj;
761+ if (inObject) obj = ReadValue (modelID,t);
762+ else {
763+ obj = emscripten::val::object ();
764+ obj.set (" type" , emscripten::val (static_cast <uint32_t >(t)));
765+ obj.set (" value" , ReadValue (modelID,t));
766+ }
767+ arguments.set (size++, obj);
768+ break ;
769+ }
770+ default :
771+ break ;
807772 }
808773 }
809-
774+ if (size == 0 ) return emscripten::val::null ();
775+ if (size == 1 && inObject) return arguments[0 ];
810776 return arguments;
811777}
812778
@@ -825,9 +791,8 @@ emscripten::val GetHeaderLine(uint32_t modelID, uint32_t headerType)
825791 auto line = lines[0 ];
826792 loader->MoveToHeaderLineArgument (line.lineIndex , 0 );
827793
828- auto arguments = emscripten::val::array ();
829794 std::string s (schemaManager.IfcTypeCodeToType (line.ifcType ));
830- GetArgs (modelID, arguments );
795+ auto arguments = GetArgs (modelID);
831796 auto retVal = emscripten::val::object ();
832797 retVal.set (" ID" , line.lineIndex );
833798 retVal.set (" type" , s);
@@ -847,9 +812,7 @@ emscripten::val GetLine(uint32_t modelID, uint32_t expressID)
847812
848813 loader->MoveToArgumentOffset (line, 0 );
849814
850- auto arguments = emscripten::val::array ();
851-
852- GetArgs (modelID, arguments);
815+ auto arguments = GetArgs (modelID);
853816
854817 auto retVal = emscripten::val::object ();
855818 retVal.set (emscripten::val (" ID" ), line.expressID );
0 commit comments