BaseList Manual

About

maxon::BaseList is a class template for double linked lists. Elements of such a list should typically be access with iterators and not with indices.

Creation

A new list object can simply be created using the class template:

// This example creates and fills a new BaseList.

The complete content of the BaseList can be deleted with:

Data

A maxon::BaseList stores maxon::BaseListNode elements. Such nodes contain the actual stored value and also references to the previous and next node.

New elements are added to the list with:

// This example creates a BaseList and adds elements to it.
// append elements
// insert object at the beginning
auto it = list.Begin();
list.Insert(it, 3) iferr_return;

If a given maxon::BaseList contains any elements can be checked with:

// This example checks if the given BaseList is empty.
// If not it is flushed.
if (!list.IsEmpty())
list.Flush();
if (!list.IsPopulated())
DiagnosticOutput("List is empty.");

A specific element stored in the maxon::BaseList can be accessed by its index:

// This example loops through all elements of the BaseList based on the element index.
const maxon::Int cnt = list.GetCount();
for (maxon::Int i = 0; i < cnt; ++i)
{
const maxon::Int value = list[i];
DiagnosticOutput("Value: @", value);
}

Single elements of the maxon::BaseList can be removed with:

// This example deletes the first two elements of the given BaseList.
// deletes the first two elements
const auto begin = list.Begin();
list.Erase(begin, 2);

The overall maxon::BaseList can be resized with:

Iterate

Using iterators it is easily possible to iterate over all elements stored in the maxon::BaseList:

// This example switches the first and last element of the BaseList
// and loops through the list using the iterator.
// swap first and last element
const auto begin = list.Begin();
auto end = list.End();
end--;
list.Swap(begin, end);
// list all values
for (const maxon::Int it : list)
DiagnosticOutput("Value: @", it);

Utility

Utility functions are:

Further Reading

maxon::BaseList::Append
ResultRef< T > Append()
Definition: baselist.h:578
maxon::BaseList::GetCount
Int GetCount() const
Definition: baselist.h:546
maxon::BaseList::Insert
ResultRef< T > Insert(Int position)
Definition: baselist.h:675
maxon::end
MAXON_ATTRIBUTE_FORCE_INLINE auto end(COLLECTION &&c) -> decltype(c.End())
Definition: foreach.h:360
maxon::BaseList::IsPopulated
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsPopulated() const
Definition: baselist.h:536
maxon::begin
MAXON_ATTRIBUTE_FORCE_INLINE auto begin(COLLECTION &&c) -> decltype(c.Begin())
Definition: foreach.h:355
iferr_return
#define iferr_return
Definition: resultbase.h:1434
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:168
maxon::BaseList::Begin
ConstIterator Begin() const
Definition: baselist.h:1231
maxon::BaseList::Erase
ResultPtr< T > Erase(Int position, Int eraseCnt=1)
Definition: baselist.h:872
maxon::BaseList::IsEmpty
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEmpty() const
Definition: baselist.h:527
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:184
maxon::BaseList::Swap
void Swap(Iterator a, Iterator b)
Definition: baselist.h:1184
maxon::BaseList::End
ConstIterator End() const
Definition: baselist.h:1253
maxon::BaseList::Flush
void Flush()
Deletes all elements (same as Reset() for the BaseList).
Definition: baselist.h:518
maxon::BaseList
Definition: baselist.h:457