2008-06-04 05:22:13 +02:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Copyright (C) 2008 Jonathan Moore Liles */
|
|
|
|
/* */
|
|
|
|
/* This program is free software; you can redistribute it and/or modify it */
|
|
|
|
/* under the terms of the GNU General Public License as published by the */
|
|
|
|
/* Free Software Foundation; either version 2 of the License, or (at your */
|
|
|
|
/* option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* This program 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 General Public License for */
|
|
|
|
/* more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public License along */
|
|
|
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Loggable.H"
|
2009-12-25 01:57:34 +01:00
|
|
|
|
2008-06-04 05:22:13 +02:00
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
class Log_Entry
|
|
|
|
{
|
|
|
|
// vector <Pair> _sa;
|
|
|
|
char **_sa;
|
|
|
|
int _i;
|
|
|
|
|
|
|
|
/* not permitted */
|
|
|
|
Log_Entry ( const Log_Entry &rhs );
|
|
|
|
Log_Entry & operator= ( const Log_Entry &rhs );
|
|
|
|
|
2008-06-04 05:34:36 +02:00
|
|
|
static char ** parse_alist ( const char *s );
|
2008-06-04 05:47:26 +02:00
|
|
|
static bool log_diff ( char **sa1, char **sa2 );
|
2008-06-04 05:34:36 +02:00
|
|
|
|
2008-06-04 05:22:13 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
Log_Entry ( );
|
|
|
|
Log_Entry ( char **sa );
|
2008-06-04 05:34:36 +02:00
|
|
|
Log_Entry ( const char *s );
|
2008-06-04 05:22:13 +02:00
|
|
|
~Log_Entry ( );
|
|
|
|
|
|
|
|
/****************/
|
|
|
|
/* Construction */
|
|
|
|
/****************/
|
|
|
|
|
|
|
|
void grow ( );
|
|
|
|
|
2010-01-14 04:20:40 +01:00
|
|
|
#define ADD( type, format, exp ) \
|
|
|
|
void add ( const char *name, type v ) \
|
|
|
|
{ \
|
|
|
|
grow(); \
|
2014-05-04 23:02:42 +02:00
|
|
|
(void)asprintf( &_sa[ _i ], "%s " format, name, (exp) ); \
|
2010-01-14 04:20:40 +01:00
|
|
|
strtok( _sa[ _i++ ], " " ); \
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_raw ( const char *name, const char *v )
|
|
|
|
{
|
|
|
|
grow();
|
2014-05-04 23:02:42 +02:00
|
|
|
(void)asprintf( &_sa[ _i ], "%s %s", name, v );
|
2010-01-14 04:20:40 +01:00
|
|
|
strtok( _sa[ _i++ ], " " );
|
|
|
|
}
|
2008-06-04 05:22:13 +02:00
|
|
|
|
|
|
|
/***************/
|
|
|
|
/* Examination */
|
|
|
|
/***************/
|
|
|
|
|
2008-06-06 05:26:51 +02:00
|
|
|
static bool diff ( Log_Entry *e1, Log_Entry *e2 );
|
2008-06-04 05:47:26 +02:00
|
|
|
|
2008-06-04 05:22:13 +02:00
|
|
|
int size ( void ) const;
|
|
|
|
|
2008-06-04 06:28:28 +02:00
|
|
|
void get ( int n, const char **name, const char **value ) const;
|
2008-06-04 05:22:13 +02:00
|
|
|
char **sa ( void );
|
|
|
|
|
2009-01-11 07:35:20 +01:00
|
|
|
char *print ( void ) const;
|
|
|
|
|
2008-06-04 05:22:13 +02:00
|
|
|
/* #define ADD ( type, format, exp ) \ */
|
|
|
|
/* void add ( const char *name, type v ) \ */
|
|
|
|
/* { \ */
|
|
|
|
/* char pat[ 256 ]; \ */
|
|
|
|
/* Pair p; \ */
|
|
|
|
/* p.name = strdup( name ); \ */
|
|
|
|
/* snprintf( pat, sizeof( pat ), format, exp ); \ */
|
|
|
|
/* p.value = strdup( pat ); \ */
|
|
|
|
/* _sa.push( p ); \ */
|
|
|
|
/* } \ */
|
|
|
|
|
2012-07-22 01:31:55 +02:00
|
|
|
|
|
|
|
void remove ( const char *s );
|
|
|
|
|
2008-06-04 05:22:13 +02:00
|
|
|
ADD( int, "%d", v );
|
|
|
|
ADD( nframes_t, "%lu", (unsigned long)v );
|
|
|
|
ADD( unsigned long, "%lu", v );
|
|
|
|
ADD( const char *, "\"%s\"", v ? Loggable::escape( v ) : "" );
|
|
|
|
ADD( Loggable * , "0x%X", v ? v->id() : 0 );
|
|
|
|
ADD( float, "%f", v );
|
|
|
|
ADD( double, "%f", v );
|
|
|
|
|
|
|
|
#undef ADD
|
|
|
|
|
|
|
|
};
|