commore  1.0.6-SNAPSHOT
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
/examples/coding/List.cpp

Commore List containers are implemented as doubly-linked lists on std::list model Many methodes are very closed Commore List are builtin types, even if List is defined as a template only following data type can be instantiaded in the commore::List template Bool, Int, Long, Float, Double, AString, String, Blob, Tuple, ArrayBool, ArrayInt, ArrayFloat, ArrayDouble Please use the types defined in Type.h Do not use this template for non commore object. STL containers will be more suitable.

#include "commore/List.h"
#include "commore/Error.h"
#include <stdio.h>
CMR_MODULE_DECLARE("EXAMPLE_LIST");
using namespace std;
using namespace commore;
//
// Trace list content
//
void trace_list(const ListAString& l, const char* label)
{
CMR_INFO("List: %0") << label;
for (ListAString::const_iterator i = l.begin(); i.more(); i++)
{
CMR_INFO(" %0") << *i;
}
}
// This is an example of how to use the ListAString class.
// this simple program show basic usage of this List class and of related iterators (const or not)
// other builtin Commore List have the same behaviour
int main(int argc, const char* argv[])
{
int r= 0;
ListAString fruits;
CMR_INFO("Start example List");
fruits.add("apple");
fruits.add("orange");
fruits.add("banana");
fruits.add("kiwi");
fruits.add("cherry");
trace_list(fruits, "original");
//
// Remove some fruits
//
{
ListAString::iterator ifruit = fruits.begin();
while (ifruit.more())
{
if (*ifruit == "orange" || *ifruit == "apple")
{
ifruit.erase();
} else {
ifruit++;
}
}
}
trace_list(fruits, "no apple, no orange");
return r;
}