#region MIT License /*Copyright (c) 2012-2013 Robert Rouhani SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #endregion using System; using System.Runtime.InteropServices; using SharpFont.Internal; namespace SharpFont { /// /// An iterator function which is called during a list parse by . /// /// The current iteration list node. /// /// A typeless pointer passed to . Can be used to point to the iteration's state. /// /// Error code. [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate Error ListIterator(NativeReference node, IntPtr user); /// /// An iterator function which is called during a list finalization by /// to destroy all elements in a given list. /// /// The current system object. /// The current object to destroy. /// /// A typeless pointer passed to . It can be used to point to the iteration's state. /// [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ListDestructor(NativeReference memory, IntPtr data, IntPtr user); /// /// A structure used to hold a simple doubly-linked list. These are used in many parts of FreeType. /// public sealed class FTList { #region Fields private IntPtr reference; private ListRec rec; #endregion #region Constructors internal FTList(IntPtr reference) { Reference = reference; } #endregion #region Properties /// /// Gets the head (first element) of doubly-linked list. /// public ListNode Head { get { return new ListNode(rec.head); } } /// /// Gets the tail (last element) of doubly-linked list. /// public ListNode Tail { get { return new ListNode(rec.tail); } } internal IntPtr Reference { get { return reference; } set { reference = value; rec = PInvokeHelper.PtrToStructure(reference); } } #endregion #region Methods /// /// Find the list node for a given listed object. /// /// The address of the listed object. /// List node. NULL if it wasn't found. public ListNode Find(IntPtr data) { return new ListNode(FT.FT_List_Find(Reference, data)); } /// /// Append an element to the end of a list. /// /// The node to append. public void Add(ListNode node) { FT.FT_List_Add(Reference, node.Reference); } /// /// Insert an element at the head of a list. /// /// The node to insert. public void Insert(ListNode node) { FT.FT_List_Insert(Reference, node.Reference); } /// /// Remove a node from a list. This function doesn't check whether the node is in the list! /// /// The node to remove. public void Remove(ListNode node) { FT.FT_List_Remove(Reference, node.Reference); } /// /// Move a node to the head/top of a list. Used to maintain LRU lists. /// /// The node to move. public void Up(ListNode node) { FT.FT_List_Up(Reference, node.Reference); } /// /// Parse a list and calls a given iterator function on each element. Note that parsing is stopped as soon as /// one of the iterator calls returns a non-zero value. /// /// An iterator function, called on each node of the list. /// A user-supplied field which is passed as the second argument to the iterator. public void Iterate(ListIterator iterator, IntPtr user) { Error err = FT.FT_List_Iterate(Reference, iterator, user); if (err != Error.Ok) throw new FreeTypeException(err); } /// /// Destroy all elements in the list as well as the list itself. /// /// /// This function expects that all nodes added by or have been /// dynamically allocated. /// /// A list destructor that will be applied to each element of the list. /// The current memory object which handles deallocation. /// A user-supplied field which is passed as the last argument to the destructor. public void Finalize(ListDestructor destroy, Memory memory, IntPtr user) { FT.FT_List_Finalize(Reference, destroy, memory.Reference, user); } #endregion } }