list.h revision 36d9047104b5881ca587a71ade77b1f21d083bc4
/*
* Authors:
* MenTaLguY <mental@rydia.net>
*
* Copyright (C) 2004 MenTaLguY
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifndef SEEN_INKSCAPE_UTIL_LIST_H
#define SEEN_INKSCAPE_UTIL_LIST_H
#include <cstddef>
#include <iterator>
#include "gc-managed.h"
#include "util/reference.h"
/// Generic ListCell for Inkscape::Util::List.
ListCell() {}
T value;
};
MutableList<T> const &rest);
/// Helper template.
typedef T const value_type;
}
}
return *this;
}
return old;
}
};
/**
* Generic linked list.
*
* These lists are designed to store simple values like pointers,
* references, and scalar values. While they can be used to directly
* store more complex objects, destructors for those objects will not
* be called unless those objects derive from Inkscape::GC::Finalized.
*
* In general it's better to use lists to store pointers or references
* to objects requiring finalization and manage object lifetimes separately.
*
* @see Inkscape::GC::Finalized
*
* cons() is synonymous with List<T>(first, rest), except that the
* compiler will usually be able to infer T from the type of \a rest.
*
* If you need to create an empty list (which can, for example, be used
* as an 'end' value with STL algorithms), call the List<> constructor
* with no arguments, like so:
*
* <code> List<int>() </code>
*/
typedef T value_type;
return *this;
}
return old;
}
};
/// Helper template.
typedef T &value_type;
}
}
return *this;
}
return old;
}
};
/**
* Generic MutableList.
*
* Like a linked list, but one whose tail can be exchanged for
* another later by using set_rest() or assignment through rest()
* as an lvalue. It's otherwise identical to the "non-mutable" form.
*
* As with List, you can create an empty list like so:
*
* <code> MutableList<int>() </code>
*/
MutableList() {}
MutableList &operator++() {
return *this;
}
MutableList operator++(int) {
return old;
}
MutableList const &);
};
/**
* Creates a (non-empty) linked list.
*
* Creates a new linked list with a copy of the given value (\a first)
* in its first element; the remainder of the list will be the list
* provided as \a rest.
*
* The remainder of the list -- the "tail" -- is incorporated by
* reference rather than being copied.
*
* The returned value can also be treated as an STL forward iterator.
*
* @param first the value for the first element of the list
* @param rest the rest of the list; may be an empty list
*
* @return a new list
*
* @see List<>
* @see is_empty<>
*
*/
{
}
/**
* Creates a (non-empty) linked list whose tail can be exchanged
* for another.
*
* Creates a new linked list, but one whose tail can be exchanged for
* another later by using set_rest() or assignment through rest()
* as an lvalue. It's otherwise identical to the "non-mutable" form.
*
* This form of cons() is synonymous with MutableList<T>(first, rest),
* except that the compiler can usually infer T from the type of \a rest.
*
* As with List<>, you can create an empty list like so:
*
* MutableList<int>()
*
* @see MutableList<>
* @see is_empty<>
*
* @param first the value for the first element of the list
* @param rest the rest of the list; may be an empty list
*
* @return a new list
*/
MutableList<T> const &rest)
{
}
/**
* Returns true if the given list is empty.
*
* Returns true if the given list is empty. This is equivalent
* to !list.
*
* @param list the list
*
* @return true if the list is empty, false otherwise.
*/
/**
* Returns the first value in a linked list.
*
* Returns a reference to the first value in the list. This
* corresponds to the value of the first argument passed to cons().
*
* If the list holds mutable values (or references to them), first()
* can be used as an lvalue.
*
* For example:
*
* first(list) = value;
*
* The results of calling this on an empty list are undefined.
*
* @see cons<>
* @see is_empty<>
*
* @param list the list; cannot be empty
*
* @return a reference to the first value in the list
*/
}
/**
* Returns the remainder of a linked list after the first element.
*
* Returns the remainder of the list after the first element (its "tail").
*
* This will be the same as the second argument passed to cons().
*
* The results of calling this on an empty list are undefined.
*
* @see cons<>
* @see is_empty<>
*
* @param list the list; cannot be empty
*
* @return the remainder of the list
*/
}
/**
* Returns a reference to the remainder of a linked list after
* the first element.
*
* Returns a reference to the remainder of the list after the first
* element (its "tail"). For MutableList<>, rest() can be used as
* an lvalue, to set a new tail.
*
* For example:
*
* rest(list) = other;
*
* Results of calling this on an empty list are undefined.
*
* @see cons<>
* @see is_empty<>
*
* @param list the list; cannot be empty
*
* @return a reference to the remainder of the list
*/
}
/**
* Sets a new tail for an existing linked list.
*
* Sets the tail of the given MutableList<>, corresponding to the
* second argument of cons().
*
* Results of calling this on an empty list are undefined.
*
* @see rest<>
* @see cons<>
* @see is_empty<>
*
* @param list the list; cannot be empty
* @param rest the new tail; corresponds to the second argument of cons()
*
* @return the new tail
*/
MutableList<T> const &rest)
{
}
}
}
#endif
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :