vfs: check userland buffers before reading them.
[haiku.git] / src / tests / add-ons / print / ppd / model / Value.cpp
blob8dfd611ae4ffaee22e502f4d0142dcfad59486f0
1 /*
2 * Copyright 2008, Haiku.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Michael Pfeiffer <laplace@users.sourceforge.net>
7 */
9 #include "Value.h"
11 #include <stdio.h>
13 Value::Value(BString* value, Type type)
14 : fType(type)
15 , fValue(value)
16 , fTranslation(NULL)
20 Value::~Value()
22 delete fValue;
23 delete fTranslation;
26 void Value::SetType(Type type)
28 fType = type;
31 Value::Type Value::GetType()
33 return fType;
36 void Value::SetValue(BString* value)
38 fValue = value;
41 BString* Value::GetValue()
43 return fValue;
46 void Value::SetTranslation(BString* translation)
48 fTranslation = translation;
51 BString* Value::GetTranslation()
53 return fTranslation;
56 const char* Value::GetValueString()
58 if (fValue != NULL) {
59 return fValue->String();
61 return NULL;
64 const char* Value::GetTranslationString()
66 if (fTranslation != NULL) {
67 return fTranslation->String();
69 return NULL;
72 const char* Value::ElementForType()
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;
86 return "NULL";
89 void Value::Print()
91 printf("\t\t<%s>\n", ElementForType());
92 if (fValue != NULL) {
93 printf("\t\t\t<value>%s</value>\n", fValue->String());
96 if (fTranslation != NULL) {
97 printf("\t\t\t<translation>%s</translation>\n", fTranslation->String());
99 printf("\t\t</%s>\n", ElementForType());