RigsofRods
Soft-body Physics Simulation
RigDef_Node.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
25 
26 #include "RigDef_Node.h"
27 
28 #include "Application.h"
29 
30 using namespace RigDef;
31 
32 // Ctors
33 
35  m_id_num(0),
36  m_flags(0)
37 {}
38 
39 Node::Id::Id(unsigned int num):
40  m_id_num(num),
41  m_flags(0)
42 {
43  this->SetNum(num);
44 }
45 
46 Node::Id::Id(std::string const & id_str):
47  m_id_num(0),
48  m_flags(0)
49 {
50  this->setStr(id_str);
51 }
52 
53 // Setters
54 
55 void Node::Id::SetNum(unsigned int num)
56 {
57  m_id_num = num;
58  m_id_str = TOSTRING(num);
59  BITMASK_SET_0(m_flags, IS_TYPE_NAMED);
60  BITMASK_SET_1(m_flags, IS_TYPE_NUMBERED | IS_VALID);
61 }
62 
63 void Node::Id::setStr(std::string const & id_str)
64 {
65  m_id_num = 0;
66  m_id_str = id_str;
67  BITMASK_SET_0(m_flags, IS_TYPE_NUMBERED);
68  BITMASK_SET_1(m_flags, IS_TYPE_NAMED | IS_VALID);
69 }
70 
71 // Util
73 {
74  m_id_num = 0;
75  m_id_str.clear();
76  m_flags = 0;
77 }
78 
79 Node::Ref::Ref(std::string const & id_str, unsigned int id_num, unsigned flags, unsigned line_number):
80  m_flags(0),
81  m_line_number(line_number),
82  m_id_as_number(id_num)
83 {
84  m_id = id_str;
85  BITMASK_SET_1(m_flags, flags);
86 }
87 
89  m_flags(0),
90  m_id_as_number(0),
91  m_line_number(0)
92 {
93 }
94 
96 {
97  m_id_as_number = 0;
98  m_id.clear();
99  m_flags = 0;
100  m_line_number = 0;
101 }
102 
103 std::string Node::Ref::ToString() const
104 {
105  std::stringstream msg;
106  msg << "Node::Ref(id:" << m_id
107  << ", src line:";
108  if (m_line_number != 0)
109  {
110  msg << m_line_number;
111  }
112  else
113  {
114  msg << "?";
115  }
116  msg << ", import flags:[";
117  if(GetImportState_IsValid ()) { msg << " VALID" ; }
118  if(GetImportState_MustCheckNamedFirst ()) { msg << " CHECK_NAMED_FIRST"; }
119  if(GetImportState_IsResolvedNamed ()) { msg << " RESOLVED_NAMED" ; }
120  if(GetImportState_IsResolvedNumbered ()) { msg << " RESOLVED_NUMBERED"; }
121  msg << "], regular flags:[";
122  if(GetRegularState_IsValid ()) { msg << " VALID" ; }
123  if(GetRegularState_IsNamed ()) { msg << " NAMED" ; }
124  if(GetRegularState_IsNumbered ()) { msg << " NUMBERED" ; }
125  msg << "])";
126  return msg.str();
127 }
128 
129 std::string Node::Id::ToString() const
130 {
131  return std::string("Node::Id(") + this->Str() + (this->IsTypeNumbered() ? " NUMBERED)" : " NAMED)");
132 }
RigDef::Node::Ref::m_flags
unsigned int m_flags
Definition: RigDef_Node.h:110
RigDef_Node.h
RigDef::Node::Ref::ToString
std::string ToString() const
Definition: RigDef_Node.cpp:103
RigDef::Node::Id::SetNum
void SetNum(unsigned int id_num)
Definition: RigDef_Node.cpp:55
RigDef::Node::Ref::Invalidate
void Invalidate()
Definition: RigDef_Node.cpp:95
RigDef::Node::Id::Id
Id()
Definition: RigDef_Node.cpp:34
BITMASK_SET_0
#define BITMASK_SET_0(VAR, FLAGS)
Definition: BitFlags.h:16
TOSTRING
#define TOSTRING(x)
Definition: Application.h:56
RigDef
Definition: RigDef_File.cpp:32
BITMASK_SET_1
#define BITMASK_SET_1(VAR, FLAGS)
Definition: BitFlags.h:17
RigDef::Node::Id::Invalidate
void Invalidate()
Definition: RigDef_Node.cpp:72
Application.h
Central state/object manager and communications hub.
RigDef::Node::Ref::Ref
Ref()
Definition: RigDef_Node.cpp:88
RigDef::Node::Id::setStr
void setStr(std::string const &id_str)
Definition: RigDef_Node.cpp:63
RigDef::Node::Id::ToString
std::string ToString() const
Definition: RigDef_Node.cpp:129
RigDef::Node::Ref::m_id
std::string m_id
Definition: RigDef_Node.h:108