Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
single_copy.cpp
1 
2 /***************************************************************************
3  * single_copy.cpp - Fawkes WorldModel Single Interface Copy Fuser
4  *
5  * Created: Tue Jan 13 11:46:30 2009
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program 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
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "single_copy.h"
24 
25 #include <blackboard/blackboard.h>
26 #include <interface/interface.h>
27 
28 using namespace fawkes;
29 
30 /** @class WorldModelSingleCopyFuser "single_copy.h"
31  * Single interface copy fuser.
32  * This fuser simply copies the data of one interface to another of the same
33  * type.
34  * @author Tim Niemueller
35  */
36 
37 /** Constructor.
38  * @param blackboard BlackBoard
39  * @param type interface type of both interfaces
40  * @param from_id ID of the interface to copy from
41  * @param to_id ID of the interface to copy to
42  */
44  const char *type,
45  const char *from_id,
46  const char *to_id)
47 {
48  __blackboard = blackboard;
49  __from = blackboard->open_for_reading(type, from_id);
50  __to = blackboard->open_for_writing(type, to_id);
51 
52  __from->read();
53  __to->copy_values(__from);
54  __to->write();
55 }
56 
57 
58 /** Destructor. */
60 {
61  __blackboard->close(__from);
62  __blackboard->close(__to);
63 }
64 
65 
66 void
68 {
69  if (__from->has_writer()) {
70  __from->read();
71  __to->copy_values(__from);
72  __to->write();
73  }
74 }
WorldModelSingleCopyFuser(fawkes::BlackBoard *blackboard, const char *type, const char *from_id, const char *to_id)
Constructor.
Definition: single_copy.cpp:43
~WorldModelSingleCopyFuser()
Destructor.
Definition: single_copy.cpp:59
virtual Interface * open_for_writing(const char *interface_type, const char *identifier)=0
Open interface for writing.
virtual void fuse()
The single function that makes fusers work.
Definition: single_copy.cpp:67
void read()
Read from BlackBoard into local copy.
Definition: interface.cpp:472
virtual Interface * open_for_reading(const char *interface_type, const char *identifier)=0
Open interface for reading.
The BlackBoard abstract class.
Definition: blackboard.h:49