Atoms Crowd  4.1.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 }
AtomsGraph::PortTemplate::copyValue
virtual void copyValue(Port *other)
Copy data from a port.
Definition: PortTemplate.impl.h:13
AtomsGraph::PortTemplate::get
T get() const
Gets data.
Definition: PortTemplate.impl.h:48
AtomsGraph::PortTemplate::getRef
const T & getRef() const
Gets a reference of the port data.
Definition: PortTemplate.impl.h:58
AtomsGraph::PortTemplate::~PortTemplate
~PortTemplate()
Destructor.
Definition: PortTemplate.impl.h:29
AtomsGraph::PortTemplate::typeStr
virtual std::string typeStr() const
Gets the type string of this node.
Definition: PortTemplate.impl.h:34
AtomsGraph::PortTemplate::staticTypeStr
static std::string staticTypeStr()
Gets the type string of this node type.
AtomsGraph::PortTemplate::setLink
void setLink(T *value)
Set this port in link mode.
Definition: PortTemplate.impl.h:79
AtomsGraph::PortTemplate::PortTemplate
PortTemplate(const std::string &name)
Constructor.
Definition: PortTemplate.impl.h:20
AtomsGraph::Port::reset
virtual void reset()
Reset the port to default value.
AtomsGraph::PortTemplate
Generic node port class.
Definition: PortTemplate.h:24
AtomsGraph::PortTemplate::reset
virtual void reset()
Reset port to the default value.
Definition: PortTemplate.impl.h:85
AtomsGraph
AtomsGraph namespace.
Definition: PosePort.h:15
AtomsGraph::Port
BasePort class.
Definition: Port.h:26
AtomsGraph::PortTemplate::set
void set(const T &value)
Sets the port data.
Definition: PortTemplate.impl.h:40