Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, April 19, 2024

File: [Platon] / libco / libco / co_tab.h (download)

Revision 1.3, Sun Mar 30 10:27:17 2003 UTC (21 years ago) by yenar


Changes since 1.2: +7 -11 lines

adapt to object system changes (flavours, data pointer) [co_super.h, co_tab.c, co_tab.h, co_vector.c, co_vector.h]

/***{{{*******************************************************************
 * This file is part of libco - object library for C                     *
 * Copyright (c) 2002                                                    *
 *     Peter Rockai (yenar) <yenar@host.sk>                              *
 *                                                                       *
 * This library is free software; you can redistribute it and/or         *
 * modify it under the terms of the GNU Lesser General Public            *
 * License as published by the Free Software Foundation; either          *
 * version 2 of the License, or (at your option) any later version.      *
 *                                                                       *
 * This library is distributed in the hope that it will be useful,       *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 * Lesser General Public License for more details.                       *
 *                                                                       *
 * You should have received a copy of the GNU Lesser General Public      *
 * License along with this library; if not, write to the Free Software   *
 * Foundation, Inc., 59 Temple Place, Suite 330,                         *
 * Boston, MA 02111-1307  USA                                            *
 *******************************************************************}}}***/
/* {{{ file description */
/**
 * @file co_tab.h
 * @brief Generic table object definition and prototypes.
 **/
/* }}} */

#ifndef __CO_TAB_H__
#define __CO_TAB_H__

#include "co_object.h"
#include "co_vector.h"

/* {{{ */
CO_OBJECT (co_tab, default)
{
    /// Vector storing row data.
    co_vector vec;
    /// Table header.
    co hdr;
    /// Sorting column.
    unsigned col;
};
/* }}} */
/* {{{ */
CO_OBJECT (co_field_set, default)
{
    co_vector d;
    /// Number of columns of table.
    unsigned n;
};
/* }}} */
/* {{{ */
CO_OBJECT (co_field, default)
{
    const char *name;
    int width;
    int flags;
    co_type t;
};
/* }}} */

co_tab co_tab_new (co hdr);
co co_field_set_new (void);
co co_field_new (const char *name, co_type t, int w, int flags);

#if 0
/* {{{ */ typedef enum td_type
    /// Possible table column/data types.
{
    /// Integer number.
    td_num,
    /// String data.
    td_str,
    /// Floating point number.
    td_fnum
} td_type; /* }}} */

/* {{{ */ struct co_tab
    /// The table structure, representing table in memory.
    /** It consists of variable number of columns and rows. Both columns and
     *  rows are stored in linked lists and there is also pointer-array
     *  available for fast row lookup, growing dynamically as new rows are
     *  added.
     *
     *  \par Messages
     *  - col_new (char *name, td_type type, unsigned width)
     *  - row_new (...) - varargs are used as row data
     *  - row_add (struct tab_row *r) - append existing row
     *  - reset (void) - clear table data
     *  - sort (void) - sort table using current sort column
     *  - move (int mv) - move current row pointer to mv-th row
     *  - reload (void) - reload table data */
{
    /// Number of columns of table.
    unsigned ncols;
    /// Number of table rows.
    unsigned nrows;
    /// Size of row-cache.
    unsigned rcs;
    /// Sorting column.
    unsigned scol;
    /// Function that can fill this table with data (optional).
    int (*fill) (co *tab, void *custom);
    /// Currently selected row.
    struct tab_row *row;
    /// Head of column list.
    struct tab_col *cols;
    /// Head of row list.
    struct tab_row *data;
    /// Row cache, used for fast row lookup by row number.
    struct tab_row **rcache;
}; typedef struct co_tab co_tab; /* }}} */
/* {{{ */ struct tab_col
    /// Table column, specifies properties of given column
{
    /// Column name.
    char *name;
    /// Column (data) type.
    td_type type;
    /// Maximal width available for column data (used only for rendering)
    unsigned width;
    /// Use \a precision digits for decimal part of number (default = 2).
    /** \note Used only if type of this column is td_fnum */
    char precision;
    /// If set to 0, this column will be hidden (1 by default).
    int visible:1;
    /// Pointer to next column (used to create linked list).
    struct tab_col *next;
}; /* }}} */
/* {{{ */ struct tab_data
    /// One cell of table, contains cell data.
{
    /// Cell data itself. Can hold several types.
    union {
        /// Integer data, used if column is of type td_num.
        long long n;
        /// String data, used if column is of type td_str.
        char *s;
        /// Floating point number data, used if column is of type td_fnum.
        double f;
    } d;
    /// Column that this cell belongs to.
    struct tab_col *col;
    /// Next cell in this row.
    struct tab_data *next;
}; /* }}} */
/* {{{ */ struct tab_row
    /// One row of table.
{
    /// Head of linked list containing this row's cells.
    struct tab_data *data;
    /// Data pointer available for free use (used by tab_sort)
    struct tab_data *dcache;
    /// Pointer to next row in table.
    struct tab_row *next;
    /// Pointer to previous row in table.
    struct tab_row *prev;
}; /* }}} */

co *co_tab_new (void);
struct tab_data *tab_data_create (td_type t, ...);
struct tab_row *tab_row_create (void);
int tab_row_data_append (struct tab_row *r, struct tab_data *d);
char *tab_data_fmt (struct tab_data *d);
struct tab_row *tab_row (co *o, int);
struct tab_col *tab_col (co *o, int n);
struct tab_data *tab_row_data (struct tab_row *, int);
#endif /* 0 */

#endif /* __CO_TAB_H__ */

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top