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

Method asArray

avida-core/source/script/cDirectInterpretASTVisitor.cc:1630–1667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1628}
1629
1630cDirectInterpretASTVisitor::cLocalArray* cDirectInterpretASTVisitor::asArray(const sASTypeInfo& type, uAnyType value, cASTNode& node)
1631{
1632 switch (type.type) {
1633 case TYPE(ARRAY):
1634 return value.as_array;
1635
1636 case TYPE(MATRIX):
1637 {
1638 cLocalMatrix* mat = value.as_matrix;
1639 cLocalArray* arr = new cLocalArray(mat->GetNumRows());
1640 uAnyType val;
1641 for (int i = 0; i < mat->GetNumRows(); i++) {
1642 val.as_array = new cLocalArray(mat->GetRow(i));
1643 arr->Set(i, TYPE(ARRAY), val);
1644 }
1645 mat->RemoveReference();
1646 return arr;
1647 }
1648
1649 case TYPE(STRING):
1650 {
1651 cString* str = value.as_string;
1652 cLocalArray* arr = new cLocalArray(str->GetSize());
1653 for (int i = 0; i < str->GetSize(); i++) {
1654 uAnyType val;
1655 val.as_char = (*str)[i];
1656 arr->Set(i, TYPE(CHAR), val);
1657 }
1658 delete str;
1659 return arr;
1660 }
1661
1662 default:
1663 INTERPRET_ERROR(TYPE_CAST, mapType(type), mapType(TYPE(ARRAY)));
1664 }
1665
1666 return false;
1667}
1668
1669bool cDirectInterpretASTVisitor::asBool(const sASTypeInfo& type, uAnyType value, cASTNode& node)
1670{

Callers

nothing calls this directly

Calls 5

GetRowMethod · 0.80
GetNumRowsMethod · 0.45
SetMethod · 0.45
RemoveReferenceMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected