MCPcopy Create free account
hub / github.com/devosoft/avida / LoadResource

Method LoadResource

avida-core/source/main/cEnvironment.cc:474–661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

472
473
474bool cEnvironment::LoadResource(cString desc, Feedback& feedback)
475{
476 if (desc.GetSize() == 0) {
477 feedback.Warning("resource line with no resources listed");
478 return false;
479 }
480
481 while (desc.GetSize() > 0) {
482 cString cur_resource = desc.PopWord();
483 const cString name = cur_resource.Pop(':');
484
485 /* If resource does not already exist create it, however if it already
486 exists (for instance was created as a cell resource) pull it out of
487 the library and modify the existing values */
488
489 cResource* new_resource;
490 if (! resource_lib.DoesResourceExist(name)) {
491 new_resource = resource_lib.AddResource(name);
492 } else {
493 new_resource = resource_lib.GetResource(name);
494 }
495
496 while (cur_resource.GetSize() != 0) {
497 cString var_entry = cur_resource.Pop(':');
498 cString var_name;
499 cString var_value;
500 const cString var_type = cStringUtil::Stringf("resource '%s'", static_cast<const char*>(name));
501
502 // Parse this entry.
503 if (!ParseSetting(var_entry, var_name, var_value, var_type, feedback)) {
504 return false;
505 }
506
507 if (var_name == "inflow") {
508 if (!AssertInputDouble(var_value, "inflow", var_type, feedback)) return false;
509 new_resource->SetInflow( var_value.AsDouble() );
510 }
511 else if (var_name == "outflow") {
512 if (!AssertInputDouble(var_value, "outflow", var_type, feedback)) return false;
513 new_resource->SetOutflow( var_value.AsDouble() );
514 }
515 else if (var_name == "initial") {
516 if (!AssertInputDouble(var_value, "initial", var_type, feedback)) return false;
517 new_resource->SetInitial( var_value.AsDouble() );
518 }
519 else if (var_name == "geometry") {
520 if (!new_resource->SetGeometry( var_value )) {
521 feedback.Error("in %s, %s unknown geometry", (const char*)var_type, (const char*)var_value);
522 return false;
523 }
524 }
525 else if (var_name == "cells")
526 {
527 Apto::Array<int> cell_list = cStringUtil::ReturnArray(var_value);
528 new_resource->SetCellIdList(cell_list);
529 }
530 else if (var_name == "inflowx1" || var_name == "inflowx") {
531 if (!AssertInputInt(var_value, "inflowX1", var_type, feedback)) return false;

Callers

nothing calls this directly

Calls 15

PopWordMethod · 0.80
DoesResourceExistMethod · 0.80
AddResourceMethod · 0.80
SetCellIdListMethod · 0.80
SetXDiffuseMethod · 0.80
SetXGravityMethod · 0.80
SetYDiffuseMethod · 0.80
SetYGravityMethod · 0.80
SetCollectableMethod · 0.80
SetEnergyResourceMethod · 0.80
GetConfigMethod · 0.80
SetHGTMetabolizeMethod · 0.80

Tested by

no test coverage detected