MessageAttributes.C 13.2 KB
Newer Older
hrchilds's avatar
hrchilds committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <MessageAttributes.h>
#include <DataNode.h>

//
// Enum conversion methods for MessageAttributes::Severity
//

static const char *Severity_strings[] = {
"Error", "Warning", "Message"
};

std::string
MessageAttributes::Severity_ToString(MessageAttributes::Severity t)
{
hrchilds's avatar
hrchilds committed
15
16
17
    int index = int(t);
    if(index < 0 || index >= 3) index = 0;
    return Severity_strings[index];
hrchilds's avatar
hrchilds committed
18
19
20
21
22
}

std::string
MessageAttributes::Severity_ToString(int t)
{
hrchilds's avatar
hrchilds committed
23
24
    int index = (t < 0 || t >= 3) ? 0 : t;
    return Severity_strings[index];
hrchilds's avatar
hrchilds committed
25
26
27
28
29
}

bool
MessageAttributes::Severity_FromString(const std::string &s, MessageAttributes::Severity &val)
{
hrchilds's avatar
hrchilds committed
30
    val = MessageAttributes::Error;
hrchilds's avatar
hrchilds committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    for(int i = 0; i < 3; ++i)
    {
        if(s == Severity_strings[i])
        {
            val = (Severity)i;
            return true;
        }
    }
    return false;
}

// ****************************************************************************
// Method: MessageAttributes::MessageAttributes
//
// Purpose: 
//   Constructor for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
51
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Modifications:
//   
// ****************************************************************************

MessageAttributes::MessageAttributes() : AttributeSubject("si")
{
    text = "";
    severity = Message;
}

// ****************************************************************************
// Method: MessageAttributes::MessageAttributes
//
// Purpose: 
//   Copy constructor for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
72
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// Modifications:
//   
// ****************************************************************************

MessageAttributes::MessageAttributes(const MessageAttributes &obj) : AttributeSubject("si")
{
    text = obj.text;
    severity = obj.severity;

    SelectAll();
}

// ****************************************************************************
// Method: MessageAttributes::~MessageAttributes
//
// Purpose: 
//   Destructor for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
95
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Modifications:
//   
// ****************************************************************************

MessageAttributes::~MessageAttributes()
{
    // nothing here
}

// ****************************************************************************
// Method: MessageAttributes::operator = 
//
// Purpose: 
//   Assignment operator for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
115
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// Modifications:
//   
// ****************************************************************************

void
MessageAttributes::operator = (const MessageAttributes &obj)
{
    text = obj.text;
    severity = obj.severity;

    SelectAll();
}

// ****************************************************************************
// Method: MessageAttributes::operator == 
//
// Purpose: 
//   Comparison operator == for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
139
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//
// Modifications:
//   
// ****************************************************************************

bool
MessageAttributes::operator == (const MessageAttributes &obj) const
{
    // Create the return value
    return ((text == obj.text) &&
            (severity == obj.severity));
}

// ****************************************************************************
// Method: MessageAttributes::operator != 
//
// Purpose: 
//   Comparison operator != for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
162
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
// Modifications:
//   
// ****************************************************************************

bool
MessageAttributes::operator != (const MessageAttributes &obj) const
{
    return !(this->operator == (obj));
}

// ****************************************************************************
// Method: MessageAttributes::TypeName
//
// Purpose: 
//   Type name method for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
183
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//
// Modifications:
//   
// ****************************************************************************

const std::string
MessageAttributes::TypeName() const
{
    return "MessageAttributes";
}

// ****************************************************************************
// Method: MessageAttributes::CopyAttributes
//
// Purpose: 
//   CopyAttributes method for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
204
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//
// Modifications:
//   
// ****************************************************************************

bool
MessageAttributes::CopyAttributes(const AttributeGroup *atts)
{
    if(TypeName() != atts->TypeName())
        return false;

    // Call assignment operator.
    const MessageAttributes *tmp = (const MessageAttributes *)atts;
    *this = *tmp;

    return true;
}

// ****************************************************************************
// Method: MessageAttributes::CreateCompatible
//
// Purpose: 
//   CreateCompatible method for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
232
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
//
// Modifications:
//   
// ****************************************************************************

AttributeSubject *
MessageAttributes::CreateCompatible(const std::string &tname) const
{
    AttributeSubject *retval = 0;
    if(TypeName() == tname)
        retval = new MessageAttributes(*this);
    // Other cases could go here too. 

    return retval;
}

// ****************************************************************************
// Method: MessageAttributes::SelectAll
//
// Purpose: 
//   Selects all attributes.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
258
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
//
// Modifications:
//   
// ****************************************************************************

