40 #ifndef __OPENFLUID_MACHINE_WAREPLUGINSSEARCHRESULTSSERIALIZER_HPP__ 41 #define __OPENFLUID_MACHINE_WAREPLUGINSSEARCHRESULTSSERIALIZER_HPP__ 46 #include <rapidjson/document.h> 47 #include <rapidjson/stringbuffer.h> 48 #include <rapidjson/prettywriter.h> 63 template<
class SignatureInstanceType>
76 for (
auto Auth: Authors)
96 std::string Str =
"undefined";
98 if (Type == openfluid::ware::SignatureTimeScheduling::SchedulingType::DEFAULT)
102 else if (Type == openfluid::ware::SignatureTimeScheduling::SchedulingType::FIXED)
106 else if (Type == openfluid::ware::SignatureTimeScheduling::SchedulingType::RANGE)
114 static std::string getIndentedText(
const unsigned int Level,
115 const std::string& Title,
const std::string& Content =
"")
134 if (!Content.empty())
136 Text +=
": "+Content;
142 void writeListToStreamAsText(std::ostream& OutStm,
bool WithErrors)
const;
151 std::ostream& OutStm)
const;
154 std::ostream& OutStm)
const;
157 const std::string& CatStr, std::ostream& OutStm)
const;
167 void writeToStreamAsText(std::ostream& OutStm,
bool WithErrors)
const;
169 void addErrorsToJSONDoc(rapidjson::Document& Doc, rapidjson::Document::AllocatorType& Alloc)
const;
171 static std::string getJSONAsString(rapidjson::Document& Doc);
173 void writeListToStreamAsJSON(std::ostream& OutStm,
bool WithErrors)
const;
176 rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc)
const;
179 rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc)
const;
182 rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc)
const;
185 rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc)
const;
188 rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc)
const;
191 rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc)
const;
194 rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc)
const;
196 void writeToStreamAsJSON(std::ostream& OutStm,
bool WithErrors)
const;
202 m_SearchResults(SearchResults)
207 void writeToStream(std::ostream& OutStm,
const std::string& Format,
bool Detailed,
bool WithErrors)
const;
216 template<
class SignatureInstanceType>
218 bool WithErrors)
const 220 for (
auto& Plug : m_SearchResults.availablePlugins())
222 if (Plug->Verified && Plug->Signature)
224 OutStm << Plug->Signature->ID <<
"\n";
228 if (WithErrors && !m_SearchResults.erroredFiles().empty())
230 for (
auto& EFile : m_SearchResults.erroredFiles())
232 OutStm <<
"Error on file " << EFile.first <<
": " << EFile.second <<
"\n";
242 template<
class SignatureInstanceType>
256 template<
class SignatureInstanceType>
268 template<
class SignatureInstanceType>
272 std::ostringstream oss;
276 oss <<
"fixed to default deltaT";
291 OutStm << getIndentedText(2,
"Time scheduling",oss.str()) <<
"\n";
299 template<
class SignatureInstanceType>
303 std::ostringstream oss;
311 oss << CatStr <<
". " << Item.
Description << UnitStr;
312 OutStm << getIndentedText(3,Item.
DataName,oss.str()) <<
"\n";
320 template<
class SignatureInstanceType>
324 std::ostringstream oss;
332 oss << CatStr <<
". " << Item.
Description << UnitStr;
333 OutStm << getIndentedText(3,Item.
DataName+
" {"+Item.
UnitsClass+
"}",oss.str()) <<
"\n";
341 template<
class SignatureInstanceType>
345 std::ostringstream oss;
359 oss << CatStr <<
". " << Item.
Description << UnitStr;
360 OutStm << getIndentedText(3,Item.
DataName+
" {"+Item.
UnitsClass+
"}"+TypeStr,oss.str()) <<
"\n";
368 template<
class SignatureInstanceType>
374 if (!Data.UsedParams.empty() || !Data.RequiredParams.empty() ||
375 !Data.ProducedVars.empty() || !Data.UpdatedVars.empty() ||
376 !Data.RequiredVars.empty() || !Data.UsedVars.empty() ||
377 !Data.ProducedAttribute.empty() || !Data.RequiredAttribute.empty() || !Data.UsedAttribute.empty() ||
378 !Data.RequiredExtraFiles.empty() || !Data.UsedExtraFiles.empty() ||
379 !Data.UsedEventsOnUnits.empty())
381 OutStm << getIndentedText(2,
"Handled data") <<
"\n";
386 for (
const auto& Item : Data.RequiredParams)
388 addDataForText(Item,
"required parameter",OutStm);
391 for (
const auto& Item : Data.UsedParams)
393 addDataForText(Item,
"used parameter",OutStm);
399 for (
const auto& Item : Data.RequiredAttribute)
401 addSpatialDataForText(Item,
"required attribute",OutStm);
404 for (
const auto& Item : Data.UsedAttribute)
406 addSpatialDataForText(Item,
"used attribute",OutStm);
409 for (
const auto& Item : Data.ProducedAttribute)
411 addSpatialDataForText(Item,
"produced attribute",OutStm);
417 for (
const auto& Item : Data.RequiredVars)
419 addTypedSpatialDataForText(Item,
"required variable",OutStm);
422 for (
const auto& Item : Data.UsedVars)
424 addTypedSpatialDataForText(Item,
"used variable",OutStm);
427 for (
const auto& Item : Data.UpdatedVars)
429 addTypedSpatialDataForText(Item,
"updated variable",OutStm);
432 for (
const auto& Item : Data.ProducedVars)
434 addTypedSpatialDataForText(Item,
"produced variable",OutStm);
439 if (!Data.UsedEventsOnUnits.empty())
442 std::string EventsStr;
444 for (
const auto& Item : Data.UsedEventsOnUnits)
453 OutStm << getIndentedText(3,
"Events handled on",EventsStr) <<
"\n";
459 for (
const auto& Item : Data.RequiredExtraFiles)
461 OutStm << getIndentedText(3,
"Required extra file",Item) <<
"\n";
464 for (
const auto& Item : Data.UsedExtraFiles)
466 OutStm << getIndentedText(3,
"Used extra file",Item) <<
"\n";
477 template<
class SignatureInstanceType>
483 OutStm << getIndentedText(2,
"Handled units graph") <<
"\n";
493 OutStm << getIndentedText(3,
"Units graph update on class "+UC.UnitsClass,UC.Description) <<
"\n";
503 template<
class SignatureInstanceType>
507 addSchedulingDetailsForText(Sign,OutStm);
508 addDataDetailsForText(Sign,OutStm);
509 addGraphDetailsForText(Sign,OutStm);
517 template<
class SignatureInstanceType>
529 template<
class SignatureInstanceType>
531 bool WithErrors)
const 535 for (
auto& Plug : m_SearchResults.availablePlugins())
537 if (Plug->Verified && Plug->Signature)
541 OutStm <<
"================================================================================\n";
545 const auto Sign = Plug->Signature;
547 OutStm << getIndentedText(1,Sign->
ID) <<
"\n";
549 OutStm << getIndentedText(2,
"File",Plug->FileFullPath) <<
"\n";
550 addWareMetaForText(Sign,OutStm);
553 OutStm << getIndentedText(2,
"Version",Sign->
Version) <<
"\n";
554 OutStm << getIndentedText(2,
"SDK version used at build time",Sign->
ABIVersion) <<
"\n";
557 OutStm << getIndentedText(2,
"Author(s)",getAuthorsAsString(Sign->
Authors)) <<
"\n";
558 addWareDynaForText(Sign,OutStm);
562 if (WithErrors && !m_SearchResults.erroredFiles().empty())
566 OutStm <<
"================================================================================\n";
570 for (
auto& EFile : m_SearchResults.erroredFiles())
573 OutStm <<
"Error on file " << EFile.first <<
": " << EFile.second <<
"\n";
583 template<
class SignatureInstanceType>
585 rapidjson::Document& Doc, rapidjson::Document::AllocatorType& Alloc)
const 587 rapidjson::Value Errors(rapidjson::kArrayType);
589 for (
auto& EFile : m_SearchResults.erroredFiles())
591 rapidjson::Value EObj(rapidjson::kObjectType);
592 EObj.AddMember(
"file_path",rapidjson::Value(EFile.first.c_str(),Alloc),Alloc);
593 EObj.AddMember(
"message",rapidjson::Value(EFile.second.c_str(),Alloc),Alloc);
594 Errors.PushBack(EObj,Alloc);
597 Doc.AddMember(
"errors",Errors,Alloc);
605 template<
class SignatureInstanceType>
608 rapidjson::StringBuffer JSONbuffer;
609 rapidjson::PrettyWriter<rapidjson::StringBuffer> JSONwriter(JSONbuffer);
610 JSONwriter.SetIndent(
' ',2);
611 Doc.Accept(JSONwriter);
613 return JSONbuffer.GetString();
621 template<
class SignatureInstanceType>
623 bool WithErrors)
const 625 rapidjson::Document JSON;
627 rapidjson::Document::AllocatorType& JSONalloc = JSON.GetAllocator();
629 rapidjson::Value Available(rapidjson::kArrayType);
631 for (
auto& Plug : m_SearchResults.availablePlugins())
633 if (Plug->Verified && Plug->Signature)
635 Available.PushBack(rapidjson::Value(Plug->Signature->ID.c_str(),JSONalloc),JSONalloc);
639 JSON.AddMember(
"available",Available,JSONalloc);
643 addErrorsToJSONDoc(JSON,JSONalloc);
647 OutStm << getJSONAsString(JSON) <<
"\n";
655 template<
class SignatureInstanceType>
659 rapidjson::Value Obj(rapidjson::kObjectType);
660 Obj.AddMember(
"name",rapidjson::Value(Item.
DataName.c_str(),Alloc),Alloc);
661 Obj.AddMember(
"description",rapidjson::Value(Item.
Description.c_str(),Alloc),Alloc);
662 Obj.AddMember(
"si_unit",rapidjson::Value(Item.
DataUnit.c_str(),Alloc),Alloc);
663 Arr.PushBack(Obj,Alloc);
671 template<
class SignatureInstanceType>
674 rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc)
const 676 rapidjson::Value Obj(rapidjson::kObjectType);
677 Obj.AddMember(
"name",rapidjson::Value(Item.
DataName.c_str(),Alloc),Alloc);
678 Obj.AddMember(
"units_class",rapidjson::Value(Item.
UnitsClass.c_str(),Alloc),Alloc);
679 Obj.AddMember(
"description",rapidjson::Value(Item.
Description.c_str(),Alloc),Alloc);
680 Obj.AddMember(
"si_unit",rapidjson::Value(Item.
DataUnit.c_str(),Alloc),Alloc);
681 Arr.PushBack(Obj,Alloc);
689 template<
class SignatureInstanceType>
692 rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc)
const 696 rapidjson::Value Obj(rapidjson::kObjectType);
697 Obj.AddMember(
"name",rapidjson::Value(Item.
DataName.c_str(),Alloc),Alloc);
698 Obj.AddMember(
"type",rapidjson::Value(TypeStr.c_str(),Alloc),Alloc);
699 Obj.AddMember(
"units_class",rapidjson::Value(Item.
UnitsClass.c_str(),Alloc),Alloc);
700 Obj.AddMember(
"description",rapidjson::Value(Item.
Description.c_str(),Alloc),Alloc);
701 Obj.AddMember(
"si_unit",rapidjson::Value(Item.
DataUnit.c_str(),Alloc),Alloc);
702 Arr.PushBack(Obj,Alloc);
710 template<
class SignatureInstanceType>
713 rapidjson::Value& Obj,
714 rapidjson::Document::AllocatorType& Alloc)
const 718 rapidjson::Value ParamsObj(rapidjson::kObjectType);
720 rapidjson::Value ReqParamsArray(rapidjson::kArrayType);
723 addDataForJSON(Item,ReqParamsArray,Alloc);
726 rapidjson::Value UsedParamsArray(rapidjson::kArrayType);
729 addDataForJSON(Item,UsedParamsArray,Alloc);
732 ParamsObj.AddMember(
"required",ReqParamsArray,Alloc);
733 ParamsObj.AddMember(
"used",UsedParamsArray,Alloc);
734 Obj.AddMember(
"parameters",ParamsObj,Alloc);
739 rapidjson::Value AttrsObj(rapidjson::kObjectType);
741 rapidjson::Value ReqAttrsArray(rapidjson::kArrayType);
744 addSpatialDataForJSON(Item,ReqAttrsArray,Alloc);
747 rapidjson::Value UsedAttrsArray(rapidjson::kArrayType);
750 addSpatialDataForJSON(Item,UsedAttrsArray,Alloc);
753 rapidjson::Value ProdAttrsArray(rapidjson::kArrayType);
756 addSpatialDataForJSON(Item,ProdAttrsArray,Alloc);
759 AttrsObj.AddMember(
"required",ReqAttrsArray,Alloc);
760 AttrsObj.AddMember(
"used",UsedAttrsArray,Alloc);
761 AttrsObj.AddMember(
"produced",ProdAttrsArray,Alloc);
762 Obj.AddMember(
"attributes",AttrsObj,Alloc);
767 rapidjson::Value VarsObj(rapidjson::kObjectType);
769 rapidjson::Value ReqVarsArray(rapidjson::kArrayType);
772 addTypedSpatialDataForJSON(Item,ReqVarsArray,Alloc);
775 rapidjson::Value UsedVarsArray(rapidjson::kArrayType);
778 addTypedSpatialDataForJSON(Item,UsedVarsArray,Alloc);
781 rapidjson::Value UpVarsArray(rapidjson::kArrayType);
784 addTypedSpatialDataForJSON(Item,UpVarsArray,Alloc);
787 rapidjson::Value ProdVarsArray(rapidjson::kArrayType);
790 addTypedSpatialDataForJSON(Item,ProdVarsArray,Alloc);
793 VarsObj.AddMember(
"required",ReqVarsArray,Alloc);
794 VarsObj.AddMember(
"used",UsedVarsArray,Alloc);
795 VarsObj.AddMember(
"updated",UpVarsArray,Alloc);
796 VarsObj.AddMember(
"produced",ProdVarsArray,Alloc);
797 Obj.AddMember(
"variables",VarsObj,Alloc);
802 rapidjson::Value EvArray(rapidjson::kArrayType);
805 EvArray.PushBack(rapidjson::Value(Item.c_str(),Alloc),Alloc);
807 Obj.AddMember(
"events",EvArray,Alloc);
812 rapidjson::Value ExtraObj(rapidjson::kObjectType);
814 rapidjson::Value ReqExtraArray(rapidjson::kArrayType);
817 ReqExtraArray.PushBack(rapidjson::Value(Item.c_str(),Alloc),Alloc);
820 rapidjson::Value UsedExtraArray(rapidjson::kArrayType);
823 UsedExtraArray.PushBack(rapidjson::Value(Item.c_str(),Alloc),Alloc);
826 ExtraObj.AddMember(
"required",ReqExtraArray,Alloc);
827 ExtraObj.AddMember(
"used",UsedExtraArray,Alloc);
828 Obj.AddMember(
"extra_files",ExtraObj,Alloc);
836 template<
class SignatureInstanceType>
839 rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc)
const 843 rapidjson::Value ClassesArray(rapidjson::kArrayType);
846 rapidjson::Value ClassObj(rapidjson::kObjectType);
847 ClassObj.AddMember(
"class_name",rapidjson::Value(Class.UnitsClass.c_str(),Alloc),Alloc);
848 ClassObj.AddMember(
"description",rapidjson::Value(Class.Description.c_str(),Alloc),Alloc);
849 ClassesArray.PushBack(ClassObj,Alloc);
851 Obj.AddMember(
"units_classses",ClassesArray,Alloc);
859 template<
class SignatureInstanceType>
862 rapidjson::Value& Obj, rapidjson::Document::AllocatorType& Alloc)
const 864 Obj.AddMember(
"domain",rapidjson::Value(Sign->
Domain.c_str(),Alloc),Alloc);
865 Obj.AddMember(
"process",rapidjson::Value(Sign->
Process.c_str(),Alloc),Alloc);
866 Obj.AddMember(
"method",rapidjson::Value(Sign->
Method.c_str(),Alloc),Alloc);
869 rapidjson::Value DataObj(rapidjson::kObjectType);
870 addDataDetailsForJSON(Sign,DataObj,Alloc);
871 Obj.AddMember(
"data",DataObj,Alloc);
874 rapidjson::Value SchedObj(rapidjson::kObjectType);
875 SchedObj.AddMember(
"type",rapidjson::Value(getSchedulingTypeAsString(Sign->
TimeScheduling.
Type).c_str(),Alloc),
879 Obj.AddMember(
"scheduling",SchedObj,Alloc);
882 rapidjson::Value GraphObj(rapidjson::kObjectType);
883 addGraphDetailsForJSON(Sign,GraphObj,Alloc);
884 Obj.AddMember(
"spatial_graph",GraphObj,Alloc);
892 template<
class SignatureInstanceType>
896 rapidjson::Document::AllocatorType& )
const 906 template<
class SignatureInstanceType>
908 bool WithErrors)
const 910 rapidjson::Document JSON;
912 rapidjson::Document::AllocatorType& JSONalloc = JSON.GetAllocator();
914 rapidjson::Value Available(rapidjson::kArrayType);
916 for (
auto& Plug : m_SearchResults.availablePlugins())
918 if (Plug->Verified && Plug->Signature)
920 const auto Sign = Plug->Signature;
922 rapidjson::Value WareObj(rapidjson::kObjectType);
923 WareObj.AddMember(
"id",rapidjson::Value(Sign->
ID.c_str(),JSONalloc),JSONalloc);
924 WareObj.AddMember(
"file_path",rapidjson::Value(Plug->FileFullPath.c_str(),JSONalloc),JSONalloc);
925 WareObj.AddMember(
"abi_version",rapidjson::Value(Sign->
ABIVersion.c_str(),JSONalloc),JSONalloc);
926 WareObj.AddMember(
"name",rapidjson::Value(Sign->
Name.c_str(),JSONalloc),JSONalloc);
927 WareObj.AddMember(
"description",rapidjson::Value(Sign->
Description.c_str(),JSONalloc),JSONalloc);
928 WareObj.AddMember(
"version",rapidjson::Value(Sign->
Version.c_str(),JSONalloc),JSONalloc);
929 WareObj.AddMember(
"status",
931 JSONalloc),JSONalloc);
933 rapidjson::Value AuthsArray(rapidjson::kArrayType);
934 for (
auto& Author : Sign->
Authors)
936 rapidjson::Value AuthObj(rapidjson::kObjectType);
937 AuthObj.AddMember(
"name",rapidjson::Value(Author.first.c_str(),JSONalloc),JSONalloc);
938 AuthObj.AddMember(
"email",rapidjson::Value(Author.second.c_str(),JSONalloc),JSONalloc);
939 AuthsArray.PushBack(AuthObj,JSONalloc);
941 WareObj.AddMember(
"authors",AuthsArray,JSONalloc);
943 addWareDetailsForJSON(Sign,WareObj,JSONalloc);
945 Available.PushBack(WareObj,JSONalloc);
949 JSON.AddMember(
"available",Available,JSONalloc);
954 addErrorsToJSONDoc(JSON,JSONalloc);
958 OutStm << getJSONAsString(JSON) <<
"\n";
966 template<
class SignatureInstanceType>
968 const std::string& Format,
969 bool Detailed,
bool WithErrors)
const 971 if (Format ==
"text")
975 writeToStreamAsText(OutStm,WithErrors);
979 writeListToStreamAsText(OutStm,WithErrors);
982 else if (Format ==
"json")
986 writeToStreamAsJSON(OutStm,WithErrors);
990 writeListToStreamAsJSON(OutStm,WithErrors);
996 "Wrong format for available wares reporting");
SignatureUnitsGraph HandledUnitsGraph
Definition: SimulatorSignature.hpp:336
Definition: ApplicationException.hpp:47
WarePluginsSearchResultsSerializer(const WarePluginsSearchResults< SignatureInstanceType > &SearchResults)
Definition: WarePluginsSearchResultsSerializer.hpp:201
Definition: SimulatorSignature.hpp:67
std::vector< SignatureSpatialDataItem > RequiredAttribute
Definition: SimulatorSignature.hpp:159
std::vector< std::string > RequiredExtraFiles
Definition: SimulatorSignature.hpp:163
std::vector< SignatureTypedSpatialDataItem > UsedVars
Definition: SimulatorSignature.hpp:155
Definition: SimulatorSignature.hpp:255
Definition: FrameworkException.hpp:50
Definition: SimulatorSignature.hpp:116
SignatureHandledData HandledData
Definition: SimulatorSignature.hpp:331
std::string UpdatedUnitsGraph
Definition: SimulatorSignature.hpp:228
std::vector< std::pair< std::string, std::string > > AuthorsList_t
Definition: WareSignature.hpp:56
std::vector< openfluid::core::UnitsClass_t > UsedEventsOnUnits
Definition: SimulatorSignature.hpp:167
openfluid::core::Duration_t Max
Definition: SimulatorSignature.hpp:261
openfluid::core::Duration_t Min
Definition: SimulatorSignature.hpp:259
Definition: WarePluginsSearchResultsSerializer.hpp:64
openfluid::core::Value::Type DataType
Definition: SimulatorSignature.hpp:121
SchedulingType
Definition: SimulatorSignature.hpp:255
SchedulingType Type
Definition: SimulatorSignature.hpp:257
Definition: SimulatorSignature.hpp:308
openfluid::core::UnitsClass_t UnitsClass
Definition: SimulatorSignature.hpp:96
std::string Description
Definition: WareSignature.hpp:62
std::vector< SignatureSpatialDataItem > ProducedAttribute
Definition: SimulatorSignature.hpp:157
std::vector< SignatureTypedSpatialDataItem > ProducedVars
Definition: SimulatorSignature.hpp:149
SimMethod_t Method
Definition: SimulatorSignature.hpp:326
Definition: WarePluginsSearchResults.hpp:57
SignatureTimeScheduling TimeScheduling
Definition: SimulatorSignature.hpp:341
WareStatus_t Status
Definition: WareSignature.hpp:72
std::vector< std::string > UsedExtraFiles
Definition: SimulatorSignature.hpp:165
static std::string getStringFromValueType(const Value::Type ValueType)
std::string OPENFLUID_API replaceEmptyString(std::string SourceStr, const std::string &ReplaceStr)
std::vector< SignatureDataItem > RequiredParams
Definition: SimulatorSignature.hpp:147
SimDomain_t Domain
Definition: SimulatorSignature.hpp:316
std::string Description
Definition: SimulatorSignature.hpp:72
SimProcess_t Process
Definition: SimulatorSignature.hpp:321
AuthorsList_t Authors
Definition: WareSignature.hpp:82
std::string DataUnit
Definition: SimulatorSignature.hpp:73
void writeToStream(std::ostream &OutStm, const std::string &Format, bool Detailed, bool WithErrors) const
Definition: WarePluginsSearchResultsSerializer.hpp:967
std::vector< SignatureDataItem > UsedParams
Definition: SimulatorSignature.hpp:145
Definition: ObserverSignature.hpp:53
Definition: SimulatorSignature.hpp:255
#define OPENFLUID_API
Definition: dllexport.hpp:86
std::vector< SignatureTypedSpatialDataItem > RequiredVars
Definition: SimulatorSignature.hpp:153
WareVersion_t ABIVersion
Definition: WareSignature.hpp:77
Definition: SimulatorSignature.hpp:92
WareVersion_t Version
Definition: WareSignature.hpp:67
std::vector< SignatureSpatialDataItem > UsedAttribute
Definition: SimulatorSignature.hpp:161
std::string DataName
Definition: SimulatorSignature.hpp:71
static std::string getStatusAsString(const WareStatus_t &Status)
Definition: WareSignature.hpp:135
Definition: SimulatorSignature.hpp:255
std::vector< SignatureTypedSpatialDataItem > UpdatedVars
Definition: SimulatorSignature.hpp:151
WareID_t ID
Definition: WareSignature.hpp:58
std::vector< SignatureUnitsClassItem > UpdatedUnitsClass
Definition: SimulatorSignature.hpp:230
WareName_t Name
Definition: WareSignature.hpp:60