Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07 / src / gtkmm / valuelink.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuelink.cpp
3 **      \brief ValueBase Link Implementation File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2004 Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "valuelink.h"
33
34 #endif
35
36 /* === U S I N G =========================================================== */
37
38 using namespace std;
39 using namespace etl;
40 using namespace synfig;
41
42 using studio::ValueBaseLink;
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 /* === P R O C E D U R E S ================================================= */
49
50 /* === M E T H O D S ======================================================= */
51
52 /* === E N T R Y P O I N T ================================================= */
53
54 //structors
55 ValueBaseLink::ValueBaseLink()
56 {
57 }
58
59 ValueBaseLink::~ValueBaseLink()
60 {
61 }
62
63 //link access
64
65 ValueNode::LooseHandle ValueBaseLink::get_link_vfunc(int i)const
66 {
67         /*list_type::const_iterator     it = list.begin();
68
69         while(it != list.end() && i-- > 0)
70         {
71                 ++it;
72         }
73
74         if(it == list.end())
75         {
76                 return ValueNode::LooseHandle();
77         }else
78         {
79                 return *it;
80         }*/
81         if(i >= 0 && i < (int)list.size())
82         {
83                 return list[i];
84         }else
85         {
86                 return ValueNode::LooseHandle();
87         }
88 }
89
90 //more link access
91 int ValueBaseLink::link_count()const
92 {
93         return list.size();
94 }
95
96 String ValueBaseLink::link_local_name(int i)const
97 {
98         ValueNode::LooseHandle h = get_link(i);
99
100         if(h)
101         {
102                 return h->get_local_name();
103         }else return String();
104 }
105
106 String ValueBaseLink::link_name(int i)const
107 {
108         ValueNode::LooseHandle h = get_link(i);
109
110         if(h)
111         {
112                 return h->get_name();
113         }else return String();
114 }
115
116 int ValueBaseLink::get_link_index_from_name(const String &name)const
117 {
118         throw Exception::BadLinkName(name);
119 }
120
121 //list management stuff
122 ValueBaseLink::list_type::const_iterator ValueBaseLink::findlink(ValueNode::Handle x) const
123 {
124         for(list_type::const_iterator i = list.begin(); i != list.end(); ++i)
125         {
126                 if(*i == x)
127                 {
128                         return i;
129                 }
130         }
131
132         return list.end();
133 }
134 ValueBaseLink::list_type::iterator ValueBaseLink::findlink(ValueNode::Handle x)
135 {
136         for(list_type::iterator i = list.begin(); i != list.end(); ++i)
137         {
138                 if(*i == x)
139                 {
140                         return i;
141                 }
142         }
143
144         return list.end();
145 }
146
147 void ValueBaseLink::add(ValueNode::Handle v)
148 {
149         list_type::iterator i = findlink(v);
150
151         if(i != list.end())
152         {
153                 list.push_back(v);
154         }
155 }
156
157 void ValueBaseLink::remove(ValueNode::Handle v)
158 {
159         list_type::iterator i = findlink(v);
160
161         if(i != list.end())
162         {
163                 if(i != list.end()-1)
164                 {
165                         *i = list.back();
166                 }
167                 list.pop_back();
168         }
169 }