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

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

static const char *Severity_strings[] = {
hrchilds's avatar
hrchilds committed
9
10
"Error", "Warning", "Message", 
"ErrorClear"};
hrchilds's avatar
hrchilds committed
11
12
13
14

std::string
MessageAttributes::Severity_ToString(MessageAttributes::Severity t)
{
hrchilds's avatar
hrchilds committed
15
    int index = int(t);
hrchilds's avatar
hrchilds committed
16
    if(index < 0 || index >= 4) index = 0;
hrchilds's avatar
hrchilds committed
17
    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
    int index = (t < 0 || t >= 4) ? 0 : t;
hrchilds's avatar
hrchilds committed
24
    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
    for(int i = 0; i < 4; ++i)
hrchilds's avatar
hrchilds committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    {
        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:   Thu May 11 14:56:29 PST 2006
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:   Thu May 11 14:56:29 PST 2006
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:   Thu May 11 14:56:29 PST 2006
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:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
116
117
118
119
120
//
// Modifications:
//   
// ****************************************************************************

hrchilds's avatar
hrchilds committed
121
MessageAttributes& 
hrchilds's avatar
hrchilds committed
122
123
MessageAttributes::operator = (const MessageAttributes &obj)
{
hrchilds's avatar
hrchilds committed
124
    if (this == &obj) return *this;
hrchilds's avatar
hrchilds committed
125
126
127
128
    text = obj.text;
    severity = obj.severity;

    SelectAll();
hrchilds's avatar
hrchilds committed
129
    return *this;
hrchilds's avatar
hrchilds committed
130
131
132
133
134
135
136
137
138
139
140
}

// ****************************************************************************
// Method: MessageAttributes::operator == 
//
// Purpose: 
//   Comparison operator == for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
141
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//
// 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
164
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
// 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
185
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//
// 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
206
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
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
232
233
//
// 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
234
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//
// 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;
}

hrchilds's avatar
hrchilds committed
251
252
253
254
255
256
257
258
259
// ****************************************************************************
// Method: MessageAttributes::NewInstance
//
// Purpose: 
//   NewInstance method for the MessageAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
260
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//
// Modifications:
//   
// ****************************************************************************

AttributeSubject *
MessageAttributes::NewInstance(bool copy) const
{
    AttributeSubject *retval = 0;
    if(copy)
        retval = new MessageAttributes(*this);
    else
        retval = new MessageAttributes;

    return retval;
}

hrchilds's avatar
hrchilds committed
278
279
280
281
282
283
284
285
286
// ****************************************************************************
// Method: MessageAttributes::SelectAll
//
// Purpose: 
//   Selects all attributes.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
hrchilds's avatar
hrchilds committed
287
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
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
//
// 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
313
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
314
315
316
317
318
319
//
// Modifications:
//   
// ****************************************************************************

bool
hrchilds's avatar
hrchilds committed
320
MessageAttributes::CreateNode(DataNode *parentNode, bool completeSave, bool forceAdd)
hrchilds's avatar
hrchilds committed
321
322
323
324
325
326
327
328
329
{
    if(parentNode == 0)
        return false;

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

hrchilds's avatar
hrchilds committed
330
    if(completeSave || !FieldsEqual(0, &defaultObject))
hrchilds's avatar
hrchilds committed
331
332
333
334
335
    {
        addToParent = true;
        node->AddNode(new DataNode("text", text));
    }

hrchilds's avatar
hrchilds committed
336
    if(completeSave || !FieldsEqual(1, &defaultObject))
hrchilds's avatar
hrchilds committed
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
    {
        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
361
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
362
363
364
365
366
367
368
369
//
// Modifications:
//   
// ****************************************************************************

void
MessageAttributes::SetFromNode(DataNode *parentNode)
{
hrchilds's avatar
hrchilds committed
370
    int i;
hrchilds's avatar
hrchilds committed
371
372
373
374
375
376
377
378
379
380
381
382
383
384
    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
385
386
        {
            int ival = node->AsInt();
hrchilds's avatar
hrchilds committed
387
            if(ival >= 0 && ival < 4)
hrchilds's avatar
hrchilds committed
388
389
                SetSeverity(Severity(ival));
        }
hrchilds's avatar
hrchilds committed
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
432
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
458
459
460
461
        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
462
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
//
// 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
488
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
//
// 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
514
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
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
//
// 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
540
// Creation:   Thu May 11 14:56:29 PST 2006
hrchilds's avatar
hrchilds committed
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
//
// 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.
///////////////////////////////////////////////////////////////////////////////