Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / 0.61.08 / 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 #include "general.h"
35
36 #endif
37
38 /* === U S I N G =========================================================== */
39
40 using namespace std;
41 using namespace etl;
42 using namespace synfig;
43
44 using studio::ValueBaseLink;
45
46 /* === M A C R O S ========================================================= */
47
48 /* === G L O B A L S ======================================================= */
49
50 /* === P R O C E D U R E S ================================================= */
51
52 /* === M E T H O D S ======================================================= */
53
54 /* === E N T R Y P O I N T ================================================= */
55
56 //structors
57 ValueBaseLink::ValueBaseLink()
58 {
59 }
60
61 ValueBaseLink::~ValueBaseLink()
62 {
63 }
64
65 //link access
66
67 ValueNode::LooseHandle ValueBaseLink::get_link_vfunc(int i)const
68 {
69         /*list_type::const_iterator     it = list.begin();
70
71         while(it != list.end() && i-- > 0)
72         {
73                 ++it;
74         }
75
76         if(it == list.end())
77         {
78                 return ValueNode::LooseHandle();
79         }else
80         {
81                 return *it;
82         }*/
83         if(i >= 0 && i < (int)list.size())
84         {
85                 return list[i];
86         }else
87         {
88                 return ValueNode::LooseHandle();
89         }
90 }
91
92 //more link access
93 int ValueBaseLink::link_count()const
94 {
95         return list.size();
96 }
97
98 String ValueBaseLink::link_local_name(int i)const
99 {
100         ValueNode::LooseHandle h = get_link(i);
101
102         if(h)
103         {
104                 return h->get_local_name();
105         }else return String();
106 }
107
108 String ValueBaseLink::link_name(int i)const
109 {
110         ValueNode::LooseHandle h = get_link(i);
111
112         if(h)
113         {
114                 return h->get_name();
115         }else return String();
116 }
117
118 int ValueBaseLink::get_link_index_from_name(const synfig::String &name)const
119 {
120         throw Exception::BadLinkName(name);
121 }
122
123 //list management stuff
124 ValueBaseLink::list_type::const_iterator ValueBaseLink::findlink(synfig::ValueNode::Handle x) const
125 {
126         for(list_type::const_iterator i = list.begin(); i != list.end(); ++i)
127         {
128                 if(*i == x)
129                 {
130                         return i;
131                 }
132         }
133
134         return list.end();
135 }
136 ValueBaseLink::list_type::iterator ValueBaseLink::findlink(synfig::ValueNode::Handle x)
137 {
138         for(list_type::iterator i = list.begin(); i != list.end(); ++i)
139         {
140                 if(*i == x)
141                 {
142                         return i;
143                 }
144         }
145
146         return list.end();
147 }
148
149 void ValueBaseLink::add(synfig::ValueNode::Handle v)
150 {
151         list_type::iterator i = findlink(v);
152
153         if(i != list.end())
154         {
155                 list.push_back(v);
156         }
157 }
158
159 void ValueBaseLink::remove(synfig::ValueNode::Handle v)
160 {
161         list_type::iterator i = findlink(v);
162
163         if(i != list.end())
164         {
165                 if(i != list.end()-1)
166                 {
167                         *i = list.back();
168                 }
169                 list.pop_back();
170         }
171 }