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