include/cdio++ Add pre- and post- increment/decrement operators for

libcdio enums that it makes sense to iterate over.

example/C++/OO/*: use these
example/*: match up C and C++ programs better.
This commit is contained in:
rocky
2005-11-11 12:26:57 +00:00
parent edfc03ac78
commit 91147fd391
11 changed files with 126 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.1 2005/11/10 11:11:16 rocky Exp $
# $Id: Makefile.am,v 1.2 2005/11/11 12:26:57 rocky Exp $
#
# Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
#
@@ -28,5 +28,6 @@ libcdioinclude_HEADERS = \
device.hpp \
devices.hpp \
disc.hpp \
enum.hpp \
read.hpp \
track.hpp

View File

@@ -1,5 +1,5 @@
/* -*- C++ -*-
$Id: cdio.hpp,v 1.1 2005/11/10 11:11:16 rocky Exp $
$Id: cdio.hpp,v 1.2 2005/11/11 12:26:57 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -29,6 +29,10 @@
#include <cdio/cdio.h>
// Make pre- and post-increment operators for enums in libcdio where it
// makes sense.
#include <cdio++/enum.hpp>
class Cdio {
public:

50
include/cdio++/enum.hpp Normal file
View File

@@ -0,0 +1,50 @@
/* -*- C++ -*-
$Id: enum.hpp,v 1.1 2005/11/11 12:26:57 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
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; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** \file enum.hpp
*
* \brief C++ header for pre- and post-increment operators for
* enumerations defined in libcdio that it makes sense to iterate over.
*/
#define ENUM_ITERATE_FNS(type) \
inline \
type &operator++(type &t) \
{ \
return t = type(t + 1); \
} \
inline \
type &operator++(type &t, int) \
{ \
return t = type(t + 1); \
} \
inline \
type &operator--(type &t) \
{ \
return t = type(t - 1); \
} \
inline \
type &operator--(type &t, int) \
{ \
return t = type(t - 1); \
}
ENUM_ITERATE_FNS(cdtext_field_t)
ENUM_ITERATE_FNS(driver_id_t)

View File

@@ -1,5 +1,5 @@
/*
$Id: cdtext.h,v 1.12 2005/11/10 00:44:40 rocky Exp $
$Id: cdtext.h,v 1.13 2005/11/11 12:26:57 rocky Exp $
Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
adapted from cuetools
@@ -37,6 +37,7 @@ extern "C" {
#endif /* __cplusplus */
#define MAX_CDTEXT_FIELDS 13
#define MIN_CDTEXT_FIELD 0
/*! \brief structure for holding CD-Text information
@@ -46,7 +47,9 @@ extern "C" {
char *field[MAX_CDTEXT_FIELDS];
};
/*! \brief A list of all of the CD-Text fields */
/*! \brief A list of all of the CD-Text fields. Because
the interval has no gaps, we can use ++ to iterate over fields.
*/
typedef enum {
CDTEXT_ARRANGER = 0, /**< name(s) of the arranger(s) */
CDTEXT_COMPOSER = 1, /**< name(s) of the composer(s) */

View File

@@ -1,5 +1,5 @@
/* -*- c -*-
$Id: device.h,v 1.25 2005/11/07 07:44:00 rocky Exp $
$Id: device.h,v 1.26 2005/11/11 12:26:57 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -136,6 +136,8 @@ extern "C" {
* different than what is available on a given host.
*
* Order is a little significant since the order is used in scans.
* Also the enumeration values are assumed not to leave any holes so
* we can use ++ to iterate over values.
* We have to start with DRIVER_UNKNOWN and devices should come before
* disk-image readers. By putting something towards the top (a lower
* enumeration number), in an iterative scan we prefer that to