From 6e3e41f9bac8e1e5c6d24a02103c0037ee9f17dd Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Tue, 3 Jun 2008 22:22:13 -0500 Subject: [PATCH] Split Log_Entry class into files of its own. --- Timeline/Log_Entry.C | 81 ++++++++++++++++++++++++++++++ Timeline/Log_Entry.H | 85 ++++++++++++++++++++++++++++++++ Timeline/Loggable.H | 114 +------------------------------------------ 3 files changed, 167 insertions(+), 113 deletions(-) create mode 100644 Timeline/Log_Entry.C create mode 100644 Timeline/Log_Entry.H diff --git a/Timeline/Log_Entry.C b/Timeline/Log_Entry.C new file mode 100644 index 0000000..2c2d48e --- /dev/null +++ b/Timeline/Log_Entry.C @@ -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; +} diff --git a/Timeline/Log_Entry.H b/Timeline/Log_Entry.H new file mode 100644 index 0000000..e88865a --- /dev/null +++ b/Timeline/Log_Entry.H @@ -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 _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 + +}; diff --git a/Timeline/Loggable.H b/Timeline/Loggable.H index cd3c21a..dbca2e7 100644 --- a/Timeline/Loggable.H +++ b/Timeline/Loggable.H @@ -270,116 +270,4 @@ public: -class Log_Entry -{ -// vector _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 - -}; +#include "Log_Entry.H"