forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputoutput.cpp
171 lines (138 loc) · 4.51 KB
/
inputoutput.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include <tier0/dbg.h>
#include "fgdlib/InputOutput.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
typedef struct
{
InputOutputType_t eType; // The enumeration of this type.
const char *pszName; // The name of this type.
} TypeMap_t;
const char *CClassInputOutputBase::g_pszEmpty = "";
//-----------------------------------------------------------------------------
// Maps type names to type enums for inputs and outputs.
//-----------------------------------------------------------------------------
static TypeMap_t TypeMap[] =
{
{ iotVoid, "void" },
{ iotInt, "integer" },
{ iotBool, "bool" },
{ iotString, "string" },
{ iotFloat, "float" },
{ iotVector, "vector" },
{ iotEHandle, "target_destination" },
{ iotColor, "color255" },
{ iotEHandle, "ehandle" }, // for backwards compatibility
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CClassInputOutputBase::CClassInputOutputBase(void)
{
m_eType = iotInvalid;
m_pszDescription = NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : pszName -
// eType -
//-----------------------------------------------------------------------------
CClassInputOutputBase::CClassInputOutputBase(const char *pszName, InputOutputType_t eType)
{
m_pszDescription = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Destructor.
//-----------------------------------------------------------------------------
CClassInputOutputBase::~CClassInputOutputBase(void)
{
delete m_pszDescription;
m_pszDescription = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Returns a string representing the type of this I/O, eg. "integer".
//-----------------------------------------------------------------------------
const char *CClassInputOutputBase::GetTypeText(void)
{
for (int i = 0; i < sizeof(TypeMap) / sizeof(TypeMap[0]); i++)
{
if (TypeMap[i].eType == m_eType)
{
return(TypeMap[i].pszName);
}
}
return("unknown");
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : szType -
// Output : InputOutputType_t
//-----------------------------------------------------------------------------
InputOutputType_t CClassInputOutputBase::SetType(const char *szType)
{
for (int i = 0; i < sizeof(TypeMap) / sizeof(TypeMap[0]); i++)
{
if (!stricmp(TypeMap[i].pszName, szType))
{
m_eType = TypeMap[i].eType;
return(m_eType);
}
}
return(iotInvalid);
}
//-----------------------------------------------------------------------------
// Purpose: Assignment operator.
//-----------------------------------------------------------------------------
CClassInputOutputBase &CClassInputOutputBase::operator =(CClassInputOutputBase &Other)
{
strcpy(m_szName, Other.m_szName);
m_eType = Other.m_eType;
//
// Copy the description.
//
delete m_pszDescription;
if (Other.m_pszDescription != NULL)
{
m_pszDescription = new char[strlen(Other.m_pszDescription) + 1];
strcpy(m_pszDescription, Other.m_pszDescription);
}
else
{
m_pszDescription = NULL;
}
return(*this);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CClassInput::CClassInput(void)
{
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : pszName -
// eType -
//-----------------------------------------------------------------------------
CClassInput::CClassInput(const char *pszName, InputOutputType_t eType)
: CClassInputOutputBase(pszName, eType)
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CClassOutput::CClassOutput(void)
{
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : pszName -
// eType -
//-----------------------------------------------------------------------------
CClassOutput::CClassOutput(const char *pszName, InputOutputType_t eType)
: CClassInputOutputBase(pszName, eType)
{
}