OpenASIP  2.0
PasteComponentCmd.icc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file PasteComponentCmd.icc
26  *
27  * Template function definitions for the PasteComponentCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  */
31 
32 #include "Machine.hh"
33 #include "Conversion.hh"
34 #include "MachinePart.hh"
35 
36 /**
37  * Adds a component to the machine.
38  *
39  * If the component name is reserved in the machine, an unreserved name will
40  * be generated by appending the name with an integer.
41  *
42  * @param machine Machine where the component is added.
43  * @param component The component to add.
44  * @param navigator Navigator which corresponds the type of the added
45  * component.
46  */
47 template <class ComponentNavigator>
48 void
49 PasteComponentCmd::paste(
50  TTAMachine::Machine& machine, TTAMachine::Component* component,
51  ComponentNavigator& navigator) {
52 
53  // If the name is reserved, generate unreserved name by appending
54  // an integer to the end of the name.
55  if (navigator.hasItem(component->name())) {
56  int i = 1;
57  while (navigator.hasItem(
58  component->name() + "_" +
59  Conversion::toString(i))) {
60  i++;
61  }
62  component->setName(component->name()+"_"+Conversion::toString(i));
63  }
64  component->setMachine(machine);
65 }