xref: /haiku/src/tests/add-ons/print/ppd/model/StatementList.cpp (revision 4420c1ceffd7f2246e4303d59cf02ed122980e9d)
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 "StatementList.h"
10 #include "Statement.h"
11 
12 #include <stdio.h>
13 
StatementList(bool ownsStatements)14 StatementList::StatementList(bool ownsStatements)
15 	: fOwnsStatements(ownsStatements)
16 {
17 }
18 
~StatementList()19 StatementList::~StatementList()
20 {
21 	if (fOwnsStatements) {
22 		for (int32 i = 0; i < Size(); i ++) {
23 			Statement* statement = StatementAt(i);
24 			delete statement;
25 		}
26 	}
27 	fList.MakeEmpty();
28 }
29 
Add(Statement * statement)30 void StatementList::Add(Statement* statement)
31 {
32 	fList.AddItem(statement);
33 }
34 
Remove(Statement * statement)35 void StatementList::Remove(Statement* statement)
36 {
37 	fList.RemoveItem(statement);
38 }
39 
Size()40 int32 StatementList::Size()
41 {
42 	return fList.CountItems();
43 }
44 
StatementAt(int32 index)45 Statement* StatementList::StatementAt(int32 index)
46 {
47 	return (Statement*)fList.ItemAt(index);
48 }
49 
GetStatement(const char * keyword)50 Statement* StatementList::GetStatement(const char* keyword)
51 {
52 	for (int32 i = 0; i < fList.CountItems(); i ++) {
53 		if (strcmp(keyword, StatementAt(i)->GetKeywordString()) == 0) {
54 			return StatementAt(i);
55 		}
56 	}
57 	return NULL;
58 }
59 
GetValue(const char * keyword)60 const char* StatementList::GetValue(const char* keyword)
61 {
62 	Statement* statement = GetStatement(keyword);
63 	if (statement != NULL) {
64 		return statement->GetValueString();
65 	}
66 	return NULL;
67 }
68 
Print()69 void StatementList::Print()
70 {
71 	for (int32 i = 0; i < Size(); i ++) {
72 		StatementAt(i)->Print();
73 	}
74 }
75