Graphite Version 3
An experimental 3D geometry processing program
Loading...
Searching...
No Matches
connection.h
Go to the documentation of this file.
1/*
2 * GXML/Graphite: Geometry and Graphics Programming Library + Utilities
3 * Copyright (C) 2000 Bruno Levy
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * If you modify this software, you should include a notice giving the
20 * name of the person performing the modification, the date of modification,
21 * and the reason for such modification.
22 *
23 * Contact: Bruno Levy
24 *
25 * levy@loria.fr
26 *
27 * ISA Project
28 * LORIA, INRIA Lorraine,
29 * Campus Scientifique, BP 239
30 * 54506 VANDOEUVRE LES NANCY CEDEX
31 * FRANCE
32 *
33 * Note that the GNU General Public License does not permit incorporating
34 * the Software into proprietary programs.
35 */
36
37#ifndef H_OGF_GOM_TYPES_CONNECTION_H
38#define H_OGF_GOM_TYPES_CONNECTION_H
39
41#include <OGF/gom/types/callable.h>
42
43#include <string>
44#include <vector>
45#include <set>
46
51namespace OGF {
52
53 class ConnectionList;
54
55 /******************************************************************/
56
65 gom_attribute(abstract, "true")
66 gom_class GOM_API Connection : public Callable {
67 public:
68
75 Object* source, const std::string& sig_name
76 );
77
81 ~Connection() override;
82
90 bool invoke(const ArgList& args, Any& ret_val) override;
91
92
99 virtual bool invoke_target(
100 const ArgList& args, Any& ret_val
101 ) = 0;
102
107 Object* source() const {
108 return source_;
109 }
110
115 const std::string& signal_name() const {
116 return signal_name_;
117 }
118
119 gom_slots:
120
132 Connection* if_arg(
133 const std::string& name, const std::string& value
134 ) {
135 if(conditions_.has_arg(name)) {
136 Logger::err("GOM")
137 << "if_arg(): duplicate condition for " << name
138 << std::endl;
139 return this;
140 }
141 conditions_.create_arg(name, value);
142 return this;
143 }
144
154 Connection* add_arg(const std::string& name, const std::string& value) {
155 if(args_.has_arg(name)) {
156 Logger::err("GOM")
157 << "add_arg(): argument " << name
158 << " already exists"
159 << std::endl;
160 return this;
161 }
162 args_.create_arg(name, value);
163 return this;
164 }
165
176 const std::string& name, const std::string& new_name
177 ) {
178 if(rename_args_.has_arg(name)) {
179 Logger::err("GOM")
180 << "rename_arg(): duplicate rename for " << name
181 << std::endl;
182 return this;
183 }
184 rename_args_.create_arg(name, new_name);
185 return this;
186 }
187
196 Connection* discard_arg(const std::string& name) {
197 discard_args_.insert(name);
198 return this;
199 }
200
205 void remove();
206
207 protected:
216 bool test_arg_conditions(const ArgList& args) const;
217
228 const std::string& value, const std::string& condition
229 ) const;
230
237 void translate_args(const ArgList& args_in, ArgList& args_out);
238
239 private:
240 Object* source_;
241 std::string signal_name_;
242 ArgList conditions_;
243 ArgList args_;
244 ArgList rename_args_;
245 std::set<std::string> discard_args_;
246 };
247
252
253 /**********************************************************************/
254
258 gom_class GOM_API SlotConnection : public Connection {
259 public:
269 Object* source, const std::string& sig_name,
270 Object* target, const std::string& slot_name
271 );
272
277 const ArgList& args, Any& ret_val
278 ) override;
279
280 private:
281 Object* target_;
282 std::string slot_name_;
283 };
284
285 /**********************************************************************/
286
294 gom_class GOM_API CallableConnection : public Connection {
295 public:
304 Object* source, const std::string& sig_name, Callable* target
305 );
306
311 const ArgList& args, Any& ret_val
312 ) override;
313
314 private:
315 Callable_var target_;
316 };
317
318
319 /**********************************************************************/
320
325 class ConnectionList : public std::vector<Connection_var> {
326 public:
331 void invoke(const ArgList& args) {
332 Any ret_val;
333 for(unsigned int i=0; i<size(); i++) {
334 (*this)[i]->invoke(args, ret_val);
335 }
336 }
337
343 void remove(Connection* conn) {
344 std::vector<Connection_var>::iterator it = this->begin();
345 while(it != this->end()) {
346 if(it->get() == conn) {
347 erase(it);
348 return;
349 }
350 ++it;
351 }
353 }
354 };
355
356 /******************************************************************/
357
358}
359
360#endif
#define geo_assert_not_reached
Sets a non reachable point in the program.
Definition assert.h:177
A smart pointer with reference-counted copy semantics.
A class that stores a variable of arbitrary type.
Definition any.h:62
Represents a list of name-value pairs.
Definition arg_list.h:65
A Connection between a signal and an abstract Callable object.
Definition connection.h:294
bool invoke_target(const ArgList &args, Any &ret_val) override
Directly invokes the target with an arguments list, without any argument translation.
CallableConnection(Object *source, const std::string &sig_name, Callable *target)
CallableConnection constructor.
A Callable object.
Definition callable.h:50
A list of connections.
Definition connection.h:325
void remove(Connection *conn)
Removes a connection from a ConnectionList.
Definition connection.h:343
void invoke(const ArgList &args)
Invokes all the connected slots.
Definition connection.h:331
Connection * discard_arg(const std::string &name)
Discards an argument.
Definition connection.h:196
virtual bool invoke_target(const ArgList &args, Any &ret_val)=0
Directly invokes the target with an arguments list, without any argument translation.
const std::string & signal_name() const
Gets the signal name.
Definition connection.h:115
void remove()
Removes this connection from the slot it is connected to.
Connection * rename_arg(const std::string &name, const std::string &new_name)
Renames an argument.
Definition connection.h:175
bool invoke(const ArgList &args, Any &ret_val) override
Invokes the target with an arguments list.
bool test_arg_conditions(const ArgList &args) const
Tests whether an argument list satisfies the argument conditions.
void translate_args(const ArgList &args_in, ArgList &args_out)
Applies all the argument list transformations.
Connection * add_arg(const std::string &name, const std::string &value)
Adds an argument.
Definition connection.h:154
bool test_arg_condition(const std::string &value, const std::string &condition) const
Tests whether an argument satisfies a condition.
Object * source() const
Gets the source.
Definition connection.h:107
Connection(Object *source, const std::string &sig_name)
Connection constructor.
~Connection() override
Connection destructor.
Base class for all objects in the GOM system.
Definition object.h:65
A Connection between a signal and a slot.
Definition connection.h:258
SlotConnection(Object *source, const std::string &sig_name, Object *target, const std::string &slot_name)
SlotConnection constructor.
bool invoke_target(const ArgList &args, Any &ret_val) override
Directly invokes the target with an arguments list, without any argument translation.
Global Graphite namespace.
Definition common.h:76
SmartPointer< Connection > Connection_var
An automatic reference-counted pointer to a Connection.
Definition connection.h:251
Definitions common to all include files in the gom library.