void
MessageAttributes::SelectAll()
{
    Select(0, (void *)&text);
    Select(1, (void *)&severity);
}

///////////////////////////////////////////////////////////////////////////////
// Persistence methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: MessageAttributes::CreateNode
//
// Purpose: 
//   This method creates a DataNode representation of the object so it can be saved to a config file.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
284
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
//
// Modifications:
//   
// ****************************************************************************

bool
MessageAttributes::CreateNode(DataNode *parentNode, bool forceAdd)
{
    if(parentNode == 0)
        return false;

    MessageAttributes defaultObject;
    bool addToParent = false;
    // Create a node for MessageAttributes.
    DataNode *node = new DataNode("MessageAttributes");

    if(!FieldsEqual(0, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("text", text));
    }

    if(!FieldsEqual(1, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("severity", Severity_ToString(severity)));
    }


    // Add the node to the parent node.
    if(addToParent || forceAdd)
        parentNode->AddNode(node);
    else
        delete node;

    return (addToParent || forceAdd);
}

// ****************************************************************************
// Method: MessageAttributes::SetFromNode
//
// Purpose: 
//   This method sets attributes in this object from values in a DataNode representation of the object.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
332
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
//
// Modifications:
//   
// ****************************************************************************

void
MessageAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("MessageAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("text")) != 0)
        SetText(node->AsString());
    if((node = searchNode->GetNode("severity")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
hrchilds's avatar
hrchilds committed
355
356
357
358
359
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 3)
                SetSeverity(Severity(ival));
        }
hrchilds's avatar
hrchilds committed
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
        else if(node->GetNodeType() == STRING_NODE)
        {
            Severity value;
            if(Severity_FromString(node->AsString(), value))
                SetSeverity(value);
        }
    }
}

///////////////////////////////////////////////////////////////////////////////
// Set property methods
///////////////////////////////////////////////////////////////////////////////

void
MessageAttributes::SetText(const std::string &text_)
{
    text = text_;
    Select(0, (void *)&text);
}

void
MessageAttributes::SetSeverity(MessageAttributes::Severity severity_)
{
    severity = severity_;
    Select(1, (void *)&severity);
}

///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////

const std::string &
MessageAttributes::GetText() const
{
    return text;
}

std::string &
MessageAttributes::GetText()
{
    return text;
}

MessageAttributes::Severity
MessageAttributes::GetSeverity() const
{
    return Severity(severity);
}

///////////////////////////////////////////////////////////////////////////////
// Select property methods
///////////////////////////////////////////////////////////////////////////////

void
MessageAttributes::SelectText()
{
    Select(0, (void *)&text);
}

///////////////////////////////////////////////////////////////////////////////
// Keyframing methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: MessageAttributes::GetFieldName
//
// Purpose: 
//   This method returns the name of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
432
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
//
// Modifications:
//   
// ****************************************************************************

std::string
MessageAttributes::GetFieldName(int index) const
{
    switch (index)
    {
        case 0:  return "text";
        case 1:  return "severity";
        default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: MessageAttributes::GetFieldType
//
// Purpose: 
//   This method returns the type of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
458
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
//
// Modifications:
//   
// ****************************************************************************

AttributeGroup::FieldType
MessageAttributes::GetFieldType(int index) const
{
    switch (index)
    {
        case 0:  return FieldType_string;
        case 1:  return FieldType_enum;
        default:  return FieldType_unknown;
    }
}

// ****************************************************************************
// Method: MessageAttributes::GetFieldTypeName
//
// Purpose: 
//   This method returns the name of a field type given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
484
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
//
// Modifications:
//   
// ****************************************************************************

std::string
MessageAttributes::GetFieldTypeName(int index) const
{
    switch (index)
    {
        case 0:  return "string";
        case 1:  return "enum";
        default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: MessageAttributes::FieldsEqual
//
// Purpose: 
//   This method compares two fields and return true if they are equal.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
510
// Creation:   Tue Jul 15 13:47:37 PST 2003
hrchilds's avatar
hrchilds committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
//
// Modifications:
//   
// ****************************************************************************

bool
MessageAttributes::FieldsEqual(int index_, const AttributeGroup *rhs) const
{
    const MessageAttributes &obj = *((const MessageAttributes*)rhs);
    bool retval = false;
    switch (index_)
    {
    case 0:
        {  // new scope
        retval = (text == obj.text);
        }
        break;
    case 1:
        {  // new scope
        retval = (severity == obj.severity);
        }
        break;
    default: retval = false;
    }

    return retval;
}

///////////////////////////////////////////////////////////////////////////////
// User-defined methods.
///////////////////////////////////////////////////////////////////////////////