cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsMulticastCommandWrite.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5  Author(s): Ankur Kapoor, Peter Kazanzides, Anton Deguet
6  Created on: 2004-04-30
7 
8  (C) Copyright 2004-2014 Johns Hopkins University (JHU), All Rights
9  Reserved.
10 
11 --- begin cisst license - do not edit ---
12 
13 This software is provided "as is" under an open source license, with
14 no warranty. The complete license can be found in license.txt and
15 http://www.cisst.org/cisst/license.txt.
16 
17 --- end cisst license ---
18 */
19 
20 
27 #ifndef _mtsMulticastCommandWrite_h
28 #define _mtsMulticastCommandWrite_h
29 
30 
33 #include <vector>
34 
35 // Always include last
37 
44 template <class _argumentType>
46 {
47 public:
49  typedef _argumentType ArgumentType; // does not need to derive from mtsGenericObject
50  typedef typename mtsGenericTypes<ArgumentType>::FinalBaseType ArgumentFinalType; // derived from mtsGenericObject
51 
52 public:
54  mtsMulticastCommandWrite(const std::string & name, const ArgumentType & argumentPrototype):
55  BaseType(name)
56  {
57  //this->ArgumentPrototype = new ArgumentType(argumentPrototype);
59  }
60 
63  if (this->ArgumentPrototype) {
64  delete this->ArgumentPrototype;
65  }
66  }
67 
69  virtual mtsExecutionResult Execute(const mtsGenericObject & argument,
70  mtsBlockingType CMN_UNUSED(blocking)) {
71  // cast argument first
72  const ArgumentFinalType * data = dynamic_cast< const ArgumentFinalType * >(&argument);
73  if (data == 0) {
75  }
76  // if cast succeeded call using actual type
77  size_t index;
78  const size_t commandsSize = Commands.size();
79  for (index = 0; index < commandsSize; index++) {
80  Commands[index]->Execute(*data, MTS_NOT_BLOCKING);
81  }
83  }
84 
85  inline mtsExecutionResult Execute(const mtsGenericObject & argument, mtsBlockingType blocking,
86  mtsCommandWriteBase * CMN_UNUSED(finishedEventHandler)) {
87  return Execute(argument, blocking);
88  }
89 };
90 
91 
92 
94 {
95 public:
97 
98 public:
100  mtsMulticastCommandWriteGeneric(const std::string & name,
101  const mtsGenericObject & argumentPrototype):
102  BaseType(name)
103  {
104  this->ArgumentPrototype = dynamic_cast<mtsGenericObject*>(argumentPrototype.Services()->Create(argumentPrototype));
105  }
106 
109  if (this->ArgumentPrototype) {
110  delete this->ArgumentPrototype;
111  }
112  }
113 
115  virtual mtsExecutionResult Execute(const mtsGenericObject & argument,
116  mtsBlockingType CMN_UNUSED(blocking)) {
117  // cast argument first
118 
119  if (typeid(argument) != typeid(*(this->ArgumentPrototype))) {
121  }
122  // if cast succeeded call using actual type
123  size_t index;
124  const size_t commandsSize = Commands.size();
125  for (index = 0; index < commandsSize; index++) {
126  Commands[index]->Execute(argument, MTS_NOT_BLOCKING);
127  }
129  }
130 
131  inline mtsExecutionResult Execute(const mtsGenericObject & argument, mtsBlockingType blocking,
132  mtsCommandWriteBase * CMN_UNUSED(finishedEventHandler)) {
133  return Execute(argument, blocking);
134  }
135 
136 };
137 
138 
139 #endif // _mtsMulticastCommandWrite_h
140 
Definition: mtsGenericObjectProxy.h:44
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
Definition: mtsForwardDeclarations.h:55
mtsExecutionResult Execute(const mtsGenericObject &argument, mtsBlockingType blocking, mtsCommandWriteBase *CMN_UNUSED(finishedEventHandler))
Definition: mtsMulticastCommandWrite.h:131
virtual mtsExecutionResult Execute(const mtsGenericObject &argument, mtsBlockingType CMN_UNUSED(blocking))
Definition: mtsMulticastCommandWrite.h:69
Base class for data object in cisstMultiTask.
Definition: mtsGenericObject.h:56
virtual const cmnClassServicesBase * Services(void) const =0
Defines a command with one argument sent to multiple interfaces.
mtsMulticastCommandWriteGeneric(const std::string &name, const mtsGenericObject &argumentPrototype)
Definition: mtsMulticastCommandWrite.h:100
mtsExecutionResult Execute(const mtsGenericObject &argument, mtsBlockingType blocking, mtsCommandWriteBase *CMN_UNUSED(finishedEventHandler))
Definition: mtsMulticastCommandWrite.h:85
VectorType Commands
Definition: mtsMulticastCommandWriteBase.h:50
mtsMulticastCommandWriteBase BaseType
Definition: mtsMulticastCommandWrite.h:96
mtsGenericTypes< ArgumentType >::FinalBaseType ArgumentFinalType
Definition: mtsMulticastCommandWrite.h:50
_argumentType ArgumentType
Definition: mtsMulticastCommandWrite.h:49
Definition: mtsCommandWriteBase.h:40
const mtsGenericObject * ArgumentPrototype
Definition: mtsCommandWriteBase.h:109
mtsMulticastCommandWriteBase BaseType
Definition: mtsMulticastCommandWrite.h:48
Definition: mtsMulticastCommandWrite.h:93
Definition: mtsForwardDeclarations.h:115
Definition: mtsMulticastCommandWriteBase.h:43
~mtsMulticastCommandWrite()
Definition: mtsMulticastCommandWrite.h:62
Definition: mtsExecutionResult.h:34
Definition: mtsExecutionResult.h:44
Rules of exporting.
virtual mtsExecutionResult Execute(const mtsGenericObject &argument, mtsBlockingType CMN_UNUSED(blocking))
Definition: mtsMulticastCommandWrite.h:115
Definition: mtsCommandBase.h:43
mtsBlockingType
Definition: mtsForwardDeclarations.h:55
Definition: mtsExecutionResult.h:44
mtsMulticastCommandWrite(const std::string &name, const ArgumentType &argumentPrototype)
Definition: mtsMulticastCommandWrite.h:54
~mtsMulticastCommandWriteGeneric()
Definition: mtsMulticastCommandWrite.h:108
virtual cmnGenericObject * Create(void) const =0
static mtsGenericObject * ConditionalCreate(const T &arg, const std::string &name)
Definition: mtsGenericObjectProxy.h:676