Manual for OpenFLUID 2.1.10

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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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->ABIVersion) << "\n";
555  OutStm <<
556  getIndentedText(2,"Development status",openfluid::ware::WareSignature::getStatusAsString(Sign->Status)) << "\n";
557  OutStm << getIndentedText(2,"Author(s)",getAuthorsAsString(Sign->Authors)) << "\n";
558  addWareDynaForText(Sign,OutStm);
559  }
560  }
561 
562  if (WithErrors && !m_SearchResults.erroredFiles().empty())
563  {
564  if (!First)
565  {
566  OutStm << "================================================================================\n";
567  }
568  First = false;
569 
570  for (auto& EFile : m_SearchResults.erroredFiles())
571  {
572 
573  OutStm << "Error on file " << EFile.first << ": " << EFile.second << "\n";
574  }
575  }
576 }
577 
578 
579 // =====================================================================
580 // =====================================================================
581 
582 
583 template<class SignatureInstanceType>
585  rapidjson::Document& Doc, rapidjson::Document::AllocatorType& Alloc) const
586 {
587  rapidjson::Value Errors(rapidjson::kArrayType);
588 
589  for (auto& EFile : m_SearchResults.erroredFiles())
590  {
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);
595  }
596 
597  Doc.AddMember("errors",Errors,Alloc);
598 }
599 
600 
601 // =====================================================================
602 // =====================================================================
603 
604 
605 template<class SignatureInstanceType>
607 {
608  rapidjson::StringBuffer JSONbuffer;
609  rapidjson::PrettyWriter<rapidjson::StringBuffer> JSONwriter(JSONbuffer);
610  JSONwriter.SetIndent(' ',2);
611  Doc.Accept(JSONwriter);
612 
613  return JSONbuffer.GetString();
614 }
615 
616 
617 // =====================================================================
618 // =====================================================================
619 
620 
621 template<class SignatureInstanceType>
623  bool WithErrors) const
624 {
625  rapidjson::Document JSON;
626  JSON.SetObject();
627  rapidjson::Document::AllocatorType& JSONalloc = JSON.GetAllocator();
628 
629  rapidjson::Value Available(rapidjson::kArrayType);
630 
631  for (auto& Plug : m_SearchResults.availablePlugins())
632  {
633  if (Plug->Verified && Plug->Signature)
634  {
635  Available.PushBack(rapidjson::Value(Plug->Signature->ID.c_str(),JSONalloc),JSONalloc);
636  }
637  }
638 
639  JSON.AddMember("available",Available,JSONalloc);
640 
641  if (WithErrors)
642  {
643  addErrorsToJSONDoc(JSON,JSONalloc);
644  }
645 
646 
647  OutStm << getJSONAsString(JSON) << "\n";
648 }
649 
650 
651 // =====================================================================
652 // =====================================================================
653 
654 
655 template<class SignatureInstanceType>
657  const openfluid::ware::SignatureDataItem& Item, rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc) const
658 {
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);
664 }
665 
666 
667 // =====================================================================
668 // =====================================================================
669 
670 
671 template<class SignatureInstanceType>
674  rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc) const
675 {
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);
682 }
683 
684 
685 // =====================================================================
686 // =====================================================================
687 
688 
689 template<class SignatureInstanceType>
692  rapidjson::Value& Arr,rapidjson::Document::AllocatorType& Alloc) const
693 {
694  std::string TypeStr = openfluid::core::Value::getStringFromValueType(Item.DataType);
695 
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);
703 }
704 
705 
706 // =====================================================================
707 // =====================================================================
708 
709 
710 template<class SignatureInstanceType>
713  rapidjson::Value& Obj,
714  rapidjson::Document::AllocatorType& Alloc) const
715 {
716  // ------ Parameters
717 
718  rapidjson::Value ParamsObj(rapidjson::kObjectType);
719 
720  rapidjson::Value ReqParamsArray(rapidjson::kArrayType);
721  for (const auto& Item : Sign->HandledData.RequiredParams)
722  {
723  addDataForJSON(Item,ReqParamsArray,Alloc);
724  }
725 
726  rapidjson::Value UsedParamsArray(rapidjson::kArrayType);
727  for (const auto& Item : Sign->HandledData.UsedParams)
728  {
729  addDataForJSON(Item,UsedParamsArray,Alloc);
730  }
731 
732  ParamsObj.AddMember("required",ReqParamsArray,Alloc);
733  ParamsObj.AddMember("used",UsedParamsArray,Alloc);
734  Obj.AddMember("parameters",ParamsObj,Alloc);
735 
736 
737  // ------ Attributes
738 
739  rapidjson::Value AttrsObj(rapidjson::kObjectType);
740 
741  rapidjson::Value ReqAttrsArray(rapidjson::kArrayType);
742  for (const auto& Item : Sign->HandledData.RequiredAttribute)
743  {
744  addSpatialDataForJSON(Item,ReqAttrsArray,Alloc);
745  }
746 
747  rapidjson::Value UsedAttrsArray(rapidjson::kArrayType);
748  for (const auto& Item : Sign->HandledData.UsedAttribute)
749  {
750  addSpatialDataForJSON(Item,UsedAttrsArray,Alloc);
751  }
752 
753  rapidjson::Value ProdAttrsArray(rapidjson::kArrayType);
754  for (const auto& Item : Sign->HandledData.ProducedAttribute)
755  {
756  addSpatialDataForJSON(Item,ProdAttrsArray,Alloc);
757  }
758 
759  AttrsObj.AddMember("required",ReqAttrsArray,Alloc);
760  AttrsObj.AddMember("used",UsedAttrsArray,Alloc);
761  AttrsObj.AddMember("produced",ProdAttrsArray,Alloc);
762  Obj.AddMember("attributes",AttrsObj,Alloc);
763 
764 
765  // ------ Variables
766 
767  rapidjson::Value VarsObj(rapidjson::kObjectType);
768 
769  rapidjson::Value ReqVarsArray(rapidjson::kArrayType);
770  for (const auto& Item : Sign->HandledData.RequiredVars)
771  {
772  addTypedSpatialDataForJSON(Item,ReqVarsArray,Alloc);
773  }
774 
775  rapidjson::Value UsedVarsArray(rapidjson::kArrayType);
776  for (const auto& Item : Sign->HandledData.UsedVars)
777  {
778  addTypedSpatialDataForJSON(Item,UsedVarsArray,Alloc);
779  }
780 
781  rapidjson::Value UpVarsArray(rapidjson::kArrayType);
782  for (const auto& Item : Sign->HandledData.UpdatedVars)
783  {
784  addTypedSpatialDataForJSON(Item,UpVarsArray,Alloc);
785  }
786 
787  rapidjson::Value ProdVarsArray(rapidjson::kArrayType);
788  for (const auto& Item : Sign->HandledData.ProducedVars)
789  {
790  addTypedSpatialDataForJSON(Item,ProdVarsArray,Alloc);
791  }
792 
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);
798 
799 
800  // ------ Events
801 
802  rapidjson::Value EvArray(rapidjson::kArrayType);
803  for (const auto& Item : Sign->HandledData.UsedEventsOnUnits)
804  {
805  EvArray.PushBack(rapidjson::Value(Item.c_str(),Alloc),Alloc);
806  }
807  Obj.AddMember("events",EvArray,Alloc);
808 
809 
810  // ------ Extrafiles
811 
812  rapidjson::Value ExtraObj(rapidjson::kObjectType);
813 
814  rapidjson::Value ReqExtraArray(rapidjson::kArrayType);
815  for (const auto& Item : Sign->HandledData.RequiredExtraFiles)
816  {
817  ReqExtraArray.PushBack(rapidjson::Value(Item.c_str(),Alloc),Alloc);
818  }
819 
820  rapidjson::Value UsedExtraArray(rapidjson::kArrayType);
821  for (const auto& Item : Sign->HandledData.UsedExtraFiles)
822  {
823  UsedExtraArray.PushBack(rapidjson::Value(Item.c_str(),Alloc),Alloc);
824  }
825 
826  ExtraObj.AddMember("required",ReqExtraArray,Alloc);
827  ExtraObj.AddMember("used",UsedExtraArray,Alloc);
828  Obj.AddMember("extra_files",ExtraObj,Alloc);
829 }
830 
831 
832 // =====================================================================
833 // =====================================================================
834 
835 
836 template<class SignatureInstanceType>
839  rapidjson::Value& Obj,rapidjson::Document::AllocatorType& Alloc) const
840 {
841  Obj.AddMember("description",rapidjson::Value(Sign->HandledUnitsGraph.UpdatedUnitsGraph.c_str(),Alloc),Alloc);
842 
843  rapidjson::Value ClassesArray(rapidjson::kArrayType);
844  for (const auto& Class : Sign->HandledUnitsGraph.UpdatedUnitsClass)
845  {
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);
850  }
851  Obj.AddMember("units_classses",ClassesArray,Alloc);
852 }
853 
854 
855 // =====================================================================
856 // =====================================================================
857 
858 
859 template<class SignatureInstanceType>
862  rapidjson::Value& Obj, rapidjson::Document::AllocatorType& Alloc) const
863 {
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);
867 
868 
869  rapidjson::Value DataObj(rapidjson::kObjectType);
870  addDataDetailsForJSON(Sign,DataObj,Alloc);
871  Obj.AddMember("data",DataObj,Alloc);
872 
873 
874  rapidjson::Value SchedObj(rapidjson::kObjectType);
875  SchedObj.AddMember("type",rapidjson::Value(getSchedulingTypeAsString(Sign->TimeScheduling.Type).c_str(),Alloc),
876  Alloc);
877  SchedObj.AddMember("min",Sign->TimeScheduling.Min,Alloc);
878  SchedObj.AddMember("min",Sign->TimeScheduling.Max,Alloc);
879  Obj.AddMember("scheduling",SchedObj,Alloc);
880 
881 
882  rapidjson::Value GraphObj(rapidjson::kObjectType);
883  addGraphDetailsForJSON(Sign,GraphObj,Alloc);
884  Obj.AddMember("spatial_graph",GraphObj,Alloc);
885 }
886 
887 
888 // =====================================================================
889 // =====================================================================
890 
891 
892 template<class SignatureInstanceType>
894  const openfluid::ware::ObserverSignature* /*Sign*/,
895  rapidjson::Value& /*Obj*/,
896  rapidjson::Document::AllocatorType& /*Alloc*/) const
897 {
898  // nothing to be done
899 }
900 
901 
902 // =====================================================================
903 // =====================================================================
904 
905 
906 template<class SignatureInstanceType>
908  bool WithErrors) const
909 {
910  rapidjson::Document JSON;
911  JSON.SetObject();
912  rapidjson::Document::AllocatorType& JSONalloc = JSON.GetAllocator();
913 
914  rapidjson::Value Available(rapidjson::kArrayType);
915 
916  for (auto& Plug : m_SearchResults.availablePlugins())
917  {
918  if (Plug->Verified && Plug->Signature)
919  {
920  const auto Sign = Plug->Signature;
921 
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",
930  rapidjson::Value(openfluid::ware::WareSignature::getStatusAsString(Sign->Status).c_str(),
931  JSONalloc),JSONalloc);
932 
933  rapidjson::Value AuthsArray(rapidjson::kArrayType);
934  for (auto& Author : Sign->Authors)
935  {
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);
940  }
941  WareObj.AddMember("authors",AuthsArray,JSONalloc);
942 
943  addWareDetailsForJSON(Sign,WareObj,JSONalloc);
944 
945  Available.PushBack(WareObj,JSONalloc);
946  }
947  }
948 
949  JSON.AddMember("available",Available,JSONalloc);
950 
951 
952  if (WithErrors)
953  {
954  addErrorsToJSONDoc(JSON,JSONalloc);
955  }
956 
957 
958  OutStm << getJSONAsString(JSON) << "\n";
959 }
960 
961 
962 // =====================================================================
963 // =====================================================================
964 
965 
966 template<class SignatureInstanceType>
968  const std::string& Format,
969  bool Detailed, bool WithErrors) const
970 {
971  if (Format == "text")
972  {
973  if (Detailed)
974  {
975  writeToStreamAsText(OutStm,WithErrors);
976  }
977  else
978  {
979  writeListToStreamAsText(OutStm,WithErrors);
980  }
981  }
982  else if (Format == "json")
983  {
984  if (Detailed)
985  {
986  writeToStreamAsJSON(OutStm,WithErrors);
987  }
988  else
989  {
990  writeListToStreamAsJSON(OutStm,WithErrors);
991  }
992  }
993  else
994  {
995  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,
996  "Wrong format for available wares reporting");
997  }
998 }
999 
1000 
1001 } } // namespaces
1002 
1003 
1004 #endif /* __OPENFLUID_MACHINE_WAREPLUGINSSEARCHRESULTSSERIALIZER_HPP__ */
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
Definition: Value.hpp:68
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