1 /* 2 * cReactionLib.cc 3 * Avida 4 * 5 * Called "reaction_lib.cc" prior to 12/5/05. 6 * Copyright 1999-2011 Michigan State University. All rights reserved. 7 * Copyright 1993-2001 California Institute of Technology. 8 * 9 * 10 * This file is part of Avida. 11 * 12 * Avida is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License 13 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 14 * 15 * Avida is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License along with Avida. 19 * If not, see <http://www.gnu.org/licenses/>. 20 * 21 */ 22 23 #include "cReactionLib.h" 24 25 #include "cReaction.h" 26 27 ~cReactionLib()28cReactionLib::~cReactionLib() 29 { 30 for (int i = 0; i < reaction_array.GetSize(); i++) { 31 delete reaction_array[i]; 32 } 33 } 34 35 GetReaction(const cString & name) const36cReaction * cReactionLib::GetReaction(const cString & name) const 37 { 38 for (int i = 0; i < reaction_array.GetSize(); i++) { 39 if (reaction_array[i]->GetName() == name) return reaction_array[i]; 40 } 41 return NULL; 42 } 43 GetReaction(int id) const44cReaction * cReactionLib::GetReaction(int id) const 45 { 46 return reaction_array[id]; 47 } 48 49 AddReaction(const cString & name)50cReaction * cReactionLib::AddReaction(const cString & name) 51 { 52 // If this reaction already exists, just return it. 53 cReaction * found_reaction = GetReaction(name); 54 if (found_reaction != NULL) return found_reaction; 55 56 // Create a new reaction... 57 const int new_id = reaction_array.GetSize(); 58 cReaction * new_reaction = new cReaction(name, new_id); 59 reaction_array.Resize(new_id + 1); 60 reaction_array[new_id] = new_reaction; 61 return new_reaction; 62 } 63