| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 4 |
// vi: set et ts=4 sw=2 sts=2: |
| 5 |
#include <config.h> |
| 6 |
|
| 7 |
#include <cstdio> |
| 8 |
#include <cstdlib> |
| 9 |
#include <cassert> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
namespace DDD { |
| 13 |
struct DDDContext; |
| 14 |
} /* namespace DDD */ |
| 15 |
|
| 16 |
/* some macros for customizing oopp */ |
| 17 |
#define _NEWPARAMS |
| 18 |
#define _NEWPARAMS_OR_VOID void |
| 19 |
|
| 20 |
#define __INDENT(n) { int i; for(i=0; i<n; i++) fputs(" ",fp);} |
| 21 |
#define _PRINTPARAMS , int indent, FILE *fp |
| 22 |
#define _PRINTPARAMS_DEFAULT ,0,stdout |
| 23 |
#define _INDENT __INDENT(indent) |
| 24 |
#define _INDENT1 __INDENT(indent+1) |
| 25 |
#define _INDENT2 __INDENT(indent+2) |
| 26 |
#define _PRINTNEXT , indent+1, fp |
| 27 |
#define _PRINTSAME , indent, fp |
| 28 |
|
| 29 |
#define _CHECKALLOC(ptr) assert(ptr!=NULL) |
| 30 |
#define OO_Allocate malloc |
| 31 |
#define OO_Free free |
| 32 |
|
| 33 |
#include "../oopp.h" /* for object-orientated style via preprocessor */ |
| 34 |
|
| 35 |
/****************************************************************************/ |
| 36 |
/* Tree element: */ |
| 37 |
/****************************************************************************/ |
| 38 |
|
| 39 |
#define ClassName TestTreeElement |
| 40 |
Class_Data_Begin |
| 41 |
int value; |
| 42 |
Class_Data_End |
| 43 |
void Method(Print) (DefThis _PRINTPARAMS); |
| 44 |
int Method(Compare) (ClassPtr, ClassPtr, const DDD::DDDContext*); |
| 45 |
|
| 46 |
#undef ClassName |
| 47 |
|
| 48 |
|
| 49 |
/* define container class */ |
| 50 |
#ifndef SetOf /* necessary for inline documentation only */ |
| 51 |
#define SetOf TestTreeElement |
| 52 |
#define Set_SegmSize 256 |
| 53 |
#define Set_BTreeOrder 32 |
| 54 |
#endif |
| 55 |
|
| 56 |
// Create method definitions, not just declarations |
| 57 |
#define ContainerImplementation |
| 58 |
|
| 59 |
#include "../ooppcc.h" |
| 60 |
|
| 61 |
void TestTreeElement_Print(TestTreeElement* element, int indent, FILE* fp) |
| 62 |
{ |
| 63 |
printf("TestTreeElement: %d\n", element->value); |
| 64 |
} |
| 65 |
|
| 66 |
int TestTreeElement_Compare(TestTreeElement* a, TestTreeElement* b, const DDD::DDDContext*) |
| 67 |
{ |
| 68 |
if (a->value < b->value) |
| 69 |
return -1; |
| 70 |
else if (a->value > b->value) |
| 71 |
return 1; |
| 72 |
|
| 73 |
return 0; |
| 74 |
} |
| 75 |
|
| 76 |
int main(int argc, char** argv) |
| 77 |
{ |
| 78 |
TestTreeElementBTree* foo = New_TestTreeElementBTree(); |
| 79 |
|
| 80 |
for (int i=0; i<40; i+=2) { |
| 81 |
|
| 82 |
TestTreeElement* newItem = new TestTreeElement; |
| 83 |
newItem->value = i; |
| 84 |
|
| 85 |
TestTreeElementBTree_Insert(foo, newItem); |
| 86 |
} |
| 87 |
|
| 88 |
for (int i=1; i<40; i+=2) { |
| 89 |
|
| 90 |
TestTreeElement* newItem = new TestTreeElement; |
| 91 |
newItem->value = i; |
| 92 |
|
| 93 |
TestTreeElementBTree_Insert(foo, newItem); |
| 94 |
} |
| 95 |
|
| 96 |
TestTreeElementBTree_Print(foo, 0, stdout); |
| 97 |
|
| 98 |
TestTreeElementBTree_Reset(foo); |
| 99 |
|
| 100 |
return 0; |
| 101 |
} |