xref: /haiku/src/tests/add-ons/print/ppd/model/Value.cpp (revision 3369e03d5cde9709c8aa70c99bfe6ce24ba65bf9)
1 /*
2  * Copyright 2008, Haiku.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Michael Pfeiffer <laplace@users.sourceforge.net>
7  */
8 
9 #include "Value.h"
10 
11 #include <stdio.h>
12 
13 Value::Value(BString* value, Type type)
14 	: fType(type)
15 	, fValue(value)
16 	, fTranslation(NULL)
17 {
18 }
19 
20 Value::~Value()
21 {
22 	delete fValue;
23 	delete fTranslation;
24 }
25 
26 void Value::SetType(Type type)
27 {
28 	fType = type;
29 }
30 
31 Value::Type Value::GetType()
32 {
33 	return fType;
34 }
35 
36 void Value::SetValue(BString* value)
37 {
38 	fValue = value;
39 }
40 
41 BString* Value::GetValue()
42 {
43 	return fValue;
44 }
45 
46 void Value::SetTranslation(BString* translation)
47 {
48 	fTranslation = translation;
49 }
50 
51 BString* Value::GetTranslation()
52 {
53 	return fTranslation;
54 }
55 
56 const char* Value::GetValueString()
57 {
58 	if (fValue != NULL) {
59 		return fValue->String();
60 	}
61 	return NULL;
62 }
63 
64 const char* Value::GetTranslationString()
65 {
66 	if (fTranslation != NULL) {
67 		return fTranslation->String();
68 	}
69 	return NULL;
70 }
71 
72 const char* Value::ElementForType()
73 {
74 	switch (fType) {
75 		case kSymbolValue: return "Symbol";
76 			break;
77 		case kStringValue: return "String";
78 			break;
79 		case kInvocationValue: return "Invocation";
80 			break;
81 		case kQuotedValue: return "Quoted";
82 			break;
83 		case kUnknownValue: return "Unknown";
84 			break;
85 	}
86 	return "NULL";
87 }
88 
89 void Value::Print()
90 {
91 	printf("\t\t<%s>\n", ElementForType());
92 	if (fValue != NULL) {
93 		printf("\t\t\t<value>%s</value>\n", fValue->String());
94 	}
95 
96 	if (fTranslation != NULL) {
97 		printf("\t\t\t<translation>%s</translation>\n", fTranslation->String());
98 	}
99 	printf("\t\t</%s>\n", ElementForType());
100 }
101