hx3d  1
2D/3D Simple Game Framework
node.inl.hpp
1 /*
2  Entity Component System: Base Node.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library 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 GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #include "hx3d/ecs/scene_graph.hpp"
22 
23 namespace hx3d {
24 namespace ecs {
25 
26 template <class T, class... Args>
27 Ptr<T> Node::createChild(SceneGraph& sg, const std::string name, Args... args) {
28  return sg.template createNodeChild<T>(this->shared_from_this(), name, args...);
29 }
30 
31 
32 template <class T>
33 Ptr<T> Node::getChild(const std::string name) {
34  for (const Ptr<Node>& obj: _children) {
35  if (obj->_name == name) {
36  return std::dynamic_pointer_cast<T>(obj);
37  }
38  }
39 
40  Log.Error("Node: child `%s` does not exists.", name.c_str());
41  return nullptr;
42 }
43 
44 } /* ecs */
45 } /* hx3d */
hx3d framework namespace
Definition: audio.hpp:26
std::vector< Ptr< Node > > _children
Children nodes.
Definition: node.hpp:149
Node management in hierarchy.
Definition: scene_graph.hpp:43
void Error(const std::string fmt,...)
Write an error message.
Definition: log.cpp:72
static hx3d::LogImpl Log
Current log implementation.
Definition: log.hpp:91
Ptr< T > createChild(SceneGraph &sg, const std::string name, Args...args)
Create a new child Node, using the SceneGraph.
Definition: node.inl.hpp:27
Ptr< T > getChild(const std::string name)
Get one child.
Definition: node.inl.hpp:33
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34