headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / add-ons / print / ppd / model / StatementList.cpp
blobf9132f1ba87404a65be69b71d75f0611b0ecc3bc
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 "StatementList.h"
10 #include "Statement.h"
12 #include <stdio.h>
14 StatementList::StatementList(bool ownsStatements)
15 : fOwnsStatements(ownsStatements)
19 StatementList::~StatementList()
21 if (fOwnsStatements) {
22 for (int32 i = 0; i < Size(); i ++) {
23 Statement* statement = StatementAt(i);
24 delete statement;
27 fList.MakeEmpty();
30 void StatementList::Add(Statement* statement)
32 fList.AddItem(statement);
35 void StatementList::Remove(Statement* statement)
37 fList.RemoveItem(statement);
40 int32 StatementList::Size()
42 return fList.CountItems();
45 Statement* StatementList::StatementAt(int32 index)
47 return (Statement*)fList.ItemAt(index);
50 Statement* StatementList::GetStatement(const char* keyword)
52 for (int32 i = 0; i < fList.CountItems(); i ++) {
53 if (strcmp(keyword, StatementAt(i)->GetKeywordString()) == 0) {
54 return StatementAt(i);
57 return NULL;
60 const char* StatementList::GetValue(const char* keyword)
62 Statement* statement = GetStatement(keyword);
63 if (statement != NULL) {
64 return statement->GetValueString();
66 return NULL;
69 void StatementList::Print()
71 for (int32 i = 0; i < Size(); i ++) {
72 StatementAt(i)->Print();