Atoms Crowd  7.0.0
PortTemplate.impl.h
1 // ===========================================================================
2 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
3 //
4 // Use of this software is subject to the terms of the Toolchefs license
5 // agreement provided at the time of installation or download, or which
6 // otherwise accompanies this software in either electronic or hard copy form.
7 // ===========================================================================
8 
9 namespace AtomsGraph
10 {
11 
12  template <class T>
14  {
15  this->m_value = (static_cast<PortTemplate<T>*>(other))->m_value;
16  this->m_link = (static_cast<PortTemplate<T>*>(other))->m_link;
17  }
18 
19  template <class T>
20  PortTemplate<T>::PortTemplate(const std::string& name) :
21  Port(name),
22  m_value(T()),
23  m_link(nullptr)
24  {
25  }
26 
27 
28  template <class T>
30  {
31  }
32 
33  template <class T>
34  std::string PortTemplate<T>::typeStr() const
35  {
37  }
38 
39  template <class T>
40  void PortTemplate<T>::set(const T& value)
41  {
42  m_value = value;
43  if (node() && isInput())
44  node()->setDirty(true);
45  }
46 
47  template <class T>
49  {
50  if (isInput() && (numConnections()>0))
51  return static_cast<PortTemplate<T>*>(input())->get();
52  if (m_link)
53  return *m_link;
54  return m_value;
55  }
56 
57  template <class T>
58  const T& PortTemplate<T>::getRef() const
59  {
60  if (isInput() && (numConnections()>0))
61  return static_cast<PortTemplate<T>*>(input())->getRef();
62  if (m_link)
63  return *m_link;
64  return m_value;
65  }
66 
67 
68  template <class T>
70  {
71  if (isInput() && (numConnections()>0))
72  return static_cast<PortTemplate<T>*>(input())->getRef();
73  if (m_link)
74  return *m_link;
75  return m_value;
76  }
77 
78  template <class T>
79  void PortTemplate<T>::setLink(T* value)
80  {
81  m_link = value;
82  }
83 
84  template <class T>
86  {
87  Port::reset();
88  m_value = T();
89  m_link = nullptr;
90  }
91 }
BasePort class.
Definition: Port.h:26
virtual void reset()
Reset the port to default value.
Generic node port class.
Definition: PortTemplate.h:24
virtual void copyValue(Port *other)
Copy data from a port.
Definition: PortTemplate.impl.h:13
virtual std::string typeStr() const
Gets the type string of this node.
Definition: PortTemplate.impl.h:34
virtual void reset()
Reset port to the default value.
Definition: PortTemplate.impl.h:85
void setLink(T *value)
Set this port in link mode.
Definition: PortTemplate.impl.h:79
const T & getRef() const
Gets a reference of the port data.
Definition: PortTemplate.impl.h:58
static std::string staticTypeStr()
Gets the type string of this node type.
T get() const
Gets data.
Definition: PortTemplate.impl.h:48
void set(const T &value)
Sets the port data.
Definition: PortTemplate.impl.h:40
PortTemplate(const std::string &name)
Constructor.
Definition: PortTemplate.impl.h:20
~PortTemplate()
Destructor.
Definition: PortTemplate.impl.h:29
AtomsGraph namespace.
Definition: PosePort.h:15