-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMListStrStr.cpp
149 lines (134 loc) · 3.11 KB
/
MListStrStr.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
/////////////////////////////////////////////////////////////////////////////
//MListStrStr.cpp
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MListStrStr.h"
/////////////////////////////////////////////////////////////////////////////
//FUNCTIONS PRIVATE
/////////////////////////////////////////////////////////////////////////////
//udalenie spiska parametrov
int MListStrStr::DeleteListStrStr()
{
NodeStrStr* SelNode = 0;
NodeStrStr* TmpNode = 0;
if (m_FirstNode)
{
SelNode = m_FirstNode;
//cikl po vsem elementam - uzlam
while (1)
{
if (SelNode)
{
//imya
if (SelNode->Name)
{
delete[] SelNode->Name;
SelNode->Name = 0;
}
//znachenie
if (SelNode->Value)
{
delete[] SelNode->Value;
SelNode->Value = 0;
}
TmpNode = SelNode;
SelNode = SelNode->Next; //sleduyushiy element - uzel
delete TmpNode;
}
else break;
}
}
return 1;
}
/////////////////////////////////////////////////////////////////////////////
//Construction/Destruction
/////////////////////////////////////////////////////////////////////////////
MListStrStr::~MListStrStr()
{
//udalenie spiska parametrov
DeleteListStrStr();
m_FirstNode = 0;
m_LastNode = 0;
}
/////////////////////////////////////////////////////////////////////////////
//FUNCTIONS PUBLIC
/////////////////////////////////////////////////////////////////////////////
//dobavit' v spisok uzel
//name - imya parametra (imya wcx-plagina)
//value - znachenie parametra (put' k plaginu)
//return
// 1 - uzel dobavlen
// 0 - uzel ne dobavlen
int MListStrStr::AddNode(const char* name, const char* value)
{
int len = 0;
//sozdaem uzel
NodeStrStr* NewNode;
NewNode = new NodeStrStr;
//imya
len = strlen(name);
if (len)
{
NewNode->Name = new char[len+1];
strcpy(NewNode->Name, name);
}
else NewNode->Name = 0;
//znachenie
len = strlen(value);
if (len)
{
NewNode->Value = new char[len+1];
strcpy(NewNode->Value, value);
}
else NewNode->Value = 0;
//ostal'noe
NewNode->Next = 0;
//perviy parametr ili net
if (m_NumberNodes == 0)
{
m_FirstNode = NewNode;
m_LastNode = NewNode;
}
else
{
m_LastNode->Next = NewNode;
m_LastNode = NewNode;
}
//+1 uzel
m_NumberNodes++;
return 1;
}
//nayti uzel po imeni
//name - imya parametra
//return
// Node - naydenniy uzel
// 0 - uzel ne nayden
NodeStrStr* MListStrStr::SearchNodeFromName(const char* name)
{
NodeStrStr* Node = 0;
Node = m_FirstNode;
//cikl po vsem elementam - uzlam
while (Node)
{
if (strcmp(Node->Name, name) == 0) return Node;
Node = Node->Next;
}
return 0;
}
//nayti uzel po znacheniyu
//name - imya parametra
//return
// Node - naydenniy uzel
// 0 - uzel ne nayden
NodeStrStr* MListStrStr::SearchNodeFromValue(const char* value)
{
NodeStrStr* Node = 0;
Node = m_FirstNode;
//cikl po vsem elementam - uzlam
while (Node)
{
if (strcmp(Node->Value, value) == 0) return Node;
Node = Node->Next;
}
return 0;
}