Manual for OpenFLUID 2.1.11

WarePluginsSearchResultsSerializer.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file WarePluginsSearchResultsSerializer.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_MACHINE_WAREPLUGINSSEARCHRESULTSSERIALIZER_HPP__
41 #define __OPENFLUID_MACHINE_WAREPLUGINSSEARCHRESULTSSERIALIZER_HPP__
42 
43 
44 #include <sstream>
45 
46 #include <rapidjson/document.h>
47 #include <rapidjson/stringbuffer.h>
48 #include <rapidjson/prettywriter.h>
49 
54 
55 
56 namespace openfluid { namespace machine {
57 
58 
59 /**
60  Class for management of search results of pluggable wares
61  @tparam SignatureType class defining the container for ware signature only
62 */
63 template<class SignatureInstanceType>
65 {
66  private:
67 
69 
70 
71  static std::string getAuthorsAsString(const openfluid::ware::WareSignature::AuthorsList_t& Authors)
72  {
73  std::string Str = "";
74  bool First = true;
75 
76  for (auto Auth: Authors)
77  {
78  if (!First)
79  {
80  Str+= ", ";
81  }
82  First = false;
83 
84  Str += openfluid::tools::replaceEmptyString(Auth.first,("(unknown author)"));
85  Str += " <";
86  Str += openfluid::tools::replaceEmptyString(Auth.second,("(unknown author email)"));
87  Str += ">";
88  }
89 
90  return Str;
91  }
92 
93 
94  static std::string getSchedulingTypeAsString(openfluid::ware::SignatureTimeScheduling::SchedulingType Type)
95  {
96  std::string Str = "undefined";
97 
98  if (Type == openfluid::ware::SignatureTimeScheduling::SchedulingType::DEFAULT)
99  {
100  Str = "default";
101  }
102  else if (Type == openfluid::ware::SignatureTimeScheduling::SchedulingType::FIXED)
103  {
104  Str = "fixed";
105  }
106  else if (Type == openfluid::ware::SignatureTimeScheduling::SchedulingType::RANGE)
107  {
108  Str = "range";
109  }
110 
111  return Str;
112  }
113 
114  static std::string getIndentedText(const unsigned int Level,
115  const std::string& Title, const std::string& Content = "")
116  {
117  std::string Text;
118 
119  if (Level == 1)
120  {
121  Text += "* ";
122  }
123  else if (Level == 2)
124  {
125  Text += " - ";
126  }
127  else if (Level == 3)
128  {
129  Text += " . ";
130  }
131 
132  Text += Title;
133 
134  if (!Content.empty())
135  {
136  Text += ": "+Content;
137  }
138 
139  return Text;
140  }
141 
142  void writeListToStreamAsText(std::ostream& OutStm,bool WithErrors) const;
143 
144  void addWareMetaForText(const openfluid::ware::SimulatorSignature* Sign, std::ostream& OutStm) const;
145 
146  void addWareMetaForText(const openfluid::ware::ObserverSignature* Sign, std::ostream& OutStm) const;
147 
148  void addSchedulingDetailsForText(const openfluid::ware::SimulatorSignature* Sign, std::ostream& OutStm) const;
149 
150  void addDataForText(const openfluid::ware::SignatureDataItem& Item, const std::string& CatStr,
151  std::ostream& OutStm) const;
152 
153  void addSpatialDataForText(const openfluid::ware::SignatureSpatialDataItem& Item, const std::string& CatStr,
154  std::ostream& OutStm) const;
155 
156  void addTypedSpatialDataForText(const openfluid::ware::SignatureTypedSpatialDataItem& Item,
157  const std::string& CatStr, std::ostream& OutStm) const;
158 
159  void addDataDetailsForText(const openfluid::ware::SimulatorSignature* Sign, std::ostream& OutStm) const;
160 
161  void addGraphDetailsForText(const openfluid::ware::SimulatorSignature* Sign, std::ostream& OutStm) const;
162 
163  void addWareDynaForText(const openfluid::ware::SimulatorSignature* Sign, std::ostream& OutStm) const;
164 
165  void addWareDynaForText(const openfluid::ware::ObserverSignature* Sign, std::ostream& OutStm) const;
166 
167  void writeToStreamAsText(std::ostream& OutStm,bool WithErrors) const;
168 
169  void addErrorsToJSONDoc(rapidjson::Document& Doc, rapidjson::Document::AllocatorType& Alloc) const;
170 
171  static std::string getJSONAsString(rapidjson::Document& Doc);
172 
173  void writeListToStreamAsJSON(std::ostream& OutStm,bool WithErrors) const;
174 
175  void addDataForJSON(const openfluid::ware::SignatureDataItem& Item,
176  rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc) const;
177 
178  void addSpatialDataForJSON(const openfluid::ware::SignatureSpatialDataItem& Item,
179  rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc) const;
180 
181  void addTypedSpatialDataForJSON(const openfluid::ware::SignatureTypedSpatialDataItem& Item,
182  rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc) const;
183 
184  void addDataDetailsForJSON(const openfluid::ware::SimulatorSignature* Sign,
185  rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc) const;
186 
187  void addGraphDetailsForJSON(const openfluid::ware::SimulatorSignature* Sign,
188  rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc) const;
189 
190  void addWareDetailsForJSON(const openfluid::ware::SimulatorSignature* Sign,
191  rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc) const;
192 
193  void addWareDetailsForJSON(const openfluid::ware::ObserverSignature* Sign,
194  rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc) const;
195 
196  void writeToStreamAsJSON(std::ostream& OutStm,bool WithErrors) const;
197 
198 
199  public:
200 
202  m_SearchResults(SearchResults)
203  {
204 
205  }
206 
207  void writeToStream(std::ostream& OutStm,const std::string& Format,bool Detailed, bool WithErrors) const;
208 
209 };
210 
211 
212 // =====================================================================
213 // =====================================================================
214 
215 
216 template<class SignatureInstanceType>
217 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::writeListToStreamAsText(std::ostream& OutStm,
218  bool WithErrors) const
219 {
220  for (auto& Plug : m_SearchResults.availablePlugins())
221  {
222  if (Plug->Verified && Plug->Signature)
223  {
224  OutStm << Plug->Signature->ID << "\n";
225  }
226  }
227 
228  if (WithErrors && !m_SearchResults.erroredFiles().empty())
229  {
230  for (auto& EFile : m_SearchResults.erroredFiles())
231  {
232  OutStm << "Error on file " << EFile.first << ": " << EFile.second << "\n";
233  }
234  }
235 }
236 
237 
238 // =====================================================================
239 // =====================================================================
240 
241 
242 template<class SignatureInstanceType>
243 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addWareMetaForText(
244  const openfluid::ware::SimulatorSignature* Sign, std::ostream& OutStm) const
245 {
246  OutStm << getIndentedText(2,"Domain",openfluid::tools::replaceEmptyString(Sign->Domain,"(unknown)")) << "\n";
247  OutStm << getIndentedText(2,"Process",openfluid::tools::replaceEmptyString(Sign->Process,"(unknown)")) << "\n";
248  OutStm << getIndentedText(2,"Method",openfluid::tools::replaceEmptyString(Sign->Method,"(unknown)")) << "\n";
249 }
250 
251 
252 // =====================================================================
253 // =====================================================================
254 
255 
256 template<class SignatureInstanceType>
257 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addWareMetaForText(
258  const openfluid::ware::ObserverSignature* /*Sign*/, std::ostream& /*OutStm*/) const
259 {
260  // nothing to be done
261 }
262 
263 
264 // =====================================================================
265 // =====================================================================
266 
267 
268 template<class SignatureInstanceType>
269 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addSchedulingDetailsForText(
270  const openfluid::ware::SimulatorSignature* Sign, std::ostream& OutStm) const
271 {
272  std::ostringstream oss;
273 
275  {
276  oss << "fixed to default deltaT";
277  }
279  {
280  oss << "fixed to " << Sign->TimeScheduling.Min << " seconds";
281  }
283  {
284  oss << "range between " << Sign->TimeScheduling.Min << " and " << Sign->TimeScheduling.Max << " seconds";
285  }
286  else
287  {
288  oss << "undefined";
289  }
290 
291  OutStm << getIndentedText(2,"Time scheduling",oss.str()) << "\n";
292 }
293 
294 
295 // =====================================================================
296 // =====================================================================
297 
298 
299 template<class SignatureInstanceType>
300 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addDataForText(
301  const openfluid::ware::SignatureDataItem& Item, const std::string& CatStr, std::ostream& OutStm) const
302 {
303  std::ostringstream oss;
304 
305  std::string UnitStr;
306  if (!Item.DataUnit.empty())
307  {
308  UnitStr = " ("+Item.DataUnit+")";
309  }
310 
311  oss << CatStr << ". " << Item.Description << UnitStr;
312  OutStm << getIndentedText(3,Item.DataName,oss.str()) << "\n";
313 }
314 
315 
316 // =====================================================================
317 // =====================================================================
318 
319 
320 template<class SignatureInstanceType>
321 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addSpatialDataForText(
322  const openfluid::ware::SignatureSpatialDataItem& Item, const std::string& CatStr, std::ostream& OutStm) const
323 {
324  std::ostringstream oss;
325 
326  std::string UnitStr;
327  if (!Item.DataUnit.empty())
328  {
329  UnitStr = " ("+Item.DataUnit+")";
330  }
331 
332  oss << CatStr << ". " << Item.Description << UnitStr;
333  OutStm << getIndentedText(3,Item.DataName+" {"+Item.UnitsClass+"}",oss.str()) << "\n";
334 }
335 
336 
337 // =====================================================================
338 // =====================================================================
339 
340 
341 template<class SignatureInstanceType>
342 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addTypedSpatialDataForText(
343  const openfluid::ware::SignatureTypedSpatialDataItem& Item, const std::string& CatStr, std::ostream& OutStm) const
344 {
345  std::ostringstream oss;
346 
347  std::string UnitStr;
348  if (!Item.DataUnit.empty())
349  {
350  UnitStr = " ("+Item.DataUnit+")";
351  }
352 
353  std::string TypeStr;
355  {
357  }
358 
359  oss << CatStr << ". " << Item.Description << UnitStr;
360  OutStm << getIndentedText(3,Item.DataName+" {"+Item.UnitsClass+"}"+TypeStr,oss.str()) << "\n";
361 }
362 
363 
364 // =====================================================================
365 // =====================================================================
366 
367 
368 template<class SignatureInstanceType>
369 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addDataDetailsForText(
370  const openfluid::ware::SimulatorSignature* Sign, std::ostream& OutStm) const
371 {
372  const auto& Data = Sign->HandledData;
373 
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())
380  {
381  OutStm << getIndentedText(2,"Handled data") << "\n";
382 
383 
384  // ------ Parameters
385 
386  for (const auto& Item : Data.RequiredParams)
387  {
388  addDataForText(Item,"required parameter",OutStm);
389  }
390 
391  for (const auto& Item : Data.UsedParams)
392  {
393  addDataForText(Item,"used parameter",OutStm);
394  }
395 
396 
397  // ------ Attributes
398 
399  for (const auto& Item : Data.RequiredAttribute)
400  {
401  addSpatialDataForText(Item,"required attribute",OutStm);
402  }
403 
404  for (const auto& Item : Data.UsedAttribute)
405  {
406  addSpatialDataForText(Item,"used attribute",OutStm);
407  }
408 
409  for (const auto& Item : Data.ProducedAttribute)
410  {
411  addSpatialDataForText(Item,"produced attribute",OutStm);
412  }
413 
414 
415  // ------ Variables
416 
417  for (const auto& Item : Data.RequiredVars)
418  {
419  addTypedSpatialDataForText(Item,"required variable",OutStm);
420  }
421 
422  for (const auto& Item : Data.UsedVars)
423  {
424  addTypedSpatialDataForText(Item,"used variable",OutStm);
425  }
426 
427  for (const auto& Item : Data.UpdatedVars)
428  {
429  addTypedSpatialDataForText(Item,"updated variable",OutStm);
430  }
431 
432  for (const auto& Item : Data.ProducedVars)
433  {
434  addTypedSpatialDataForText(Item,"produced variable",OutStm);
435  }
436 
437 
438  // ------ Events
439  if (!Data.UsedEventsOnUnits.empty())
440  {
441  bool First = true;
442  std::string EventsStr;
443 
444  for (const auto& Item : Data.UsedEventsOnUnits)
445  {
446  if (!First)
447  {
448  EventsStr += ", ";
449  }
450  First = false;
451  EventsStr += Item;
452  }
453  OutStm << getIndentedText(3,"Events handled on",EventsStr) << "\n";
454  }
455 
456 
457  // ------ Extrafiles
458 
459  for (const auto& Item : Data.RequiredExtraFiles)
460  {
461  OutStm << getIndentedText(3,"Required extra file",Item) << "\n";
462  }
463 
464  for (const auto& Item : Data.UsedExtraFiles)
465  {
466  OutStm << getIndentedText(3,"Used extra file",Item) << "\n";
467  }
468 
469  }
470 }
471 
472 
473 // =====================================================================
474 // =====================================================================
475 
476 
477 template<class SignatureInstanceType>
478 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addGraphDetailsForText(
479  const openfluid::ware::SimulatorSignature* Sign, std::ostream& OutStm) const
480 {
481  if (!Sign->HandledUnitsGraph.UpdatedUnitsGraph.empty() || !Sign->HandledUnitsGraph.UpdatedUnitsClass.empty())
482  {
483  OutStm << getIndentedText(2,"Handled units graph") << "\n";
484 
485 
486  if (!Sign->HandledUnitsGraph.UpdatedUnitsGraph.empty())
487  {
488  OutStm << getIndentedText(3,"Global units graph updates",Sign->HandledUnitsGraph.UpdatedUnitsGraph) << "\n";
489  }
490 
491  for (auto& UC : Sign->HandledUnitsGraph.UpdatedUnitsClass)
492  {
493  OutStm << getIndentedText(3,"Units graph update on class "+UC.UnitsClass,UC.Description) << "\n";
494  }
495  }
496 }
497 
498 
499 // =====================================================================
500 // =====================================================================
501 
502 
503 template<class SignatureInstanceType>
504 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addWareDynaForText(
505  const openfluid::ware::SimulatorSignature* Sign, std::ostream& OutStm) const
506 {
507  addSchedulingDetailsForText(Sign,OutStm);
508  addDataDetailsForText(Sign,OutStm);
509  addGraphDetailsForText(Sign,OutStm);
510 }
511 
512 
513 // =====================================================================
514 // =====================================================================
515 
516 
517 template<class SignatureInstanceType>
518 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addWareDynaForText(
519  const openfluid::ware::ObserverSignature* /*Sign*/, std::ostream& /*OutStm*/) const
520 {
521  // nothing to be done
522 }
523 
524 
525 // =====================================================================
526 // =====================================================================
527 
528 
529 template<class SignatureInstanceType>
530 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::writeToStreamAsText(std::ostream& OutStm,
531  bool WithErrors) const
532 {
533  bool First = true;
534 
535  for (auto& Plug : m_SearchResults.availablePlugins())
536  {
537  if (Plug->Verified && Plug->Signature)
538  {
539  if (!First)
540  {
541  OutStm << "================================================================================\n";
542  }
543  First = false;
544 
545  const auto Sign = Plug->Signature;
546 
547  OutStm << getIndentedText(1,Sign->ID) << "\n";
548  OutStm << getIndentedText(2,"Name",openfluid::tools::replaceEmptyString(Sign->Name,"(none)")) << "\n";
549  OutStm << getIndentedText(2,"File",Plug->FileFullPath) << "\n";
550  addWareMetaForText(Sign,OutStm);
551  OutStm <<
552  getIndentedText(2,"Description",openfluid::tools::replaceEmptyString(Sign->Description,"(none)")) << "\n";
553  OutStm << getIndentedText(2,"Version",Sign->Version) << "\n";
554  OutStm << getIndentedText(2,"SDK version used at build time",Sign->BuildInfo.SDKVersion) << "\n";
555  OutStm << getIndentedText(2,"Build information") << "\n";
556  OutStm <<
557  getIndentedText(3,"Build type",openfluid::tools::replaceEmptyString(Sign->BuildInfo.BuildType,"(unknown)")) <<
558  "\n";
559  OutStm <<
560  getIndentedText(3,"Compiler ID",openfluid::tools::replaceEmptyString(Sign->BuildInfo.CompilerID,"(unknown)")) <<
561  "\n";
562  OutStm <<
563  getIndentedText(3,"Compiler version",
565  "\n";
566  OutStm <<
567  getIndentedText(3,"Compilation flags",
569  "\n";
570  OutStm <<
571  getIndentedText(2,"Development status",openfluid::ware::WareSignature::getStatusAsString(Sign->Status)) << "\n";
572  OutStm << getIndentedText(2,"Author(s)",getAuthorsAsString(Sign->Authors)) << "\n";
573  addWareDynaForText(Sign,OutStm);
574  }
575  }
576 
577  if (WithErrors && !m_SearchResults.erroredFiles().empty())
578  {
579  if (!First)
580  {
581  OutStm << "================================================================================\n";
582  }
583  First = false;
584 
585  for (auto& EFile : m_SearchResults.erroredFiles())
586  {
587 
588  OutStm << "Error on file " << EFile.first << ": " << EFile.second << "\n";
589  }
590  }
591 }
592 
593 
594 // =====================================================================
595 // =====================================================================
596 
597 
598 template<class SignatureInstanceType>
599 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addErrorsToJSONDoc(
600  rapidjson::Document& Doc, rapidjson::Document::AllocatorType& Alloc) const
601 {
602  rapidjson::Value Errors(rapidjson::kArrayType);
603 
604  for (auto& EFile : m_SearchResults.erroredFiles())
605  {
606  rapidjson::Value EObj(rapidjson::kObjectType);
607  EObj.AddMember("file_path",rapidjson::Value(EFile.first.c_str(),Alloc),Alloc);
608  EObj.AddMember("message",rapidjson::Value(EFile.second.c_str(),Alloc),Alloc);
609  Errors.PushBack(EObj,Alloc);
610  }
611 
612  Doc.AddMember("errors",Errors,Alloc);
613 }
614 
615 
616 // =====================================================================
617 // =====================================================================
618 
619 
620 template<class SignatureInstanceType>
621 std::string WarePluginsSearchResultsSerializer<SignatureInstanceType>::getJSONAsString(rapidjson::Document& Doc)
622 {
623  rapidjson::StringBuffer JSONbuffer;
624  rapidjson::PrettyWriter<rapidjson::StringBuffer> JSONwriter(JSONbuffer);
625  JSONwriter.SetIndent(' ',2);
626  Doc.Accept(JSONwriter);
627 
628  return JSONbuffer.GetString();
629 }
630 
631 
632 // =====================================================================
633 // =====================================================================
634 
635 
636 template<class SignatureInstanceType>
637 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::writeListToStreamAsJSON(std::ostream& OutStm,
638  bool WithErrors) const
639 {
640  rapidjson::Document JSON;
641  JSON.SetObject();
642  rapidjson::Document::AllocatorType& JSONalloc = JSON.GetAllocator();
643 
644  rapidjson::Value Available(rapidjson::kArrayType);
645 
646  for (auto& Plug : m_SearchResults.availablePlugins())
647  {
648  if (Plug->Verified && Plug->Signature)
649  {
650  Available.PushBack(rapidjson::Value(Plug->Signature->ID.c_str(),JSONalloc),JSONalloc);
651  }
652  }
653 
654  JSON.AddMember("available",Available,JSONalloc);
655 
656  if (WithErrors)
657  {
658  addErrorsToJSONDoc(JSON,JSONalloc);
659  }
660 
661 
662  OutStm << getJSONAsString(JSON) << "\n";
663 }
664 
665 
666 // =====================================================================
667 // =====================================================================
668 
669 
670 template<class SignatureInstanceType>
671 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addDataForJSON(
672  const openfluid::ware::SignatureDataItem& Item, rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc) const
673 {
674  rapidjson::Value Obj(rapidjson::kObjectType);
675  Obj.AddMember("name",rapidjson::Value(Item.DataName.c_str(),Alloc),Alloc);
676  Obj.AddMember("description",rapidjson::Value(Item.Description.c_str(),Alloc),Alloc);
677  Obj.AddMember("si_unit",rapidjson::Value(Item.DataUnit.c_str(),Alloc),Alloc);
678  Arr.PushBack(Obj,Alloc);
679 }
680 
681 
682 // =====================================================================
683 // =====================================================================
684 
685 
686 template<class SignatureInstanceType>
687 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addSpatialDataForJSON(
689  rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc) const
690 {
691  rapidjson::Value Obj(rapidjson::kObjectType);
692  Obj.AddMember("name",rapidjson::Value(Item.DataName.c_str(),Alloc),Alloc);
693  Obj.AddMember("units_class",rapidjson::Value(Item.UnitsClass.c_str(),Alloc),Alloc);
694  Obj.AddMember("description",rapidjson::Value(Item.Description.c_str(),Alloc),Alloc);
695  Obj.AddMember("si_unit",rapidjson::Value(Item.DataUnit.c_str(),Alloc),Alloc);
696  Arr.PushBack(Obj,Alloc);
697 }
698 
699 
700 // =====================================================================
701 // =====================================================================
702 
703 
704 template<class SignatureInstanceType>
705 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addTypedSpatialDataForJSON(
707  rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc) const
708 {
709  std::string TypeStr = openfluid::core::Value::getStringFromValueType(Item.DataType);
710 
711  rapidjson::Value Obj(rapidjson::kObjectType);
712  Obj.AddMember("name",rapidjson::Value(Item.DataName.c_str(),Alloc),Alloc);
713  Obj.AddMember("type",rapidjson::Value(TypeStr.c_str(),Alloc),Alloc);
714  Obj.AddMember("units_class",rapidjson::Value(Item.UnitsClass.c_str(),Alloc),Alloc);
715  Obj.AddMember("description",rapidjson::Value(Item.Description.c_str(),Alloc),Alloc);
716  Obj.AddMember("si_unit",rapidjson::Value(Item.DataUnit.c_str(),Alloc),Alloc);
717  Arr.PushBack(Obj,Alloc);
718 }
719 
720 
721 // =====================================================================
722 // =====================================================================
723 
724 
725 template<class SignatureInstanceType>
726 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addDataDetailsForJSON(
728  rapidjson::Value& Obj,
729  rapidjson::Document::AllocatorType& Alloc) const
730 {
731  // ------ Parameters
732 
733  rapidjson::Value ParamsObj(rapidjson::kObjectType);
734 
735  rapidjson::Value ReqParamsArray(rapidjson::kArrayType);
736  for (const auto& Item : Sign->HandledData.RequiredParams)
737  {
738  addDataForJSON(Item,ReqParamsArray,Alloc);
739  }
740 
741  rapidjson::Value UsedParamsArray(rapidjson::kArrayType);
742  for (const auto& Item : Sign->HandledData.UsedParams)
743  {
744  addDataForJSON(Item,UsedParamsArray,Alloc);
745  }
746 
747  ParamsObj.AddMember("required",ReqParamsArray,Alloc);
748  ParamsObj.AddMember("used",UsedParamsArray,Alloc);
749  Obj.AddMember("parameters",ParamsObj,Alloc);
750 
751 
752  // ------ Attributes
753 
754  rapidjson::Value AttrsObj(rapidjson::kObjectType);
755 
756  rapidjson::Value ReqAttrsArray(rapidjson::kArrayType);
757  for (const auto& Item : Sign->HandledData.RequiredAttribute)
758  {
759  addSpatialDataForJSON(Item,ReqAttrsArray,Alloc);
760  }
761 
762  rapidjson::Value UsedAttrsArray(rapidjson::kArrayType);
763  for (const auto& Item : Sign->HandledData.UsedAttribute)
764  {
765  addSpatialDataForJSON(Item,UsedAttrsArray,Alloc);
766  }
767 
768  rapidjson::Value ProdAttrsArray(rapidjson::kArrayType);
769  for (const auto& Item : Sign->HandledData.ProducedAttribute)
770  {
771  addSpatialDataForJSON(Item,ProdAttrsArray,Alloc);
772  }
773 
774  AttrsObj.AddMember("required",ReqAttrsArray,Alloc);
775  AttrsObj.AddMember("used",UsedAttrsArray,Alloc);
776  AttrsObj.AddMember("produced",ProdAttrsArray,Alloc);
777  Obj.AddMember("attributes",AttrsObj,Alloc);
778 
779 
780  // ------ Variables
781 
782  rapidjson::Value VarsObj(rapidjson::kObjectType);
783 
784  rapidjson::Value ReqVarsArray(rapidjson::kArrayType);
785  for (const auto& Item : Sign->HandledData.RequiredVars)
786  {
787  addTypedSpatialDataForJSON(Item,ReqVarsArray,Alloc);
788  }
789 
790  rapidjson::Value UsedVarsArray(rapidjson::kArrayType);
791  for (const auto& Item : Sign->HandledData.UsedVars)
792  {
793  addTypedSpatialDataForJSON(Item,UsedVarsArray,Alloc);
794  }
795 
796  rapidjson::Value UpVarsArray(rapidjson::kArrayType);
797  for (const auto& Item : Sign->HandledData.UpdatedVars)
798  {
799  addTypedSpatialDataForJSON(Item,UpVarsArray,Alloc);
800  }
801 
802  rapidjson::Value ProdVarsArray(rapidjson::kArrayType);
803  for (const auto& Item : Sign->HandledData.ProducedVars)
804  {
805  addTypedSpatialDataForJSON(Item,ProdVarsArray,Alloc);
806  }
807 
808  VarsObj.AddMember("required",ReqVarsArray,Alloc);
809  VarsObj.AddMember("used",UsedVarsArray,Alloc);
810  VarsObj.AddMember("updated",UpVarsArray,Alloc);
811  VarsObj.AddMember("produced",ProdVarsArray,Alloc);
812  Obj.AddMember("variables",VarsObj,Alloc);
813 
814 
815  // ------ Events
816 
817  rapidjson::Value EvArray(rapidjson::kArrayType);
818  for (const auto& Item : Sign->HandledData.UsedEventsOnUnits)
819  {
820  EvArray.PushBack(rapidjson::Value(Item.c_str(),Alloc),Alloc);
821  }
822  Obj.AddMember("events",EvArray,Alloc);
823 
824 
825  // ------ Extrafiles
826 
827  rapidjson::Value ExtraObj(rapidjson::kObjectType);
828 
829  rapidjson::Value ReqExtraArray(rapidjson::kArrayType);
830  for (const auto& Item : Sign->HandledData.RequiredExtraFiles)
831  {
832  ReqExtraArray.PushBack(rapidjson::Value(Item.c_str(),Alloc),Alloc);
833  }
834 
835  rapidjson::Value UsedExtraArray(rapidjson::kArrayType);
836  for (const auto& Item : Sign->HandledData.UsedExtraFiles)
837  {
838  UsedExtraArray.PushBack(rapidjson::Value(Item.c_str(),Alloc),Alloc);
839  }
840 
841  ExtraObj.AddMember("required",ReqExtraArray,Alloc);
842  ExtraObj.AddMember("used",UsedExtraArray,Alloc);
843  Obj.AddMember("extra_files",ExtraObj,Alloc);
844 }
845 
846 
847 // =====================================================================
848 // =====================================================================
849 
850 
851 template<class SignatureInstanceType>
852 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addGraphDetailsForJSON(
854  rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc) const
855 {
856  Obj.AddMember("description",rapidjson::Value(Sign->HandledUnitsGraph.UpdatedUnitsGraph.c_str(),Alloc),Alloc);
857 
858  rapidjson::Value ClassesArray(rapidjson::kArrayType);
859  for (const auto& Class : Sign->HandledUnitsGraph.UpdatedUnitsClass)
860  {
861  rapidjson::Value ClassObj(rapidjson::kObjectType);
862  ClassObj.AddMember("class_name",rapidjson::Value(Class.UnitsClass.c_str(),Alloc),Alloc);
863  ClassObj.AddMember("description",rapidjson::Value(Class.Description.c_str(),Alloc),Alloc);
864  ClassesArray.PushBack(ClassObj,Alloc);
865  }
866  Obj.AddMember("units_classses",ClassesArray,Alloc);
867 }
868 
869 
870 // =====================================================================
871 // =====================================================================
872 
873 
874 template<class SignatureInstanceType>
875 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addWareDetailsForJSON(
877  rapidjson::Value& Obj, rapidjson::Document::AllocatorType& Alloc) const
878 {
879  Obj.AddMember("domain",rapidjson::Value(Sign->Domain.c_str(),Alloc),Alloc);
880  Obj.AddMember("process",rapidjson::Value(Sign->Process.c_str(),Alloc),Alloc);
881  Obj.AddMember("method",rapidjson::Value(Sign->Method.c_str(),Alloc),Alloc);
882 
883 
884  rapidjson::Value DataObj(rapidjson::kObjectType);
885  addDataDetailsForJSON(Sign,DataObj,Alloc);
886  Obj.AddMember("data",DataObj,Alloc);
887 
888 
889  rapidjson::Value SchedObj(rapidjson::kObjectType);
890  SchedObj.AddMember("type",rapidjson::Value(getSchedulingTypeAsString(Sign->TimeScheduling.Type).c_str(),Alloc),
891  Alloc);
892  SchedObj.AddMember("min",Sign->TimeScheduling.Min,Alloc);
893  SchedObj.AddMember("min",Sign->TimeScheduling.Max,Alloc);
894  Obj.AddMember("scheduling",SchedObj,Alloc);
895 
896 
897  rapidjson::Value GraphObj(rapidjson::kObjectType);
898  addGraphDetailsForJSON(Sign,GraphObj,Alloc);
899  Obj.AddMember("spatial_graph",GraphObj,Alloc);
900 }
901 
902 
903 // =====================================================================
904 // =====================================================================
905 
906 
907 template<class SignatureInstanceType>
908 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::addWareDetailsForJSON(
909  const openfluid::ware::ObserverSignature* /*Sign*/,
910  rapidjson::Value& /*Obj*/,
911  rapidjson::Document::AllocatorType& /*Alloc*/) const
912 {
913  // nothing to be done
914 }
915 
916 
917 // =====================================================================
918 // =====================================================================
919 
920 
921 template<class SignatureInstanceType>
922 void WarePluginsSearchResultsSerializer<SignatureInstanceType>::writeToStreamAsJSON(std::ostream& OutStm,
923  bool WithErrors) const
924 {
925  rapidjson::Document JSON;
926  JSON.SetObject();
927  rapidjson::Document::AllocatorType& JSONalloc = JSON.GetAllocator();
928 
929  rapidjson::Value Available(rapidjson::kArrayType);
930 
931  for (auto& Plug : m_SearchResults.availablePlugins())
932  {
933  if (Plug->Verified && Plug->Signature)
934  {
935  const auto Sign = Plug->Signature;
936 
937  rapidjson::Value WareObj(rapidjson::kObjectType);
938  WareObj.AddMember("id",rapidjson::Value(Sign->ID.c_str(),JSONalloc),JSONalloc);
939  WareObj.AddMember("file_path",rapidjson::Value(Plug->FileFullPath.c_str(),JSONalloc),JSONalloc);
940  WareObj.AddMember("abi_version",rapidjson::Value(Sign->BuildInfo.SDKVersion.c_str(),JSONalloc),JSONalloc);
941 
942  rapidjson::Value BuildObj(rapidjson::kObjectType);
943  BuildObj.AddMember("type",rapidjson::Value(Sign->BuildInfo.BuildType.c_str(),JSONalloc),JSONalloc);
944  BuildObj.AddMember("compiler_id",rapidjson::Value(Sign->BuildInfo.CompilerID.c_str(),JSONalloc),JSONalloc);
945  BuildObj.AddMember("compiler_version",
946  rapidjson::Value(Sign->BuildInfo.CompilerVersion.c_str(),JSONalloc),JSONalloc);
947  BuildObj.AddMember("compilation_flags",
948  rapidjson::Value(Sign->BuildInfo.CompilationFlags.c_str(),JSONalloc),JSONalloc);
949  WareObj.AddMember("build_info",BuildObj,JSONalloc);
950 
951  WareObj.AddMember("name",rapidjson::Value(Sign->Name.c_str(),JSONalloc),JSONalloc);
952  WareObj.AddMember("description",rapidjson::Value(Sign->Description.c_str(),JSONalloc),JSONalloc);
953  WareObj.AddMember("version",rapidjson::Value(Sign->Version.c_str(),JSONalloc),JSONalloc);
954  WareObj.AddMember("status",
955  rapidjson::Value(openfluid::ware::WareSignature::getStatusAsString(Sign->Status).c_str(),
956  JSONalloc),JSONalloc);
957 
958  rapidjson::Value AuthsArray(rapidjson::kArrayType);
959  for (auto& Author : Sign->Authors)
960  {
961  rapidjson::Value AuthObj(rapidjson::kObjectType);
962  AuthObj.AddMember("name",rapidjson::Value(Author.first.c_str(),JSONalloc),JSONalloc);
963  AuthObj.AddMember("email",rapidjson::Value(Author.second.c_str(),JSONalloc),JSONalloc);
964  AuthsArray.PushBack(AuthObj,JSONalloc);
965  }
966  WareObj.AddMember("authors",AuthsArray,JSONalloc);
967 
968  addWareDetailsForJSON(Sign,WareObj,JSONalloc);
969 
970  Available.PushBack(WareObj,JSONalloc);
971  }
972  }
973 
974  JSON.AddMember("available",Available,JSONalloc);
975 
976 
977  if (WithErrors)
978  {
979  addErrorsToJSONDoc(JSON,JSONalloc);
980  }
981 
982 
983  OutStm << getJSONAsString(JSON) << "\n";
984 }
985 
986 
987 // =====================================================================
988 // =====================================================================
989 
990 
991 template<class SignatureInstanceType>
993  const std::string& Format,
994  bool Detailed, bool WithErrors) const
995 {
996  if (Format == "text")
997  {
998  if (Detailed)
999  {
1000  writeToStreamAsText(OutStm,WithErrors);
1001  }
1002  else
1003  {
1004  writeListToStreamAsText(OutStm,WithErrors);
1005  }
1006  }
1007  else if (Format == "json")
1008  {
1009  if (Detailed)
1010  {
1011  writeToStreamAsJSON(OutStm,WithErrors);
1012  }
1013  else
1014  {
1015  writeListToStreamAsJSON(OutStm,WithErrors);
1016  }
1017  }
1018  else
1019  {
1020  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,
1021  "Wrong format for available wares reporting");
1022  }
1023 }
1024 
1025 
1026 } } // namespaces
1027 
1028 
1029 #endif /* __OPENFLUID_MACHINE_WAREPLUGINSSEARCHRESULTSSERIALIZER_HPP__ */
openfluid::ware::SignatureHandledData::RequiredAttribute
std::vector< SignatureSpatialDataItem > RequiredAttribute
Definition: SimulatorSignature.hpp:159
openfluid::ware::SignatureHandledData::RequiredExtraFiles
std::vector< std::string > RequiredExtraFiles
Definition: SimulatorSignature.hpp:163
openfluid::ware::SignatureDataItem::DataName
std::string DataName
Definition: SimulatorSignature.hpp:71
openfluid::ware::SignatureHandledData::RequiredParams
std::vector< SignatureDataItem > RequiredParams
Definition: SimulatorSignature.hpp:147
openfluid::ware::SimulatorSignature::TimeScheduling
SignatureTimeScheduling TimeScheduling
Definition: SimulatorSignature.hpp:341
FrameworkException.hpp
OPENFLUID_API
#define OPENFLUID_API
Definition: dllexport.hpp:86
openfluid::ware::SignatureHandledData::UpdatedVars
std::vector< SignatureTypedSpatialDataItem > UpdatedVars
Definition: SimulatorSignature.hpp:151
openfluid::ware::SignatureBuildInfo::CompilationFlags
std::string CompilationFlags
Definition: TypeDefs.hpp:134
openfluid::ware::SimulatorSignature::Domain
SimDomain_t Domain
Definition: SimulatorSignature.hpp:316
openfluid::ware::SignatureUnitsGraph::UpdatedUnitsGraph
std::string UpdatedUnitsGraph
Definition: SimulatorSignature.hpp:228
openfluid::ware::SignatureBuildInfo::SDKVersion
WareVersion_t SDKVersion
Definition: TypeDefs.hpp:126
openfluid::ware::SignatureTimeScheduling::DEFAULT
@ DEFAULT
Definition: SimulatorSignature.hpp:255
openfluid::ware::SignatureHandledData::UsedAttribute
std::vector< SignatureSpatialDataItem > UsedAttribute
Definition: SimulatorSignature.hpp:161
openfluid::ware::WareSignature::Name
WareName_t Name
Definition: WareSignature.hpp:65
openfluid::ware::WareSignature::BuildInfo
SignatureBuildInfo BuildInfo
Definition: WareSignature.hpp:61
openfluid::ware::SignatureDataItem::Description
std::string Description
Definition: SimulatorSignature.hpp:72
openfluid::ware::SignatureHandledData::UsedVars
std::vector< SignatureTypedSpatialDataItem > UsedVars
Definition: SimulatorSignature.hpp:155
openfluid::ware::SignatureHandledData::ProducedAttribute
std::vector< SignatureSpatialDataItem > ProducedAttribute
Definition: SimulatorSignature.hpp:157
openfluid::ware::SimulatorSignature::Process
SimProcess_t Process
Definition: SimulatorSignature.hpp:321
openfluid::ware::SignatureTimeScheduling::Type
SchedulingType Type
Definition: SimulatorSignature.hpp:257
openfluid::ware::WareSignature::ID
WareID_t ID
Definition: WareSignature.hpp:63
openfluid::ware::WareSignature::Version
WareVersion_t Version
Definition: WareSignature.hpp:72
openfluid::ware::SignatureTimeScheduling::Min
openfluid::core::Duration_t Min
Definition: SimulatorSignature.hpp:259
openfluid::ware::SignatureTimeScheduling::Max
openfluid::core::Duration_t Max
Definition: SimulatorSignature.hpp:261
openfluid::ware::SignatureDataItem
Definition: SimulatorSignature.hpp:67
openfluid::machine::WarePluginsSearchResults
Definition: WarePluginsSearchResults.hpp:57
openfluid::ware::SimulatorSignature
Definition: SimulatorSignature.hpp:308
openfluid::ware::ObserverSignature
Definition: ObserverSignature.hpp:53
openfluid::core::Value::NONE
@ NONE
Definition: Value.hpp:66
openfluid::ware::SignatureBuildInfo::CompilerID
std::string CompilerID
Definition: TypeDefs.hpp:130
openfluid::ware::SignatureBuildInfo::CompilerVersion
std::string CompilerVersion
Definition: TypeDefs.hpp:132
openfluid::ware::WareSignature::Description
std::string Description
Definition: WareSignature.hpp:67
openfluid::ware::SignatureTypedSpatialDataItem
Definition: SimulatorSignature.hpp:116
openfluid::machine::WarePluginsSearchResultsSerializer::WarePluginsSearchResultsSerializer
WarePluginsSearchResultsSerializer(const WarePluginsSearchResults< SignatureInstanceType > &SearchResults)
Definition: WarePluginsSearchResultsSerializer.hpp:201
openfluid
Definition: ApplicationException.hpp:47
openfluid::ware::SignatureTimeScheduling::SchedulingType
SchedulingType
Definition: SimulatorSignature.hpp:255
openfluid::ware::SignatureSpatialDataItem::UnitsClass
openfluid::core::UnitsClass_t UnitsClass
Definition: SimulatorSignature.hpp:96
openfluid::ware::SignatureDataItem::DataUnit
std::string DataUnit
Definition: SimulatorSignature.hpp:73
openfluid::ware::SimulatorSignature::HandledUnitsGraph
SignatureUnitsGraph HandledUnitsGraph
Definition: SimulatorSignature.hpp:336
openfluid::ware::WareSignature::getStatusAsString
static std::string getStatusAsString(const WareStatus_t &Status)
Definition: WareSignature.hpp:125
openfluid::ware::WareSignature::Authors
AuthorsList_t Authors
Definition: WareSignature.hpp:82
SimulatorSignature.hpp
openfluid::ware::SignatureHandledData::UsedEventsOnUnits
std::vector< openfluid::core::UnitsClass_t > UsedEventsOnUnits
Definition: SimulatorSignature.hpp:167
openfluid::ware::SignatureBuildInfo::BuildType
std::string BuildType
Definition: TypeDefs.hpp:128
WareSignature.hpp
openfluid::ware::WareSignature::AuthorsList_t
std::vector< std::pair< std::string, std::string > > AuthorsList_t
Definition: WareSignature.hpp:56
openfluid::machine::WarePluginsSearchResultsSerializer::writeToStream
void writeToStream(std::ostream &OutStm, const std::string &Format, bool Detailed, bool WithErrors) const
Definition: WarePluginsSearchResultsSerializer.hpp:992
openfluid::ware::SignatureHandledData::UsedExtraFiles
std::vector< std::string > UsedExtraFiles
Definition: SimulatorSignature.hpp:165
openfluid::ware::SimulatorSignature::Method
SimMethod_t Method
Definition: SimulatorSignature.hpp:326
openfluid::base::FrameworkException
Definition: FrameworkException.hpp:50
openfluid::ware::SignatureTimeScheduling::FIXED
@ FIXED
Definition: SimulatorSignature.hpp:255
openfluid::core::Value::getStringFromValueType
static std::string getStringFromValueType(const Value::Type ValueType)
openfluid::ware::SignatureTimeScheduling::RANGE
@ RANGE
Definition: SimulatorSignature.hpp:255
openfluid::ware::SimulatorSignature::HandledData
SignatureHandledData HandledData
Definition: SimulatorSignature.hpp:331
openfluid::ware::SignatureTypedSpatialDataItem::DataType
openfluid::core::Value::Type DataType
Definition: SimulatorSignature.hpp:121
openfluid::ware::SignatureSpatialDataItem
Definition: SimulatorSignature.hpp:92
openfluid::ware::SignatureHandledData::UsedParams
std::vector< SignatureDataItem > UsedParams
Definition: SimulatorSignature.hpp:145
openfluid::machine::WarePluginsSearchResultsSerializer
Definition: WarePluginsSearchResultsSerializer.hpp:64
ObserverSignature.hpp
openfluid::ware::SignatureHandledData::ProducedVars
std::vector< SignatureTypedSpatialDataItem > ProducedVars
Definition: SimulatorSignature.hpp:149
openfluid::tools::replaceEmptyString
std::string OPENFLUID_API replaceEmptyString(std::string SourceStr, const std::string &ReplaceStr)
openfluid::ware::SignatureUnitsGraph::UpdatedUnitsClass
std::vector< SignatureUnitsClassItem > UpdatedUnitsClass
Definition: SimulatorSignature.hpp:230
openfluid::ware::WareSignature::Status
WareStatus_t Status
Definition: WareSignature.hpp:77
openfluid::ware::SignatureHandledData::RequiredVars
std::vector< SignatureTypedSpatialDataItem > RequiredVars
Definition: SimulatorSignature.hpp:153