linklist.h Source File

Main Page Modules Class Hierarchy Compound List File List Compound Members File Members

# linklist.h

    00001 /*  Fast atomical linklist class
    00002  *  (c) Copyright 2001 Denis Roio aka jaromil <jaromil@dyne.org>
    00003  *
    00004  * This source code is free software; you can redistribute it and/or
    00005  * modify it under the terms of the GNU Public License as published
    00006  * by the Free Software Foundation; either version 2 of the License,
    00007  * or (at your option) any later version.
    00008  *
    00009  * This source code is distributed in the hope that it will be useful,
    00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00012  * Please refer to the GNU Public License for more details.
    00013  *
    00014  * You should have received a copy of the GNU Public License along with
    00015  * this source code; if not, write to:
    00016  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017  */
    00018
    00019 #ifndef __linklist_h__
    00020 #define __linklist_h__
    00021
    00022 #include <pthread.h>
    00023
    00024 class Entry;
    00025
    00026 class Linklist {
    00027  public:
    00028   Linklist();
    00029   virtual ~Linklist();
    00030
    00031   Entry *begin() { return(first); };
    00032   Entry *end() { return(last); };
    00033   int len() { return(length); };
    00034
    00035   void append(Entry *addr);
    00036   void add(Entry *addr) { append(addr); }; /* lazy backward compatibility */
    00037   void prepend(Entry *addr);
    00038   void insert(Entry *addr, int pos);
    00039
    00040   bool rem(int pos);
    00041   bool sel(int pos);
    00042   bool clear();
    00043   bool moveup(int pos);
    00044   bool movedown(int pos);
    00045   bool moveto(int num, int pos);
    00046   Entry *pick(int pos);
    00047   Entry *Linklist::selected();
    00048
    00049   Entry *operator[](int pos) { return pick(pos); };
    00050
    00051   /* don't touch these directly */
    00052   Entry *first;
    00053   Entry *last;
    00054   int length;
    00055
    00056   /* deprecated, here just for MuSE */
    00057   Entry *pick_id(int id);
    00058   int selected_pos();
    00059
    00060   /* thread stuff */
    00061   void lock();
    00062   void unlock();
    00063  private:
    00064   pthread_mutex_t _mutex;
    00065
    00066 };
    00067
    00068 class Entry {
    00069  public:
    00070   Entry();
    00071   ~Entry();
    00072
    00073   Entry *next;
    00074   Entry *prev;
    00075
    00076   Linklist *list;
    00077
    00078   bool up();
    00079   bool down();
    00080   bool move(int pos);
    00081   void rem();
    00082   void sel(bool on);
    00083
    00084   int id;  /* deprecated, here just for MuSE */
    00085   bool select;
    00086 };
    00087
    00088 #endif