From 428046400de2068e98254e8395642cbc17e9b70b Mon Sep 17 00:00:00 2001 From: Armin Burgmeier Date: Mon, 4 Aug 2014 14:51:09 -0400 Subject: [PATCH] mape: Implement minimalist C4DefList --- CMakeLists.txt | 1 + src/mape/cpp-handles/c4def-handle.cpp | 77 +++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/mape/cpp-handles/c4def-handle.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ced943365..580c03b67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -486,6 +486,7 @@ set(MAPE_BASE_SOURCES ) set(MAPE_SOURCES + src/mape/cpp-handles/c4def-handle.cpp src/mape/cpp-handles/group-handle.h src/mape/cpp-handles/group-handle.cpp src/mape/cpp-handles/log-handle.h diff --git a/src/mape/cpp-handles/c4def-handle.cpp b/src/mape/cpp-handles/c4def-handle.cpp new file mode 100644 index 000000000..506bf2954 --- /dev/null +++ b/src/mape/cpp-handles/c4def-handle.cpp @@ -0,0 +1,77 @@ +/* + * mape - C4 Landscape.txt editor + * + * Copyright (c) 2005-2009, Armin Burgmeier + * + * Distributed under the terms of the ISC license; see accompanying file + * "COPYING" for details. + * + * "Clonk" is a registered trademark of Matthes Bender, used with permission. + * See accompanying file "TRADEMARK" for details. + * + * To redistribute this file separately, substitute the full license texts + * for the above references. + */ + +#include "C4Include.h" + +#include "C4Def.h" +#include "C4DefList.h" + +/* This is a simple implementation of C4DefList for what is required by + * mape. We cannot link the full implementation since it would introduce + * a dependency on C4Game, and therefore the rest of the engine. */ + +C4DefList::C4DefList() +{ + FirstDef = NULL; +} + +C4DefList::~C4DefList() +{ + Clear(); +} + +void C4DefList::Clear() +{ + while(FirstDef) + { + C4Def* out = FirstDef; + FirstDef = FirstDef->Next; + delete out; + } +} + +C4Def* C4DefList::ID2Def(C4ID id) +{ + C4Def* cdef; + for(cdef = FirstDef; cdef != NULL; cdef = cdef->Next) + if(cdef->id == id) + return cdef; + return NULL; +} + +C4Def* C4DefList::GetByName(const StdStrBuf& name) +{ + return ID2Def(C4ID(name)); +} + +C4Def* C4DefList::GetDef(int iIndex) +{ + int counter = 0; + for(C4Def* cdef = FirstDef; cdef != NULL; cdef = cdef->Next) + { + if(counter == iIndex) return cdef; + ++counter; + } + + return NULL; +} + +int C4DefList::GetDefCount() +{ + int counter = 0; + for(C4Def* cdef = FirstDef; cdef != NULL; cdef = cdef->Next) + ++counter; + return counter; +}