@@ -85,6 +85,32 @@ namespace tivars::TypeHandlers
8585 throw std::invalid_argument (" Unknown structured AppVar type name: " + typeName);
8686 }
8787
88+ const char * type_name_from_subtype (StructuredAppVarSubtype subtype)
89+ {
90+ switch (subtype)
91+ {
92+ case APPVAR_SUBTYPE_PYTHON_MODULE:
93+ return " PythonModuleAppVar" ;
94+ case APPVAR_SUBTYPE_PYTHON_IMAGE:
95+ return " PythonImageAppVar" ;
96+ case APPVAR_SUBTYPE_STUDY_CARDS:
97+ return " StudyCardsAppVar" ;
98+ case APPVAR_SUBTYPE_STUDY_CARDS_SETTINGS:
99+ return " StudyCardsSetgsAppVar" ;
100+ case APPVAR_SUBTYPE_CELSHEET:
101+ return " CellSheetAppVar" ;
102+ case APPVAR_SUBTYPE_CELSHEET_STATE:
103+ return " CellSheetStateAppVar" ;
104+ case APPVAR_SUBTYPE_CABRIJR:
105+ return " CabriJrAppVar" ;
106+ case APPVAR_SUBTYPE_NOTEFOLIO:
107+ return " NotefolioAppVar" ;
108+ case APPVAR_SUBTYPE_NONE:
109+ break ;
110+ }
111+ throw std::invalid_argument (" Unknown structured AppVar subtype" );
112+ }
113+
88114 bool has_prefix (const data_t & data, const char * magic)
89115 {
90116 return data.size () >= appVarSizePrefixByteCount + magicByteCount
@@ -371,12 +397,12 @@ namespace tivars::TypeHandlers
371397
372398 StructuredAppVarSubtype subtype_from_data_or_throw (const data_t & data)
373399 {
374- const std::string typeName = detectStructuredAppVarTypeName (data);
375- if (typeName == " AppVar " || typeName == " PythonAppVar " )
400+ const StructuredAppVarSubtype subtype = detectStructuredAppVarSubtype (data);
401+ if (subtype == APPVAR_SUBTYPE_NONE )
376402 {
377403 throw std::invalid_argument (" Unsupported structured AppVar payload" );
378404 }
379- return subtype_from_type_name (typeName) ;
405+ return subtype ;
380406 }
381407
382408 data_t payload_from_json_or_raw (const json& j, StructuredAppVarSubtype subtype)
@@ -691,6 +717,8 @@ namespace tivars::TypeHandlers
691717 }
692718 return payload;
693719 }
720+ case APPVAR_SUBTYPE_NONE:
721+ throw std::invalid_argument (" Unsupported structured AppVar subtype" );
694722 }
695723
696724 throw std::invalid_argument (" Unsupported structured AppVar subtype" );
@@ -1024,44 +1052,56 @@ namespace tivars::TypeHandlers
10241052 }
10251053 }
10261054
1027- std::string detectStructuredAppVarTypeName (const data_t & data)
1055+ StructuredAppVarSubtype detectStructuredAppVarSubtype (const data_t & data)
10281056 {
1029- if (has_prefix (data, STH_PythonAppVar::ID_CODE) || has_prefix (data, STH_PythonAppVar::ID_SCRIPT))
1030- {
1031- return " PythonAppVar" ;
1032- }
10331057 if (has_prefix (data, PYTHON_MODULE_MAGIC))
10341058 {
1035- return " PythonModuleAppVar " ;
1059+ return APPVAR_SUBTYPE_PYTHON_MODULE ;
10361060 }
10371061 if (has_prefix (data, PYTHON_IMAGE_MAGIC))
10381062 {
1039- return " PythonImageAppVar " ;
1063+ return APPVAR_SUBTYPE_PYTHON_IMAGE ;
10401064 }
10411065 if (has_prefix (data, CABRIJR_MAGIC))
10421066 {
1043- return " CabriJrAppVar " ;
1067+ return APPVAR_SUBTYPE_CABRIJR ;
10441068 }
10451069 if (has_prefix (data, STUDY_CARDS_MAGIC))
10461070 {
1047- return " StudyCardsAppVar " ;
1071+ return APPVAR_SUBTYPE_STUDY_CARDS ;
10481072 }
10491073 if (has_prefix (data, STUDY_CARDS_SETTINGS_MAGIC))
10501074 {
1051- return " StudyCardsSetgsAppVar " ;
1075+ return APPVAR_SUBTYPE_STUDY_CARDS_SETTINGS ;
10521076 }
10531077 if (has_prefix (data, CELSHEET_MAGIC))
10541078 {
1055- return " CellSheetAppVar " ;
1079+ return APPVAR_SUBTYPE_CELSHEET ;
10561080 }
10571081 if (has_prefix (data, CELSHEET_STATE_MAGIC))
10581082 {
1059- return " CellSheetStateAppVar " ;
1083+ return APPVAR_SUBTYPE_CELSHEET_STATE ;
10601084 }
10611085 if (has_prefix (data, NOTEFOLIO_MAGIC))
10621086 {
1063- return " NotefolioAppVar " ;
1087+ return APPVAR_SUBTYPE_NOTEFOLIO ;
10641088 }
1089+ return APPVAR_SUBTYPE_NONE;
1090+ }
1091+
1092+ std::string detectStructuredAppVarTypeName (const data_t & data)
1093+ {
1094+ if (has_prefix (data, STH_PythonAppVar::ID_CODE) || has_prefix (data, STH_PythonAppVar::ID_SCRIPT))
1095+ {
1096+ return " PythonAppVar" ;
1097+ }
1098+
1099+ const StructuredAppVarSubtype subtype = detectStructuredAppVarSubtype (data);
1100+ if (subtype != APPVAR_SUBTYPE_NONE)
1101+ {
1102+ return type_name_from_subtype (subtype);
1103+ }
1104+
10651105 return " AppVar" ;
10661106 }
10671107
@@ -1108,18 +1148,21 @@ namespace tivars::TypeHandlers
11081148 return parse_cabrijr_appvar (payload).dump (4 );
11091149 case APPVAR_SUBTYPE_NOTEFOLIO:
11101150 return parse_notefolio_appvar (payload).dump (4 );
1151+ case APPVAR_SUBTYPE_NONE:
1152+ break ;
11111153 }
11121154
11131155 throw std::invalid_argument (" Unsupported structured AppVar subtype" );
11141156 }
11151157
11161158 TIVarFileMinVersionByte TH_StructuredAppVar::getMinVersionFromData (const data_t & data)
11171159 {
1118- if ( detectStructuredAppVarTypeName (data) == " PythonModuleAppVar " )
1160+ switch ( detectStructuredAppVarSubtype (data))
11191161 {
1120- return VER_CE_PYTHONMOD;
1162+ case APPVAR_SUBTYPE_PYTHON_MODULE:
1163+ return VER_CE_PYTHONMOD;
1164+ default :
1165+ return VER_NONE;
11211166 }
1122-
1123- return VER_NONE;
11241167 }
11251168}
0 commit comments