Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/parameter.cc
[mareframe] / trunk / gadget / parameter.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/parameter.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "parameter.h"
2 :     #include "errorhandler.h"
3 :     #include "gadget.h"
4 :     #include "global.h"
5 :    
6 :     Parameter::Parameter(const Parameter& p) {
7 :     if (p.name == NULL) {
8 :     name = NULL;
9 :     } else {
10 :     name = new char[strlen(p.name) + 1];
11 :     strcpy(name, p.name);
12 :     }
13 :     }
14 :    
15 :     Parameter::Parameter(char* value) {
16 :     if (value == NULL) {
17 :     name = NULL;
18 :     } else {
19 :     if (this->isValidName(value)) {
20 :     name = new char[strlen(value) + 1];
21 :     strcpy(name, value);
22 :     } else {
23 :     handle.logMessage(LOGFAIL, "Error in parameter - invalid parameter name", value);
24 :     }
25 :     }
26 :     }
27 :    
28 :     Parameter::~Parameter() {
29 :     if (name != NULL) {
30 :     delete[] name;
31 :     name = NULL;
32 :     }
33 :     }
34 :    
35 :     int Parameter::operator == (const Parameter& p) const {
36 :     return (strcasecmp(name, p.name) == 0);
37 :     }
38 :    
39 :     Parameter& Parameter::operator = (const Parameter& p) {
40 :     if (this == &p)
41 :     return *this;
42 :    
43 :     if (name != NULL) {
44 :     delete[] name;
45 :     name = NULL;
46 :     }
47 :     if (p.name == NULL) {
48 :     name = NULL;
49 :     } else {
50 :     name = new char[strlen(p.name) + 1];
51 :     strcpy(name, p.name);
52 :     }
53 :     return *this;
54 :     }
55 :    
56 :     int Parameter::isValidName(char* value) {
57 :     int len = int(strlen(value));
58 :     if (len > MaxStrLength)
59 :     return 0;
60 :     int i;
61 :     for (i = 0; i < len; i++)
62 :     if (!this->isValidChar(value[i]))
63 :     return 0;
64 :     return 1;
65 :     }
66 :    
67 :     int Parameter::isValidChar(int c) {
68 :     //standard latin numbers and letters are ok
69 :     if (isalnum(c))
70 :     return 1;
71 :    
72 :     switch (c) {
73 :     case '_':
74 :     case '.':
75 :     //other valid characters in addition to numbers and letters
76 :     return 1;
77 :     break;
78 :     default:
79 :     //all other character are invalid in parameter names
80 :     //JMB this means that Icelandic, Norwegian, etc characters are invalid
81 :     return 0;
82 :     }
83 :     return 0;
84 :     }
85 :    
86 :     CommentStream& operator >> (CommentStream& infile, Parameter& p) {
87 :     char* tempString = new char[MaxStrLength];
88 :     strncpy(tempString, "", MaxStrLength);
89 :     int i = 0;
90 :     infile >> ws;
91 :     while (p.isValidChar(infile.peek()) && i < (MaxStrLength - 1)) {
92 :     if (infile.fail() && !infile.eof()) {
93 :     delete[] tempString;
94 :     return infile;
95 :     }
96 :     infile.get(tempString[i]);
97 :     i++;
98 :     }
99 :    
100 :     tempString[i] = '\0';
101 :     if (i == MaxStrLength)
102 :     handle.logMessage(LOGWARN, "Warning in parameter - parameter name has reached maximum length");
103 :    
104 :     if (p.name != NULL) {
105 :     delete[] p.name;
106 :     p.name = NULL;
107 :     }
108 :    
109 :     if (i != 0) {
110 :     p.name = new char[strlen(tempString) + 1];
111 :     strcpy(p.name, tempString);
112 :     }
113 :    
114 :     delete[] tempString;
115 :     return infile;
116 :     }
117 :    
118 :     istream& operator >> (istream& infile, Parameter& p) {
119 :     char* tempString = new char[MaxStrLength];
120 :     strncpy(tempString, "", MaxStrLength);
121 :     int i = 0;
122 :     infile >> ws;
123 :     while (p.isValidChar(infile.peek()) && i < (MaxStrLength - 1)) {
124 :     if (infile.fail() && !infile.eof()) {
125 :     delete[] tempString;
126 :     return infile;
127 :     }
128 :     infile.get(tempString[i]);
129 :     i++;
130 :     }
131 :    
132 :     tempString[i] = '\0';
133 :     if (i == MaxStrLength)
134 :     handle.logMessage(LOGWARN, "Warning in parameter - parameter name has reached maximum length");
135 :    
136 :     if (p.name != NULL) {
137 :     delete[] p.name;
138 :     p.name = NULL;
139 :     }
140 :    
141 :     if (i != 0) {
142 :     p.name = new char[strlen(tempString) + 1];
143 :     strcpy(p.name, tempString);
144 :     }
145 :    
146 :     delete[] tempString;
147 :     return infile;
148 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge