RecipieLoader.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <stdexcept>
  2. #include <Datei.h>
  3. #include <iostream>
  4. #include "RecipieLoader.h"
  5. RecipieLoader::RecipieLoader()
  6. : Framework::ReferenceCounter()
  7. {}
  8. void RecipieLoader::loadRecipies( const char* path )
  9. {
  10. std::cout << "loading recipies from '" << path << "'" << std::endl;
  11. Framework::Datei d;
  12. d.setDatei( path );
  13. if( d.istOrdner() )
  14. {
  15. Framework::RCArray<Framework::Text>* files = d.getDateiListe();
  16. for( Framework::Text* f : *files )
  17. loadRecipies( Framework::Text( path ) + "/" + *f );
  18. files->release();
  19. }
  20. else
  21. {
  22. Framework::JSON::JSONValue* json = Framework::JSON::loadJSONFromFile( path );
  23. if( json->getType() == Framework::JSON::JSONType::ARRAY )
  24. {
  25. // TODO: parse the json recipies
  26. }
  27. else
  28. std::cout << "could not load recipie file '" << path << "' because it does not contain a valid json array of recipies" << std::endl;
  29. json->release();
  30. }
  31. }
  32. RecipieList* RecipieLoader::zRecipieList( const char* name )
  33. {
  34. for( RecipieList* l : lists )
  35. {
  36. if( l->getName().istGleich( name ) )
  37. return l;
  38. }
  39. return 0;
  40. }
  41. ShapedRecipieList* RecipieLoader::zShapedRecipieList( const char* name )
  42. {
  43. for( ShapedRecipieList* l : shapedLists )
  44. {
  45. if( l->getName().istGleich( name ) )
  46. return l;
  47. }
  48. return 0;
  49. }
  50. void RecipieLoader::registerRecipieList( const char* name )
  51. {
  52. if( zRecipieList( name ) )
  53. throw new std::invalid_argument( "the recipie list already exists" );
  54. lists.add( new RecipieList( name ) );
  55. }
  56. void RecipieLoader::registerShapedRecipieList( const char* name )
  57. {
  58. if( zShapedRecipieList( name ) )
  59. throw new std::invalid_argument( "the recipie list already exists" );
  60. shapedLists.add( new ShapedRecipieList( name ) );
  61. }