grab stable branch
[synfig.git] / synfig-studio / tags / stable / src / gtkmm / valuelink.cpp
1 /* === S I N F G =========================================================== */
2 /*!     \file valuelink.cpp
3 **      \brief ValueBase Link Implementation File
4 **
5 **      $Id: valuelink.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2004 Adrian Bentley
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "valuelink.h"
32
33 #endif
34
35 /* === U S I N G =========================================================== */
36
37 using namespace std;
38 using namespace etl;
39 using namespace sinfg;
40
41 using studio::ValueBaseLink;
42
43 /* === M A C R O S ========================================================= */
44
45 /* === G L O B A L S ======================================================= */
46
47 /* === P R O C E D U R E S ================================================= */
48
49 /* === M E T H O D S ======================================================= */
50
51 /* === E N T R Y P O I N T ================================================= */
52
53 //structors
54 ValueBaseLink::ValueBaseLink()
55 {
56 }
57
58 ValueBaseLink::~ValueBaseLink()
59 {
60 }
61
62 //link access
63
64 ValueNode::LooseHandle ValueBaseLink::get_link_vfunc(int i)const
65 {
66         /*list_type::const_iterator     it = list.begin();
67         
68         while(it != list.end() && i-- > 0)
69         {
70                 ++it;
71         }
72         
73         if(it == list.end())
74         {
75                 return ValueNode::LooseHandle();
76         }else
77         {
78                 return *it;
79         }*/
80         if(i >= 0 && i < (int)list.size())
81         {
82                 return list[i];
83         }else
84         {
85                 return ValueNode::LooseHandle();
86         }
87 }
88
89 //more link access
90 int ValueBaseLink::link_count()const
91 {
92         return list.size();
93 }
94
95 String ValueBaseLink::link_local_name(int i)const
96 {
97         ValueNode::LooseHandle h = get_link(i);
98
99         if(h)
100         {
101                 return h->get_local_name();             
102         }else return String();
103 }
104
105 String ValueBaseLink::link_name(int i)const
106 {
107         ValueNode::LooseHandle h = get_link(i);
108
109         if(h)
110         {
111                 return h->get_name();
112         }else return String();
113 }
114
115 int ValueBaseLink::get_link_index_from_name(const String &name)const
116 {
117         throw Exception::BadLinkName(name);
118 }
119
120 //list management stuff
121 ValueBaseLink::list_type::const_iterator ValueBaseLink::findlink(ValueNode::Handle x) const
122 {
123         for(list_type::const_iterator i = list.begin(); i != list.end(); ++i)
124         {
125                 if(*i == x)
126                 {
127                         return i;
128                 }
129         }
130         
131         return list.end();
132 }
133 ValueBaseLink::list_type::iterator ValueBaseLink::findlink(ValueNode::Handle x)
134 {
135         for(list_type::iterator i = list.begin(); i != list.end(); ++i)
136         {
137                 if(*i == x)
138                 {
139                         return i;
140                 }
141         }
142         
143         return list.end();
144 }
145
146 void ValueBaseLink::add(ValueNode::Handle v)
147 {
148         list_type::iterator i = findlink(v);
149         
150         if(i != list.end())
151         {
152                 list.push_back(v);
153         }
154 }
155
156 void ValueBaseLink::remove(ValueNode::Handle v)
157 {
158         list_type::iterator i = findlink(v);
159         
160         if(i != list.end())
161         {
162                 if(i != list.end()-1)
163                 {
164                         *i = list.back();
165                 }
166                 list.pop_back();
167         }       
168 }