Split Log_Entry class into files of its own.

This commit is contained in:
Jonathan Moore Liles 2008-06-03 22:22:13 -05:00
parent 9ae6c0ea5e
commit 6e3e41f9ba
3 changed files with 167 additions and 113 deletions

81
Timeline/Log_Entry.C Normal file
View File

@ -0,0 +1,81 @@
/*******************************************************************************/
/* 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. */
/*******************************************************************************/
#include "Log_Entry.H"
Log_Entry::Log_Entry ( )
{
_sa = (char**)malloc( sizeof( char * ) );
*_sa = NULL;
_i = 0;
}
Log_Entry::Log_Entry ( char **sa )
{
_sa = sa;
_i = 0;
if ( _sa )
while ( _sa[ _i ] ) ++_i;
}
Log_Entry::~Log_Entry ( )
{
if ( ! _sa )
return;
for ( _i = 0; _sa[ _i ]; ++_i )
{
free( _sa[ _i ] );
}
free( _sa );
}
void
Log_Entry::grow ( )
{
_sa = (char**)realloc( _sa, sizeof( char * ) * (_i + 2) );
_sa[ _i + 1 ] = NULL;
}
\
int
Log_Entry::size ( void ) const
{
return _i;
}
void
Log_Entry::get ( int n, const char **name, const char **value )
{
*name = _sa[ n ];
*value = *name + strlen( *name ) + 1;
}
char **
Log_Entry::sa ( void )
{
char **sa = _sa;
_sa = NULL;
return sa;
}

85
Timeline/Log_Entry.H Normal file
View File

@ -0,0 +1,85 @@
/*******************************************************************************/
/* 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"
#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 );
public:
Log_Entry ( );
Log_Entry ( char **sa );
~Log_Entry ( );
/****************/
/* Construction */
/****************/
void grow ( );
#define ADD( type, format, exp ) \
void add ( const char *name, type v ) \
{ \
grow(); \
asprintf( &_sa[ _i ], "%s " format, name, (exp) ); \
strtok( _sa[ _i++ ], " " ); \
} \
/***************/
/* Examination */
/***************/
int size ( void ) const;
void get ( int n, const char **name, const char **value );
char **sa ( void );
/* #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 ); \ */
/* } \ */
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
};

View File

@ -270,116 +270,4 @@ public:
class Log_Entry #include "Log_Entry.H"
{
// vector <Pair> _sa;
char **_sa;
int _i;
/* not permitted */
Log_Entry ( const Log_Entry &rhs );
Log_Entry & operator= ( const Log_Entry &rhs );
public:
struct Pair
{
const char *name;
const char *value;
};
Log_Entry ( )
{
_sa = (char**)malloc( sizeof( char * ) );
*_sa = NULL;
_i = 0;
}
Log_Entry ( char **sa )
{
_sa = sa;
_i = 0;
if ( _sa )
while ( _sa[ _i ] ) ++_i;
}
~Log_Entry ( )
{
if ( ! _sa )
return;
for ( _i = 0; _sa[ _i ]; ++_i )
{
free( _sa[ _i ] );
}
free( _sa );
}
/****************/
/* Construction */
/****************/
void grow ( )
{
_sa = (char**)realloc( _sa, sizeof( char * ) * (_i + 2) );
_sa[ _i + 1 ] = NULL;
}
#define ADD( type, format, exp ) \
void add ( const char *name, type v ) \
{ \
grow(); \
asprintf( &_sa[ _i ], "%s " format, name, (exp) ); \
strtok( _sa[ _i++ ], " " ); \
} \
/***************/
/* Examination */
/***************/
int size ( void ) const
{
return _i;
}
void get ( int n, const char **name, const char **value )
{
*name = _sa[ n ];
*value = *name + strlen( *name ) + 1;
}
char **sa ( void )
{
char **sa = _sa;
_sa = NULL;
return sa;
}
/* #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 ); \ */
/* } \ */
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
};