-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfFileRead.cpp
More file actions
executable file
·164 lines (137 loc) · 3.14 KB
/
ConfFileRead.cpp
File metadata and controls
executable file
·164 lines (137 loc) · 3.14 KB
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
#include "ConfFileRead.h"
ReadConf::ReadConf( string filePath )
{
mRCPath = filePath;
if( !OpenConfFile( mRCPath ) )
{
return;
}
ReadConfFile();
}
bool ReadConf::OpenConfFile( string filePath )
{
if( ( mCF = fopen( filePath.c_str(),"r" ) ) == NULL )
{
cout<< " [Error] Can't open Conf File ! " << endl;
return false;
}
return true;
}
void ReadConf::ShowConfFile()
{
mCFVector.ShowValue();
}
int ReadConf::GetSubMsg( string &msg )
{
char buff[100];
strcpy( buff, msg.c_str() );
int head; //第一个英文字母处或者‘-’处
int tail; //最后一个英文字母或数字处
for( head = 0;head < msg.size(); head++ )
{
if( isalnum(buff[head]) || ( buff[head] == '-' ) )
{
break;
}
}
for( tail = head; tail < msg.size(); tail ++ )
{
if( buff[tail] == '\n' || buff[tail] == '\r' || buff[tail] == '\t'
|| buff[tail] == ' ' || ((!isalnum(buff[tail]) && buff[tail] != '.' && buff[tail] != '-' && buff[tail] != '_' )) )
{
break;
}
}
msg.assign( msg.begin() + head, msg.begin() + tail );
return tail;
}
bool ReadConf::GetOneLineConf( string msg )
{
int head = 0;
string subMsg;
string subName;
//CFVector subAttr;
Predicate subAttr;
while( head < msg.size() )
{
subMsg = msg.assign( msg.begin() + head, msg.end() );
if( head == 0 )
{
head = GetSubMsg( subMsg );
subName = subMsg;
}
else
{
head = GetSubMsg( subMsg );
subAttr.attr.push_back( subMsg );
}
}
mCFVector.AddChild( subName,subAttr );
return true;
}
bool ReadConf::ReadConfFile()
{
char buf[200];
while(fgets(buf,200,mCF) != NULL)
{
if(buf[0] == '#' || buf[0] == '\n' || buf[0] == '\r' )
{
continue ;
}
if( !GetOneLineConf( buf ) )
{
cout<< "[Warning] " << "Unknown Conf Format ! " << endl;
}
}
fclose( mCF );
}
void ReadConf::Tranversal( const string &name, Predicate &tarP )
{
multimap<string, Predicate>:: iterator cp = mCFVector.child.begin();
while( cp != mCFVector.child.end() )
{
if( (cp->first) == name )
{
tarP.name = name;
tarP.AddChild( name, (cp->second) );
}
cp ++;
}
}
/*************************** TESTING PURPOSES ********************************/
//int main( void )
//{
// ReadConf rC( string( "agentConf.conf" ) );
//
// rC.ShowConfFile();
//
// /*************************** TESTING PURPOSES ********************************/
// //string test1;
// float test2;
// int test3;
// bool test4;
// float test5[4];
//
// Predicate test1;
//
// rC.Tranversal( "test5",test1);
// //rC.mCFVector.ShowValue();
// test1.ShowValue();
// //rC.mCFVector.GetValue( "test1",test1);
// //rC.mCFVector.GetValue( "test2",test2);
// //rC.mCFVector.GetValue( "test3",test3);
// //rC.mCFVector.GetValue( "test4",test4);
// //rC.mCFVector.GetValue( "test5",test5,4);
//
// //cout<< "test1 "<< test1 << endl;
// //cout<< "test2 "<< test2 << endl;
// //cout<< "test3 "<< test3 << endl;
// //cout<< "test4 "<< test4 << endl;
// //cout<< "test5 ";
// //for( int i = 0; i < 4; i++ )
// //{
// // cout<< test5[i] <<" ";
// //}
// //cout<< endl;
//
//}