headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / add-ons / print / ppd / model / Statement.cpp
blobeccad9280a6fb613c29309b3127b71e9673f22ef
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 "Statement.h"
11 #include <stdio.h>
14 Statement::Statement()
15 : fType(kUnknown)
16 , fKeyword(NULL)
17 , fOption(NULL)
18 , fValue(NULL)
19 , fChildren(NULL)
23 Statement::~Statement()
25 delete fKeyword;
26 delete fOption;
27 delete fValue;
28 delete fChildren;
31 void Statement::SetType(Type type)
33 fType = type;
36 Statement::Type Statement::GetType()
38 return fType;
41 void Statement::SetKeyword(BString* keyword)
43 fKeyword = keyword;
46 BString* Statement::GetKeyword()
48 return fKeyword;
51 void Statement::SetOption(Value* option)
53 fOption = option;
56 Value* Statement::GetOption()
58 return fOption;
62 void Statement::SetValue(Value* value)
64 fValue = value;
67 Value* Statement::GetValue()
69 return fValue;
72 StatementList* Statement::GetChildren()
74 return fChildren;
77 void Statement::AddChild(Statement* statement)
79 if (fChildren == NULL) {
80 fChildren = new StatementList(true);
82 fChildren->Add(statement);
85 const char* Statement::GetKeywordString()
87 if (fKeyword != NULL) {
88 return fKeyword->String();
90 return NULL;
93 const char* Statement::GetOptionString()
95 Value* option = GetOption();
96 if (option != NULL) {
97 return option->GetValueString();
99 return NULL;
102 const char* Statement::GetTranslationString()
104 Value* option = GetOption();
105 if (option != NULL) {
106 return option->GetTranslationString();
108 return NULL;
111 const char* Statement::GetValueString()
113 Value* value = GetValue();
114 if (value != NULL) {
115 return value->GetValueString();
117 return NULL;
120 const char* Statement::GetValueTranslationString()
122 Value* value = GetValue();
123 if (value != NULL) {
124 return value->GetTranslationString();
126 return NULL;
130 const char* Statement::ElementForType() {
131 switch (fType) {
132 case kDefault: return "Default";
133 break;
134 case kParam: return "Param";
135 break;
136 case kQuery: return "Query";
137 break;
138 case kValue: return "Value";
139 break;
140 case kUnknown: return "Unknown";
141 break;
143 return NULL;
146 void Statement::Print()
148 bool hasValue = fValue != NULL;
149 bool hasOption = fOption != NULL;
151 printf("<%s", ElementForType());
153 if (fKeyword != NULL) {
154 printf(" keyword=\"%s\"", fKeyword->String());
157 if (hasValue || hasOption) {
158 printf(">\n");
159 } else {
160 printf("/>\n");
164 if (hasOption) {
165 printf("\t<option>\n");
166 fOption->Print();
167 printf("\t</option>\n");
171 if (hasValue) {
172 printf("\t<value>\n");
173 fValue->Print();
174 printf("\t</value>\n");
177 if (GetChildren() != NULL) {
178 printf("\t<children>\n");
179 GetChildren()->Print();
180 printf("\t</children>\n");
183 if (hasValue || hasOption) {
184 printf("</%s>\n\n", ElementForType());