This commit was manufactured by cvs2svn to create tag 'darkice-0_3'.

This commit is contained in:
nobody 2000-12-20 13:01:43 +00:00
parent d7f5de1d90
commit 2e6dd391f6
152 changed files with 47298 additions and 0 deletions

View File

@ -0,0 +1,4 @@
DarkIce is being written by:
Akos Maroy, darkeye@users.sourceforge.net

View File

@ -0,0 +1,389 @@
Contents
--------
1. Standard Template Library license
2. GNU General Public License
1. Standard Template Library license
------------------------------------
Sources found in the stl directory are covered under the following
license:
Copyright (c) 1996
Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, distribute and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear
in supporting documentation. Silicon Graphics makes no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied warranty.
Copyright (c) 1994
Hewlett-Packard Company
Permission to use, copy, modify, distribute and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear
in supporting documentation. Hewlett-Packard Company makes no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied warranty.
2. GNU General Public License
-----------------------------
All source code in the src directory is covered under the
GNU General Public License (GNU GPL).
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@ -0,0 +1,14 @@
20-12-2000: DarkIce 0.3 released
o added POSIX real-time scheduling
18-11-2000: DarkIce 0.2 released
o code cleanup
o first real tests made
o added verbosity command line option
13-11-2000: DarkIce 0.1 released

View File

@ -0,0 +1,182 @@
Basic Installation
==================
These are generic installation instructions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, a file
`config.cache' that saves the results of its tests to speed up
reconfiguring, and a file `config.log' containing compiler output
(useful mainly for debugging `configure').
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If at some point `config.cache'
contains results you don't want to keep, you may remove or edit it.
The file `configure.in' is used to create `configure' by a program
called `autoconf'. You only need `configure.in' if you want to change
it or regenerate `configure' using a newer version of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system. If you're
using `csh' on an old version of System V, you might need to type
`sh ./configure' instead to prevent `csh' from trying to execute
`configure' itself.
Running `configure' takes awhile. While running, it prints some
messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. You can give `configure'
initial values for variables by setting them in the environment. Using
a Bourne-compatible shell, you can do that on the command line like
this:
CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
Or on systems that have the `env' program, you can do it like this:
env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you must use a version of `make' that
supports the `VPATH' variable, such as GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
If you have to use a `make' that does not supports the `VPATH'
variable, you have to compile the package for one architecture at a time
in the source code directory. After you have installed the package for
one architecture, use `make distclean' before reconfiguring for another
architecture.
Installation Names
==================
By default, `make install' will install the package's files in
`/usr/local/bin', `/usr/local/man', etc. You can specify an
installation prefix other than `/usr/local' by giving `configure' the
option `--prefix=PATH'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
give `configure' the option `--exec-prefix=PATH', the package will use
PATH as the prefix for installing programs and libraries.
Documentation and other data files will still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=PATH' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Specifying the System Type
==========================
There may be some features `configure' can not figure out
automatically, but needs to determine by the type of host the package
will run on. Usually `configure' can figure that out, but if it prints
a message saying it can not guess the host type, give it the
`--host=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name with three fields:
CPU-COMPANY-SYSTEM
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the host type.
If you are building compiler tools for cross-compiling, you can also
use the `--target=TYPE' option to select the type of system they will
produce code for and the `--build=TYPE' option to select the type of
system on which you are compiling the package.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Operation Controls
==================
`configure' recognizes the following options to control how it
operates.
`--cache-file=FILE'
Use and save the results of the tests in FILE instead of
`./config.cache'. Set FILE to `/dev/null' to disable caching, for
debugging `configure'.
`--help'
Print a summary of the options to `configure', and exit.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`--version'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`configure' also accepts some other, not widely useful, options.

View File

@ -0,0 +1,11 @@
SUBDIRS = src
EXTRA_DIST = stl doc darkice.cfg
dist-hook: kdocs
kdocs: src
cd src; kdoc --private --strip-h-path --name DarkIce --outputdir ../doc/ *.h
kdocs_clean:
rm -rf doc/

View File

@ -0,0 +1,16 @@
20-12-2000, Akos Maroy, darkeye@users.sourceforge.net
Released version 0.3. See ChangeLog for changes.
18-11-2000, Akos Maroy, darkeye@users.sourceforge.net
Released version 0.2. See ChangeLog for changes.
13-11-2000, Akos Maroy, darkeye@users.sourceforge.net
Initial release. Supports the lame encoder.

View File

@ -0,0 +1,132 @@
DarkIce 0.2 live audio streamer, http://darkice.sourceforge.net
Copyright (C) 2000, Tyrell Hungary, http://tyrell.hu
Contents
--------
1. Compiling and installing
2. Configuration file format
2.1 Section [general]
2.2 Section [input]
2.3 Section [lamex]
3. Supported encoders
4. Kown bugs and issues
1. Compiling and installing
---------------------------
On how to compile and install, please read the file INSTALL. If you're
impatient, try:
./configure
make
make install
The executable built is src/darkice.
For command line syntax, try:
darkice --help
It is recommended to run DarkIce as root.
2. Configuration file format
----------------------------
DarkIce requires a configuration file. Please take a look at the supplied
darkice.cfg sample configuration file.
The file has to following general format:
[section1]
# this is a whole line comment
key = value
an ugly key name = long value # this end is a comment too
[section2]
# this is a whole line comment in section 2
key = value
an ugly key name = long value # this end is a comment too
In particular, the following sections and values are required:
2.1 Section [general]
---------------------
This section describes general operational parameters.
Required values:
duration Time for DarkIce to run, in seconds.
bufferSecs Data read from the sound card is buffered before sent to
the mp3 encoder. Each buffer will be able to hold this
many seconds of samples.
2.2 Section [input]
---------------------
This section describes the input.
Required values:
device OSS DSP audio device to record from (e.g. /dev/dsp)
sampleRate The sample rate to record with, samples per second
(e.g. 44100 for 44.1kHz CD-quality audio)
bitsPerSample Bites to use for each sample (e.g. 8 bits or 16 bits)
channel Number of channels to record (e.g. 1 for mono, 2 for stereo)
2.3 Section [lamex]
---------------------
This section describes an output to an IceCast server, while encoding
with a lame encoder. There may be at most 8 outputs, numbered from 0 ... 7.
The number is included in the section name (e.g. [lame0] ... [lame7]).
Required values:
encoder The command used to invoke the encoder
bitrate Bit rate to encode to in kBits / sec (e.g. 96)
server The IceCast server's name (e.g. yp.sourserver.com)
port The port to connect to the IceCast server (e.g. 8000)
password The password to use to connet to the IceCast server
mountPoint Mount point for the stream on the server
name Name of the stream
description Description of the stream
url Url related to the stream
genre Genre of the stream
public "yes" or "no", wether the stream is public
Optional values:
remoteDumpFile The file the IceCast server should dump the contents of
this stream on its side.
lowpass Lowpass filter setting for the lame encoder. If not set,
the encoder's default behaviour is used
highpass Highpass filter setting for the lame encoder. If not set,
the encoder's default behaviour is used
3. Supported encoders
---------------------
Currently the lame encoder is supported (http://www.mp3dev.org/mp3/).
Tests were made with version 3.86.
4. Kown bugs and issues
-----------------------
Lots of bugs, this is the first release.
You must have write permissions in the directory you execute DarkIce.
DarkIce was only tested under RedHat Linux

View File

@ -0,0 +1,3 @@
o make FIFO pipes in /tmp with valid temp filenames
o change Ref to follow inheritance
o add support for shared object lame

127
darkice/tags/darkice-0_3/aclocal.m4 vendored Normal file
View File

@ -0,0 +1,127 @@
dnl aclocal.m4 generated automatically by aclocal 1.4
dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
dnl PARTICULAR PURPOSE.
# Do all the work for Automake. This macro actually does too much --
# some checks are only needed if your package does certain things.
# But this isn't really a big deal.
# serial 1
dnl Usage:
dnl AM_INIT_AUTOMAKE(package,version, [no-define])
AC_DEFUN(AM_INIT_AUTOMAKE,
[AC_REQUIRE([AC_PROG_INSTALL])
PACKAGE=[$1]
AC_SUBST(PACKAGE)
VERSION=[$2]
AC_SUBST(VERSION)
dnl test to see if srcdir already configured
if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
fi
ifelse([$3],,
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package]))
AC_REQUIRE([AM_SANITY_CHECK])
AC_REQUIRE([AC_ARG_PROGRAM])
dnl FIXME This is truly gross.
missing_dir=`cd $ac_aux_dir && pwd`
AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
AC_REQUIRE([AC_PROG_MAKE_SET])])
#
# Check to make sure that the build environment is sane.
#
AC_DEFUN(AM_SANITY_CHECK,
[AC_MSG_CHECKING([whether build environment is sane])
# Just in case
sleep 1
echo timestamp > conftestfile
# Do `set' in a subshell so we don't clobber the current shell's
# arguments. Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null`
if test "[$]*" = "X"; then
# -L didn't work.
set X `ls -t $srcdir/configure conftestfile`
fi
if test "[$]*" != "X $srcdir/configure conftestfile" \
&& test "[$]*" != "X conftestfile $srcdir/configure"; then
# If neither matched, then we have a broken ls. This can happen
# if, for instance, CONFIG_SHELL is bash and it inherits a
# broken ls alias from the environment. This has actually
# happened. Such a system could not be considered "sane".
AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken
alias in your environment])
fi
test "[$]2" = conftestfile
)
then
# Ok.
:
else
AC_MSG_ERROR([newly created file is older than distributed files!
Check your system clock])
fi
rm -f conftest*
AC_MSG_RESULT(yes)])
dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY)
dnl The program must properly implement --version.
AC_DEFUN(AM_MISSING_PROG,
[AC_MSG_CHECKING(for working $2)
# Run test in a subshell; some versions of sh will print an error if
# an executable is not found, even if stderr is redirected.
# Redirect stdin to placate older versions of autoconf. Sigh.
if ($2 --version) < /dev/null > /dev/null 2>&1; then
$1=$2
AC_MSG_RESULT(found)
else
$1="$3/missing $2"
AC_MSG_RESULT(missing)
fi
AC_SUBST($1)])
# Like AC_CONFIG_HEADER, but automatically create stamp file.
AC_DEFUN(AM_CONFIG_HEADER,
[AC_PREREQ([2.12])
AC_CONFIG_HEADER([$1])
dnl When config.status generates a header, we must update the stamp-h file.
dnl This file resides in the same directory as the config header
dnl that is generated. We must strip everything past the first ":",
dnl and everything past the last "/".
AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl
ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>,
<<test -z "<<$>>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>,
<<am_indx=1
for am_file in <<$1>>; do
case " <<$>>CONFIG_HEADERS " in
*" <<$>>am_file "*<<)>>
echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx
;;
esac
am_indx=`expr "<<$>>am_indx" + 1`
done<<>>dnl>>)
changequote([,]))])

View File

@ -0,0 +1,77 @@
/* configure.h.in. Generated automatically from configure.in by autoheader. */
/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
#undef HAVE_SYS_WAIT_H
/* Define to `int' if <sys/types.h> doesn't define. */
#undef pid_t
/* Define to `unsigned' if <sys/types.h> doesn't define. */
#undef size_t
/* Define if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define if you have the <errno.h> header file. */
#undef HAVE_ERRNO_H
/* Define if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define if you have the <getopt.h> header file. */
#undef HAVE_GETOPT_H
/* Define if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
/* Define if you have the <netdb.h> header file. */
#undef HAVE_NETDB_H
/* Define if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
/* Define if you have the <sched.h> header file. */
#undef HAVE_SCHED_H
/* Define if you have the <signal.h> header file. */
#undef HAVE_SIGNAL_H
/* Define if you have the <stdio.h> header file. */
#undef HAVE_STDIO_H
/* Define if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define if you have the <sys/soundcard.h> header file. */
#undef HAVE_SYS_SOUNDCARD_H
/* Define if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define if you have the <time.h> header file. */
#undef HAVE_TIME_H
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Name of package */
#undef PACKAGE
/* Version number of package */
#undef VERSION

View File

@ -0,0 +1,20 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/DarkIce.cpp)
AM_INIT_AUTOMAKE(darkice, 0.3)
AM_CONFIG_HEADER(configure.h)
AC_PROG_CXX
AC_PROG_INSTALL
dnl AC_STDC_HEADERS
AC_HAVE_HEADERS(errno.h fcntl.h stdio.h stdlib.h string.h unistd.h limits.h)
AC_HAVE_HEADERS(getopt.h signal.h time.h sys/time.h sys/types.h sys/soundcard.h)
AC_HAVE_HEADERS(netdb.h netinet/in.h sys/ioctl.h sys/socket.h sys/stat.h)
AC_HAVE_HEADERS(sched.h)
AC_HEADER_SYS_WAIT()
AC_TYPE_PID_T()
AC_TYPE_SIZE_T()
AC_OUTPUT(Makefile src/Makefile)

View File

@ -0,0 +1,41 @@
[general]
duration = 60
bufferSecs = 5
[input]
device = /dev/dsp
sampleRate = 22050
bitsPerSample = 16
channel = 2
[lame0]
encoder = notlame
bitrate = 96
server = yp.yourserver.com
port = 8000
password = hackme
mountPoint = live96
name = DarkIce trial
description = This is only a trial
url = http://www.yourserver.com
genre = live
public = no
remoteDumpFile = /tmp/live96.mp3
[lame1]
encoder = notlame
bitrate = 24
lowpass = 8500
server = yp.yourserver.com
port = 8000
password = hackme
mountPoint = live24
name = DarkIce trial
description = This is only a trial
url = http://www.yourserver.com
genre = live
public = no
remoteDumpFile = /tmp/live24.mp3

View File

@ -0,0 +1,251 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
chmodcmd=""
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

190
darkice/tags/darkice-0_3/missing Executable file
View File

@ -0,0 +1,190 @@
#! /bin/sh
# Common stub for a few missing GNU programs while installing.
# Copyright (C) 1996, 1997 Free Software Foundation, Inc.
# Franc,ois Pinard <pinard@iro.umontreal.ca>, 1996.
# 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, 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.
if test $# -eq 0; then
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
fi
case "$1" in
-h|--h|--he|--hel|--help)
echo "\
$0 [OPTION]... PROGRAM [ARGUMENT]...
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
error status if there is no known handling for PROGRAM.
Options:
-h, --help display this help and exit
-v, --version output version information and exit
Supported PROGRAM values:
aclocal touch file \`aclocal.m4'
autoconf touch file \`configure'
autoheader touch file \`config.h.in'
automake touch all \`Makefile.in' files
bison create \`y.tab.[ch]', if possible, from existing .[ch]
flex create \`lex.yy.c', if possible, from existing .c
lex create \`lex.yy.c', if possible, from existing .c
makeinfo touch the output file
yacc create \`y.tab.[ch]', if possible, from existing .[ch]"
;;
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
echo "missing - GNU libit 0.0"
;;
-*)
echo 1>&2 "$0: Unknown \`$1' option"
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
;;
aclocal)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified \`acinclude.m4' or \`configure.in'. You might want
to install the \`Automake' and \`Perl' packages. Grab them from
any GNU archive site."
touch aclocal.m4
;;
autoconf)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified \`configure.in'. You might want to install the
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU
archive site."
touch configure
;;
autoheader)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified \`acconfig.h' or \`configure.in'. You might want
to install the \`Autoconf' and \`GNU m4' packages. Grab them
from any GNU archive site."
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' configure.in`
test -z "$files" && files="config.h"
touch_files=
for f in $files; do
case "$f" in
*:*) touch_files="$touch_files "`echo "$f" |
sed -e 's/^[^:]*://' -e 's/:.*//'`;;
*) touch_files="$touch_files $f.in";;
esac
done
touch $touch_files
;;
automake)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified \`Makefile.am', \`acinclude.m4' or \`configure.in'.
You might want to install the \`Automake' and \`Perl' packages.
Grab them from any GNU archive site."
find . -type f -name Makefile.am -print |
sed 's/\.am$/.in/' |
while read f; do touch "$f"; done
;;
bison|yacc)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified a \`.y' file. You may need the \`Bison' package
in order for those modifications to take effect. You can get
\`Bison' from any GNU archive site."
rm -f y.tab.c y.tab.h
if [ $# -ne 1 ]; then
eval LASTARG="\${$#}"
case "$LASTARG" in
*.y)
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" y.tab.c
fi
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" y.tab.h
fi
;;
esac
fi
if [ ! -f y.tab.h ]; then
echo >y.tab.h
fi
if [ ! -f y.tab.c ]; then
echo 'main() { return 0; }' >y.tab.c
fi
;;
lex|flex)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified a \`.l' file. You may need the \`Flex' package
in order for those modifications to take effect. You can get
\`Flex' from any GNU archive site."
rm -f lex.yy.c
if [ $# -ne 1 ]; then
eval LASTARG="\${$#}"
case "$LASTARG" in
*.l)
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" lex.yy.c
fi
;;
esac
fi
if [ ! -f lex.yy.c ]; then
echo 'main() { return 0; }' >lex.yy.c
fi
;;
makeinfo)
echo 1>&2 "\
WARNING: \`$1' is missing on your system. You should only need it if
you modified a \`.texi' or \`.texinfo' file, or any other file
indirectly affecting the aspect of the manual. The spurious
call might also be the consequence of using a buggy \`make' (AIX,
DU, IRIX). You might want to install the \`Texinfo' package or
the \`GNU make' package. Grab either from any GNU archive site."
file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
if test -z "$file"; then
file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
fi
touch $file
;;
*)
echo 1>&2 "\
WARNING: \`$1' is needed, and you do not seem to have it handy on your
system. You might have modified some files without having the
proper tools for further handling them. Check the \`README' file,
it often tells you about the needed prerequirements for installing
this package. You may also peek at any GNU archive site, in case
some other package would contain this missing \`$1' program."
exit 1
;;
esac
exit 0

View File

@ -0,0 +1,40 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Public domain
# $Id$
errstatus=0
for file
do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d
do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp"
mkdir "$pathcomp" || lasterr=$?
if test ! -d "$pathcomp"; then
errstatus=$lasterr
fi
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
# mkinstalldirs ends here

View File

@ -0,0 +1,370 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : AudioEncoder.h
Version : $Revision$
Author : $Author$
Location : $AudioEncoder$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef AUDIO_ENCODER_H
#define AUDIO_ENCODER_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Referable.h"
#include "AudioSource.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An audio encoder
*
* @author $Author$
* @version $Revision$
*/
class AudioEncoder : public virtual Referable
{
private:
/**
* Sample rate of the input.
*/
unsigned int inSampleRate;
/**
* Number of bits per sample of the input.
*/
unsigned int inBitsPerSample;
/**
* Number of channels of the input.
*/
unsigned int inChannel;
/**
* Bit rate of the output. (bits/sec)
*/
unsigned int outBitrate;
/**
* Sample rate of the output.
*/
unsigned int outSampleRate;
/**
* Number of channels of the output.
*/
unsigned int outChannel;
/**
* Initialize the object.
*
* @param inSampleRate sample rate of the input.
* @param inBitsPerSample number of bits per sample of the input.
* @param inChannel number of channels of the input.
* @param outBitrate bit rate of the output.
* @param outSampleRate sample rate of the output.
* @param outChannel number of channels of the output.
* @exception Exception
*/
inline void
init ( unsigned int inSampleRate,
unsigned int inBitsPerSample,
unsigned int inChannel,
unsigned int outBitrate,
unsigned int outSampleRate,
unsigned int outChannel ) throw ( Exception )
{
this->inSampleRate = inSampleRate;
this->inBitsPerSample = inBitsPerSample;
this->inChannel = inChannel;
this->outBitrate = outBitrate;
this->outSampleRate = outSampleRate;
this->outChannel = outChannel;
}
/**
* De-iitialize the object.
*
* @exception Exception
*/
inline void
strip ( void ) throw ( Exception )
{
}
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
AudioEncoder ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Constructor.
*
* @param inSampleRate sample rate of the input.
* @param inBitsPerSample number of bits per sample of the input.
* @param inChannel number of channels of the input.
* @param outBitrate bit rate of the output (bits/sec).
* @param outSampleRate sample rate of the output.
* If 0, inSampleRate is used.
* @param outChannel number of channels of the output.
* If 0, inChannel is used.
* @exception Exception
*/
inline
AudioEncoder ( unsigned int inSampleRate,
unsigned int inBitsPerSample,
unsigned int inChannel,
unsigned int outBitrate,
unsigned int outSampleRate = 0,
unsigned int outChannel = 0 )
throw ( Exception )
{
init ( inSampleRate,
inBitsPerSample,
inChannel,
outBitrate,
outSampleRate ? outSampleRate : inSampleRate,
outChannel ? outChannel : inChannel );
}
/**
* Constructor.
*
* @param as get input sample rate, bits per sample and channels
* from this AudioSource.
* @param outBitrate bit rate of the output (bits/sec).
* @param outSampleRate sample rate of the output.
* If 0, input sample rate is used.
* @param outChannel number of channels of the output.
* If 0, input channel is used.
* @exception Exception
*/
inline
AudioEncoder ( const AudioSource * as,
unsigned int outBitrate,
unsigned int outSampleRate = 0,
unsigned int outChannel = 0 )
throw ( Exception)
{
init( as->getSampleRate(),
as->getBitsPerSample(),
as->getChannel(),
outBitrate,
outSampleRate ? outSampleRate : as->getSampleRate(),
outChannel ? outChannel : as->getChannel() );
}
/**
* Copy constructor.
*
* @param encoder the AudioEncoder to copy.
*/
inline
AudioEncoder ( const AudioEncoder & encoder ) throw ( Exception )
{
init ( encoder.inSampleRate,
encoder.inBitsPerSample,
encoder.inChannel,
encoder.outBitrate,
encoder.outSampleRate,
encoder.outChannel );
}
/**
* Assignment operator.
*
* @param encoder the AudioEncoder to assign this to.
* @return a reference to this AudioEncoder.
* @exception Exception
*/
inline virtual AudioEncoder &
operator= ( const AudioEncoder & encoder ) throw ( Exception )
{
if ( this != &encoder ) {
strip();
init ( encoder.inSampleRate,
encoder.inBitsPerSample,
encoder.inChannel,
encoder.outBitrate,
encoder.outSampleRate,
encoder.outChannel );
}
return *this;
}
public:
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~AudioEncoder ( void ) throw ( Exception )
{
strip();
}
/**
* Get the number of channels of the input.
*
* @return the number of channels of the input.
*/
inline int
getInChannel ( void ) const throw ()
{
return inChannel;
}
/**
* Get the sample rate of the input.
*
* @return the sample rate of the input.
*/
inline int
getInSampleRate ( void ) const throw ()
{
return inSampleRate;
}
/**
* Get the number of bits per sample of the input.
*
* @return the number of bits per sample of the input.
*/
inline int
getInBitsPerSample ( void ) const throw ()
{
return inBitsPerSample;
}
/**
* Get the number of channels of the output.
*
* @return the number of channels of the output.
*/
inline int
getOutChannel ( void ) const throw ()
{
return outChannel;
}
/**
* Get the sample rate of the output.
*
* @return the sample rate of the output.
*/
inline int
getOutSampleRate ( void ) const throw ()
{
return outSampleRate;
}
/**
* Get the bit rate of the output. (bits/sec)
*
* @return the bit rate of the output.
*/
inline int
getOutBitrate ( void ) const throw ()
{
return outBitrate;
}
/**
* Check wether encoding is in progress.
*
* @return true if encoding is in progress, false otherwise.
*/
virtual bool
isRunning ( void ) const throw () = 0;
/**
* Start encoding. This function returns as soon as possible,
* with encoding started in the background.
*
* @return true if encoding has started, false otherwise.
* @exception Exception
*/
virtual bool
start ( void ) throw ( Exception ) = 0;
/**
* Stop encoding. Stops the encoding running in the background.
*
* @exception Exception
*/
virtual void
stop ( void ) throw ( Exception ) = 0;
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* AUDIO_ENCODER_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.2 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.1.1.1 2000/11/05 10:05:47 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,234 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : AudioSource.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef AUDIO_SOURCE_H
#define AUDIO_SOURCE_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Source.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Audio data input
*
* @author $Author$
* @version $Revision$
*/
class AudioSource : public Source
{
private:
/**
* Number of channels of the audio source
* (e.g. 1 for mono, 2 for stereo, etc.)
*/
unsigned int channel;
/**
* Samples per second (e.g. 44100 for 44.1kHz CD quality)
*/
unsigned int sampleRate;
/**
* Bits per sample (e.g. 8 bits, 16 bits, etc.)
*/
unsigned int bitsPerSample;
/**
* Initialize the object.
*
* @param sampleRate samples per second.
* @param bitsPerSample bits per sample.
* @param channel number of channels of the audio source.
* @exception Exception
*/
inline void
init ( unsigned int sampleRate,
unsigned int bitsPerSample,
unsigned int channel ) throw ( Exception )
{
this->sampleRate = sampleRate;
this->bitsPerSample = bitsPerSample;
this->channel = channel;
}
/**
* De-initialize the object.
*
* @exception Exception
*/
inline void
strip ( void ) throw ( Exception )
{
}
protected:
/**
* Constructor.
* Because all values have defaults, this is also the default
* constructor.
*
* @param sampleRate samples per second (e.g. 44100 for 44.1kHz).
* @param bitsPerSample bits per sample (e.g. 16 bits).
* @param channel number of channels of the audio source
* (e.g. 1 for mono, 2 for stereo, etc.).
* @exception Exception
*/
inline
AudioSource ( unsigned int sampleRate = 44100,
unsigned int bitsPerSample = 16,
unsigned int channel = 2 )
throw ( Exception )
{
init ( sampleRate, bitsPerSample, channel);
}
/**
* Copy Constructor.
*
* @param source the object to copy.
* @exception Exception
*/
inline
AudioSource ( const AudioSource & as ) throw ( Exception )
: Source( as )
{
init ( as.sampleRate, as.bitsPerSample, as.channel);
}
/**
* Destructor.
*
* @exception Exception
*/
virtual inline
~AudioSource ( void ) throw ( Exception )
{
}
/**
* Assignment operator.
*
* @param as the object to assign to this one.
* @return a reference to this object.
* @exception Exception
*/
inline virtual AudioSource &
operator= ( const AudioSource & as ) throw ( Exception )
{
if ( this != &as ) {
strip();
Source::operator=( as );
init ( as.sampleRate, as.bitsPerSample, as.channel);
}
return *this;
}
public:
/**
* Get the number of channels for this AudioSource.
*
* @return the number of channels.
*/
inline unsigned int
getChannel ( void ) const throw ()
{
return channel;
}
/**
* Get the sample rate per seconds for this AudioSource.
*
* @return the sample rate per seconds.
*/
inline unsigned int
getSampleRate ( void ) const throw ()
{
return sampleRate;
}
/**
* Get the number of bits per sample for this AudioSource.
*
* @return the number of bits per sample.
*/
inline unsigned int
getBitsPerSample ( void ) const throw ()
{
return bitsPerSample;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* AUDIO_SOURCE_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.1.1.1 2000/11/05 10:05:47 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,389 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : BufferedSink.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
the buffer is filled like this:
buffer bufferEnd
| |
+----------+--------------------------+--------------+
|<---- valid data -------->|
outp inp
buffer bufferEnd
| |
+----------------+--------------+--------------------+
-- valid data -->| |--- valid data ----->
inp outp
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include "Exception.h"
#include "BufferedSink.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
BufferedSink :: init ( Sink * sink,
unsigned int size,
unsigned int chunkSize ) throw ( Exception )
{
if ( !sink ) {
throw Exception( __FILE__, __LINE__, "no sink");
}
this->sink = sink; // create a reference
this->chunkSize = chunkSize ? chunkSize : 1;
this->bufferSize = size;
// make bufferSize a multiple of chunkSize
this->bufferSize -= this->bufferSize % this->chunkSize;
this->peak = 0;
this->misalignment = 0;
this->buffer = new unsigned char[bufferSize];
this->bufferEnd = buffer + bufferSize;
this->inp = buffer;
this->outp = buffer;
}
/*------------------------------------------------------------------------------
* Copy Constructor
*----------------------------------------------------------------------------*/
BufferedSink :: BufferedSink ( const BufferedSink & buffer )
throw ( Exception )
{
init( buffer.sink.get(), buffer.bufferSize, buffer.chunkSize);
this->peak = buffer.peak;
this->misalignment = buffer.misalignment;
memcpy( this->buffer, buffer.buffer, this->bufferSize);
}
/*------------------------------------------------------------------------------
* De-initalize the object
*----------------------------------------------------------------------------*/
void
BufferedSink :: strip ( void ) throw ( Exception )
{
if ( isOpen() ) {
close();
}
sink = 0; // delete the reference
delete buffer;
}
/*------------------------------------------------------------------------------
* Assignment operator
*----------------------------------------------------------------------------*/
BufferedSink &
BufferedSink :: operator= ( const BufferedSink & buffer )
throw ( Exception )
{
if ( this != &buffer ) {
strip();
Sink::operator=( buffer );
init( buffer.sink.get(), buffer.bufferSize, buffer.chunkSize);
this->peak = buffer.peak;
this->misalignment = buffer.misalignment;
memcpy( this->buffer, buffer.buffer, this->bufferSize);
}
return *this;
}
/*------------------------------------------------------------------------------
* Store bufferSize bytes into the buffer
* All data is consumed. The return value is less then bufferSize only
* if the BufferedSink's internal buffer is smaller than bufferSize,
* thus can't hold that much
* The data to be stored is treated as parts with chunkSize size
* Only full chunkSize sized parts are stored
*----------------------------------------------------------------------------*/
unsigned int
BufferedSink :: store ( const void * buffer,
unsigned int bufferSize ) throw ( Exception )
{
const unsigned char * buf;
unsigned int size;
unsigned int i;
unsigned char * oldInp;
if ( !buffer ) {
throw Exception( __FILE__, __LINE__, "buffer is null");
}
if ( !bufferSize ) {
return 0;
}
oldInp = inp;
buf = (const unsigned char *) buffer;
// adjust so it is a multiple of chunkSize
bufferSize -= bufferSize % chunkSize;
// cut the front of the supplied buffer if it wouldn't fit
if ( bufferSize > this->bufferSize ) {
size = this->bufferSize - 1;
size -= size % chunkSize; // keep it a multiple of chunkSize
buf += bufferSize - size;
} else {
size = bufferSize;
}
// copy the data into the buffer
i = bufferEnd - inp;
if ( (i % chunkSize) != 0 ) {
throw Exception( __FILE__, __LINE__, "copy quantity not aligned", i);
}
if ( size <= i ) {
// the place between inp and bufferEnd is
// big enough to hold the data
memcpy( inp, buf, size);
inp = slidePointer( inp, size);
// adjust outp, lose the data that was overwritten, if any
if ( outp > oldInp && outp <= inp ) {
outp = slidePointer( inp, chunkSize);
}
} else {
// the place between inp and bufferEnd is not
// big enough to hold the data
// writing will take place in two turns, once from
// inp -> bufferEnd, then from buffer ->
memcpy( inp, buf, i);
i = size - i;
if ( (i % chunkSize) != 0 ) {
throw Exception(__FILE__, __LINE__, "copy quantity not aligned", i);
}
memcpy( this->buffer, buf, i);
inp = slidePointer( this->buffer, i);
// adjust outp, lose the data that was overwritten, if any
if ( outp <= oldInp ) {
if ( outp < inp ) {
outp = slidePointer( inp, chunkSize);
}
} else {
outp = slidePointer( inp, chunkSize);
}
}
updatePeak();
if ( ((inp - this->buffer) % chunkSize) != 0 ) {
throw Exception( __FILE__, __LINE__,
"inp not aligned", inp - this->buffer);
}
if ( ((outp - this->buffer) % chunkSize) != 0 ) {
throw Exception( __FILE__, __LINE__,
"outp not aligned", outp - this->buffer);
}
return size;
}
/*------------------------------------------------------------------------------
* Write some data to the sink
* if len == 0, try to flush the buffer
*----------------------------------------------------------------------------*/
unsigned int
BufferedSink :: write ( const void * buf,
unsigned int len ) throw ( Exception )
{
unsigned int length;
unsigned int soFar;
unsigned char * b = (unsigned char *) buf;
if ( !buf ) {
throw Exception( __FILE__, __LINE__, "buf is null");
}
if ( !isOpen() ) {
return 0;
}
if ( !align() ) {
return 0;
}
// make it a multiple of chunkSize
len -= len % chunkSize;
// try to write data from the buffer first, if any
if ( inp != outp ) {
unsigned int size = 0;
unsigned int total = 0;
if ( outp > inp ) {
// valuable data is between outp -> bufferEnd and buffer -> inp
// try to write the outp -> bufferEnd
// the rest will be written in the next if
size = bufferEnd - outp - 1;
size -= size % chunkSize;
soFar = 0;
while ( outp > inp && soFar < size && sink->canWrite( 0, 0) ) {
length = sink->write( outp + soFar, size - soFar);
outp = slidePointer( outp, length);
soFar += length;
}
total += soFar;
}
if ( outp < inp ) {
// valuable data is between outp and inp
// if the previous if wrote all data from the end
// this part will write the rest
size = inp - outp;
soFar = 0;
while ( soFar < size && sink->canWrite( 0, 0) ) {
length = sink->write( outp + soFar, size - soFar);
outp = slidePointer( outp, length);
soFar += length;
}
total += soFar;
}
while ( (outp - buffer) % chunkSize ) {
slidePointer( outp, 1);
}
// calulate the misalignment to chunkSize boundaries
misalignment = (chunkSize - (total % chunkSize)) % chunkSize;
}
if ( !align() ) {
return 0;
}
// the internal buffer is empty, try to write the fresh data
soFar = 0;
if ( inp != outp ) {
while ( soFar < len && sink->canWrite( 0, 0) ) {
soFar += sink->write( b + soFar, len - soFar);
}
}
length = soFar;
// calulate the misalignment to chunkSize boundaries
misalignment = (chunkSize - (length % chunkSize)) % chunkSize;
if ( length < len ) {
// if not all fresh could be written, store the remains
store( b + length, len - length);
}
// tell them we ate everything up to chunkSize alignment
return len;
}
/*------------------------------------------------------------------------------
* Close the sink, lose all pending data
*----------------------------------------------------------------------------*/
void
BufferedSink :: close ( void ) throw ( Exception )
{
if ( !isOpen() ) {
return;
}
flush();
sink->close();
inp = outp = buffer;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.3 2000/11/10 20:16:21 darkeye
first real tests with multiple streaming
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:48 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,412 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : BufferedSink.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef BUFFERED_SINK_H
#define BUFFERED_SINK_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Ref.h"
#include "Reporter.h"
#include "Sink.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A Sink First-In First-Out buffer.
* This buffer can always be written to, it overwrites any
* data contained if needed.
* The class is not thread-safe.
*
* @author $Author$
* @version $Revision$
*/
class BufferedSink : public Sink, public virtual Reporter
{
private:
/**
* The buffer.
*/
unsigned char * buffer;
/**
* The end of the buffer.
*/
unsigned char * bufferEnd;
/**
* The size of the buffer.
*/
unsigned int bufferSize;
/**
* The highest usage of the buffer.
*/
unsigned int peak;
/**
* All data written to this BufferedSink is handled by chuncks
* of this size.
*/
unsigned int chunkSize;
/**
* Number of bytes the underlying stream is misaligned with
* chunkSize. (It needs this many bytes more to be aligned.)
*/
unsigned int misalignment;
/**
* Start of free territory in buffer.
*/
unsigned char * inp;
/**
* Start of sensible data in buffer.
*/
unsigned char * outp;
/**
* The underlying Sink.
*/
Ref<Sink> sink;
/**
* Initialize the object.
*
* @param sink the Sink to attach this BufferedSink to.
* @param size the size of the internal buffer to use.
* @param chunkSize size of chunks to handle data in.
* @exception Exception
*/
void
init ( Sink * sink,
unsigned int size,
unsigned int chunkSize ) throw ( Exception );
/**
* De-initialize the object.
*
* @exception Exception
*/
void
strip ( void ) throw ( Exception );
/**
* Slide a pointer in the internal buffer by offset. If the pointer
* would reach beyond the end of the buffer, it goes wraps around.
*
* @param p the pointer to slide.
* @param offset the amount to slide with.
* @return pointer p + offset, wrapped around if needed.
*/
inline unsigned char *
slidePointer (
unsigned char * p,
unsigned int offset ) throw ()
{
p += offset;
while ( p >= bufferEnd ) {
p -= bufferSize;
}
return p;
}
/**
* Update the peak buffer usage indicator.
*
* @see #peak
*/
inline void
updatePeak ( void ) throw ()
{
unsigned int u;
u = outp <= inp ? inp - outp : (bufferEnd - outp) + (inp - buffer);
if ( peak < u ) {
reportEvent( 4, "BufferedSink, new peak:", peak);
reportEvent( 4, "BufferedSink, remaining:", bufferSize - peak);
peak = u;
}
}
/**
* If the underlying Sink is misaligned on chunkSize, write as
* many 0s as needed to get it aligned.
*
* @see #misalignment
* @see #chunkSize
*/
inline bool
align ( void )
{
char b[] = { 0 };
while ( misalignment ) {
if ( sink->canWrite( 0, 0) ) {
unsigned int ret;
if ( !(ret = sink->write( b, 1)) ) {
return false;
}
--misalignment;
} else {
return false;
}
}
return true;
}
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
BufferedSink ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Get the size of the buffer.
*
* @return the size of the buffer.
*/
inline unsigned int
getSize ( void ) const throw ()
{
return bufferSize;
}
/**
* Store data in the internal buffer. If there is not enough space,
* discard all in the buffer and the beginning of the supplied
* buffer if needed.
*
* @param buffer the data to store.
* @param bufferSize the amount of data to store in bytes.
* @return number of bytes really stored.
*/
unsigned int
store ( const void * buffer,
unsigned int bufferSize ) throw ( Exception );
public:
/**
* Constructor by an underlying Sink, buffer size and chunk size.
*
* @param sink the Sink to attach this BufferSink to.
* @param size the size of the buffer to use for buffering.
* @param chunkSize hanlde all data in write() as chunks of
* chunkSize
* @exception Exception
*/
inline
BufferedSink ( Sink * sink,
unsigned int size,
unsigned int chunkSize = 1 ) throw ( Exception )
{
init( sink, size, chunkSize);
}
/**
* Copy constructor.
*
* @param buffer the object to copy.
* @exception Exception
*/
BufferedSink ( const BufferedSink & buffer ) throw ( Exception );
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~BufferedSink ( void ) throw ( Exception )
{
strip();
}
/**
* Assignment operator.
*
* @param bs the object to assign to this one.
* @return a reference to this object.
* @exception Exception
*/
virtual BufferedSink &
operator= ( const BufferedSink & bs ) throw ( Exception );
/**
* Get the peak usage of the internal buffer.
*
* @return the peak usage of the internal buffer.
*/
inline unsigned int
getPeak ( void ) const throw ()
{
return peak;
}
/**
* Open the BufferedSink. Opens the underlying Sink.
*
* @return true if opening was successful, false otherwise.
* @exception Exception
*/
inline virtual bool
open ( void ) throw ( Exception )
{
return sink->open();
}
/**
* Check if a BufferedSink is open.
*
* @return true if the BufferedSink is open, false otherwise.
*/
inline virtual bool
isOpen ( void ) const throw ()
{
return sink->isOpen();
}
/**
* Check if the BufferedSink is ready to accept data.
* Always returns true immediately.
*
* @param sec the maximum seconds to block.
* @param usec micro seconds to block after the full seconds.
* @return true
* @exception Exception
*/
inline virtual bool
canWrite ( unsigned int sec,
unsigned int usec ) throw ( Exception )
{
return true;
}
/**
* Write data to the BufferedSink.
* Always reads the maximum number of chunkSize chunks buf
* holds. If the data can not be written to the underlying
* stream, it is buffered. If the buffer overflows, the oldest
* data is discarded.
*
* @param buf the data to write.
* @param len number of bytes to write from buf.
* @return the number of bytes written (may be less than len).
* @exception Exception
*/
virtual unsigned int
write ( const void * buf,
unsigned int len ) throw ( Exception );
/**
* Flush all data that was written to the BufferedSink to the
* underlying Sink.
*
* @exception Exception
*/
inline virtual void
flush ( void ) throw ( Exception )
{
unsigned char b[0];
write( b, 0);
}
/**
* Close the BufferedSink. Closes the underlying Sink.
*
* @exception Exception
*/
virtual void
close ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* BUFFERED_SINK_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.5 2000/11/15 18:08:42 darkeye
added multiple verbosity-level event reporting and verbosity command
line option
Revision 1.4 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.3 2000/11/10 20:16:21 darkeye
first real tests with multiple streaming
Revision 1.2 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.1.1.1 2000/11/05 10:05:48 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,150 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : CastSink.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include "Util.h"
#include "Exception.h"
#include "CastSink.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
CastSink :: init ( TcpSocket * socket,
const char * password,
const char * mountPoint,
const char * remoteDumpFile,
const char * name,
const char * description,
const char * url,
const char * genre,
unsigned int bitRate,
bool isPublic,
unsigned int bufferDuration )
throw ( Exception )
{
this->socket = socket;
this->password = Util::strDup( password);
this->mountPoint = Util::strDup( mountPoint);
this->remoteDumpFile = remoteDumpFile ? Util::strDup( remoteDumpFile) : 0;
this->name = Util::strDup( name);
this->description = Util::strDup( description);
this->url = Util::strDup( url);
this->genre = Util::strDup( genre);
this->bitRate = bitRate;
this->isPublic = isPublic;
this->bufferDuration = bufferDuration;
bufferedSink = new BufferedSink( socket,
(bitRate * 1024 / 8) * bufferDuration);
}
/*------------------------------------------------------------------------------
* De-initialize the object
*----------------------------------------------------------------------------*/
void
CastSink :: strip ( void ) throw ( Exception )
{
if ( isOpen() ) {
close();
}
delete[] password;
delete[] mountPoint;
if ( remoteDumpFile ) {
delete[] remoteDumpFile;
}
delete[] name;
delete[] description;
delete[] url;
delete[] genre;
}
/*------------------------------------------------------------------------------
* Open the connection
*----------------------------------------------------------------------------*/
bool
CastSink :: open ( void ) throw ( Exception )
{
if ( isOpen() ) {
return false;
}
if ( !bufferedSink->open() ) {
return false;
}
if ( !sendLogin() ) {
close();
return false;
}
return true;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/10 20:14:11 darkeye
added support for remote dump file
Revision 1.1.1.1 2000/11/05 10:05:48 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,533 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : CastSink.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef CAST_SINK_H
#define CAST_SINK_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Ref.h"
#include "Sink.h"
#include "TcpSocket.h"
#include "BufferedSink.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Data output to a ShoutCast / IceCast / etc. server
* This is an abstract class. A subclass should override at least
* the sendLogin() function.
*
* @author $Author$
* @version $Revision$
*/
class CastSink : public Sink
{
private:
/**
* The socket connection to the server.
*/
Ref<TcpSocket> socket;
/**
* The BufferedSink encapsulating the socket connection to the server.
*/
Ref<BufferedSink> bufferedSink;
/**
* Duration of the BufferedSink buffer in seconds.
*/
unsigned int bufferDuration;
/**
* Password to the server.
*/
char * password;
/**
* Mount point of the stream on the server.
*/
char * mountPoint;
/**
* Remote dump file if any.
*/
char * remoteDumpFile;
/**
* Name of the stream.
*/
char * name;
/**
* Description of the stream.
*/
char * description;
/**
* URL associated with the stream.
*/
char * url;
/**
* Genre of the stream.
*/
char * genre;
/**
* Bitrate of the stream (e.g. mp3 bitrate).
*/
unsigned int bitRate;
/**
* Is the stream public?
*/
bool isPublic;
/**
* Initalize the object.
*
* @param socket socket connection to the server.
* @param password password to the server.
* @param mountPoint mount point of the stream on the server.
* @param remoteDumpFile remote dump file (may be NULL).
* @param name name of the stream.
* @param description description of the stream.
* @param url URL associated with the stream.
* @param genre genre of the stream.
* @param bitRate bitrate of the stream (e.g. mp3 bitrate).
* @param isPublic is the stream public?
* @param bufferDuration duration of the BufferedSink buffer
* in seconds.
* @exception Exception
*/
void
init ( TcpSocket * socket,
const char * password,
const char * mountPoint,
const char * remoteDumpFile,
const char * name,
const char * description,
const char * url,
const char * genre,
unsigned int bitRate,
bool isPublic,
unsigned int bufferDuration )
throw ( Exception );
/**
* De-initalize the object.
*
* @exception Exception
*/
void
strip ( void ) throw ( Exception );
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
CastSink ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Log in to the server using the socket avialable.
*
* @return true if login was successful, false otherwise.
* @exception Exception
*/
virtual bool
sendLogin ( void ) throw ( Exception ) = 0;
/**
* Get the Sink underneath this CastSink.
*
* @return pointer to the Sink underneath this CastSink.
*/
inline Sink *
getSink ( void ) const throw ()
{
return bufferedSink.get();
}
/**
* Get the TcpSocket underneath this CastSink.
*
* @return pointer to the TcpSocket underneath this CastSink.
*/
inline TcpSocket *
getSocket ( void ) const throw ()
{
return socket.get();
}
public:
/**
* Constructor.
*
* @param socket socket connection to the server.
* @param password password to the server.
* @param mountPoint mount point of the stream on the server.
* @param remoteDumpFile remote dump file (may be NULL).
* @param name name of the stream.
* @param description description of the stream.
* @param url URL associated with the stream.
* @param genre genre of the stream.
* @param bitRate bitrate of the stream (e.g. mp3 bitrate).
* @param isPublic is the stream public?
* @param bufferDuration duration of the BufferedSink buffer
* in seconds.
* @exception Exception
*/
inline
CastSink ( TcpSocket * socket,
const char * password,
const char * mountPoint,
const char * remoteDumpFile,
const char * name,
const char * description,
const char * url,
const char * genre,
unsigned int bitRate,
bool isPublic,
unsigned int bufferDuration = 10 )
throw ( Exception )
{
init( socket,
password,
mountPoint,
remoteDumpFile,
name,
description,
url,
genre,
bitRate,
isPublic,
bufferDuration );
}
/**
* Copy constructor.
*
* @param cs the CastSink to copy.
*/
inline
CastSink( const CastSink & cs ) throw ( Exception )
: Sink( cs )
{
init( cs.socket.get(),
cs.password,
cs.mountPoint,
cs.remoteDumpFile,
cs.name,
cs.description,
cs.url,
cs.genre,
cs.bitRate,
cs.isPublic,
cs.bufferDuration );
}
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~CastSink( void ) throw ( Exception )
{
strip();
}
/**
* Assignment operator.
*
* @param cs the CastSink to assign this to.
* @return a reference to this CastSink.
* @exception Exception
*/
inline virtual CastSink &
operator= ( const CastSink & cs ) throw ( Exception )
{
if ( this != &cs ) {
strip();
Sink::operator=( cs );
init( cs.socket.get(),
cs.password,
cs.mountPoint,
cs.remoteDumpFile,
cs.name,
cs.description,
cs.url,
cs.genre,
cs.bitRate,
cs.isPublic,
cs.bufferDuration );
}
return *this;
}
/**
* Open the CastSink.
* Logs in to the server.
*
* @return true if opening was successfull, false otherwise.
* @exception Exception
*/
virtual bool
open ( void ) throw ( Exception );
/**
* Check if the CastSink is open.
*
* @return true if the CastSink is open, false otherwise.
*/
inline virtual bool
isOpen ( void ) const throw ()
{
return bufferedSink->isOpen();
}
/**
* Check if the CastSink is ready to accept data.
* Blocks until the specified time for data to be available.
*
* @param sec the maximum seconds to block.
* @param usec micro seconds to block after the full seconds.
* @return true if the CastSink is ready to accept data,
* false otherwise.
* @exception Exception
*/
inline virtual bool
canWrite ( unsigned int sec,
unsigned int usec ) throw ( Exception )
{
return getSink()->canWrite( sec, usec);
}
/**
* Write data to the CastSink.
*
* @param buf the data to write.
* @param len number of bytes to write from buf.
* @return the number of bytes written (may be less than len).
* @exception Exception
*/
inline virtual unsigned int
write ( const void * buf,
unsigned int len ) throw ( Exception )
{
return getSink()->write( buf, len);
}
/**
* Flush all data that was written to the CastSink to the server.
*
* @exception Exception
*/
inline virtual void
flush ( void ) throw ( Exception )
{
return getSink()->flush();
}
/**
* Close the CastSink.
*
* @exception Exception
*/
inline virtual void
close ( void ) throw ( Exception )
{
return getSink()->close();
}
/**
* Get the password to the server.
*
* @return the password to the server.
*/
inline const char *
getPassword ( void ) const throw ()
{
return password;
}
/**
* Get the mount point of the stream on the server.
*
* @return the mount point of the stream on the server.
*/
inline const char *
getMountPoint ( void ) const throw ()
{
return mountPoint;
}
/**
* Get the remote dump file if any.
*
* @return the remote dump file. May be NULL.
*/
inline const char *
getRemoteDumpFile ( void ) const throw ()
{
return remoteDumpFile;
}
/**
* Get the name of the stream.
*
* @return the name of the stream.
*/
inline const char *
getName ( void ) const throw ()
{
return name;
}
/**
* Get the description of the stream.
*
* @return the description of the stream.
*/
inline const char *
getDescription ( void ) const throw ()
{
return description;
}
/**
* Get the URL associated with the stream.
*
* @return the URL associated with the stream.
*/
inline const char *
getUrl ( void ) const throw ()
{
return url;
}
/**
* Get the genre of the stream.
*
* @return the genre of the stream.
*/
inline const char *
getGenre ( void ) const throw ()
{
return genre;
}
/**
* Get the bitrate of the stream (e.g. mp3 bitrate).
*
* @return the bitrate of the stream (e.g. mp3 bitrate).
*/
inline unsigned int
getBitRate ( void ) const throw ()
{
return bitRate;
}
/**
* Get wether this stream is public.
*
* @return true if the stream is public, false otherwise.
*/
inline bool
getIsPublic ( void ) const throw ()
{
return isPublic;
}
/**
* Get the duration of the BufferedSink buffer in seconds.
*
* @return the the duration of the BufferedSink buffer in seconds.
*/
inline unsigned int
getBufferDuration ( void ) const throw ()
{
return bufferDuration;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* CAST_SINK_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.3 2000/11/10 20:14:11 darkeye
added support for remote dump file
Revision 1.2 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.1.1.1 2000/11/05 10:05:48 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,177 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell Config
File : Config.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <iterator>
#include <iostream.h>
#include "Config.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/*------------------------------------------------------------------------------
* Max line size
*----------------------------------------------------------------------------*/
#define LINE_SIZE 256
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Get a value for a key
*----------------------------------------------------------------------------*/
const ConfigSection *
Config :: get ( const char * key ) const throw ( Exception )
{
if ( !key ) {
throw Exception( __FILE__, __LINE__, "no key");
}
TableType::const_iterator it = table.find( key);
if ( it == table.end() ) {
return 0;
}
return &(it->second);
}
/*------------------------------------------------------------------------------
* Add a configuration line
*----------------------------------------------------------------------------*/
bool
Config :: addLine ( const char * line ) throw ( Exception )
{
if ( !line ) {
throw Exception( __FILE__, __LINE__, "no line");
}
string::size_type ix;
string str( line);
/* delete everything after the first # */
if ( (ix = str.find( '#')) != str.npos ) {
str.erase( ix);
}
/* eat up all white space from the front */
if ( (ix = str.find_first_not_of( ' ')) != str.npos ) {
str.erase( 0, ix);
}
/* eat up all white space from the end */
if ( (ix = str.find_last_not_of( ' ')) != str.npos ) {
str.erase( ix + 1);
}
if ( str[0] == '[' && str[str.size()-1] == ']' ) {
// a new section starts
string section( str, 1, str.size()-2);
ConfigSection cSection;
pair<const string, ConfigSection> element( section, cSection);
pair<TableType::iterator, bool> res;
res = table.insert( element);
currentSection = section;
return res.second;
} else {
// it's a line for the current section
TableType::iterator it = table.find( currentSection);
if ( it == table.end() ) {
throw Exception( __FILE__, __LINE__, "no current section");
}
return it->second.addLine( line);
}
}
/*------------------------------------------------------------------------------
* Add a configuration line
*----------------------------------------------------------------------------*/
void
Config :: read ( istream & is ) throw ( Exception )
{
char line[LINE_SIZE];
unsigned int num;
for ( num = 0; !is.fail() && !is.eof(); ++num ) {
is.getline( line, LINE_SIZE);
if ( is.eof() ) {
break;
} else if ( is.fail() ) {
throw Exception( __FILE__, __LINE__, "line too long", num);
}
addLine( line);
}
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.2 2000/11/13 18:46:50 darkeye
added kdoc-style documentation comments
Revision 1.1 2000/11/08 17:29:50 darkeye
added configuration file reader
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:49 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,230 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell Config
File : Config.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef CONFIG_H
#define CONFIG_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include <hash_map>
#include <string>
#include <iostream.h>
#include "Referable.h"
#include "ConfigSection.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A configuration file representation. The file is of the syntax:
*
* <pre>
* [section1]
* # this is a whole line comment
* key = value
* an ugly key name = long value # this end is a comment too
*
* [section2]
* # this is a whole line comment in section 2
* key = value
* an ugly key name = long value # this end is a comment too
* </pre>
*
* also empty lines are ignored and all white space is removed
* from the front and end of keys / values
*
* Knwon problem: you can't use '#' in any part of a key / value pair
*
* @author $Author$
* @version $Revision$
*/
class Config : public virtual Referable
{
private:
/**
* Type declaration of the hash table type.
*/
typedef hash_map<string, ConfigSection> TableType;
/**
* Hash table holding the configuration sections.
*
* @see ConfigSection
*/
TableType table;
/**
* Hash table holding the configuration sections.
*
* @see ConfigSection
*/
string currentSection;
protected:
public:
/**
* Default constructor.
*
* @exception Exception
*/
inline
Config ( void ) throw ( Exception )
{
}
/**
* Constructor based on an input stream.
*
* @param is configuration will be read from this input stream
* until end of stream is reached.
* @exception Exception
*/
inline
Config ( istream & is ) throw ( Exception )
{
read( is );
}
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~Config ( void ) throw ( Exception )
{
}
/* TODO
inline
Config ( const Config & di ) throw ( Exception )
{
}
inline Config &
operator= ( const Config * di ) throw ( Exception )
{
}
*/
/**
* Delete the configuration information stored in the object.
* Resets the object to a clean state.
*
* @exception Exception
*/
inline virtual void
reset ( void ) throw ( Exception )
{
table.clear();
currentSection = "";
}
/**
* Read a line of confiugration information.
*
* @param line the line to read.
* @return true if the line was correct, false otherwise.
* @exception Exception
*/
virtual bool
addLine ( const char * line ) throw ( Exception );
/**
* Read a line of confiugration information.
*
* @param line the line to read.
* @return true if the line was correct, false otherwise.
* @exception Exception
*/
virtual void
read ( istream & is ) throw ( Exception );
/**
* Get a ConfigSection by name.
*
* @param key the name of the ConfigSection
* @return the ConfigSection requested, or NULL if it doesn't exists.
* @exception Exception
*/
virtual const ConfigSection *
get ( const char * key ) const throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* CONFIG_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/13 18:46:50 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/09 22:07:19 darkeye
added constructor with istream
Revision 1.1 2000/11/08 17:29:50 darkeye
added configuration file reader
Revision 1.1.1.1 2000/11/05 10:05:50 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,188 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell ConfigSection
File : ConfigSection.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <iterator>
#include <iostream.h>
#include "ConfigSection.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Add a key / value pair
*----------------------------------------------------------------------------*/
bool
ConfigSection :: add ( const char * key,
const char * value ) throw ( Exception )
{
if ( !key || !value ) {
throw Exception( __FILE__, __LINE__, "no key or value");
}
pair<const string, string> element( key, value);
pair<TableType::iterator, bool> res;
res = table.insert( element);
return res.second;
}
/*------------------------------------------------------------------------------
* Get a value for a key
*----------------------------------------------------------------------------*/
const char *
ConfigSection :: get ( const char * key ) const throw ( Exception )
{
if ( !key ) {
throw Exception( __FILE__, __LINE__, "no key");
}
TableType::const_iterator it = table.find( key);
if ( it == table.end() ) {
return 0;
}
return it->second.c_str();
}
/*------------------------------------------------------------------------------
* Get a value for a key, in the key does not exist, throw an exception
*----------------------------------------------------------------------------*/
const char *
ConfigSection :: getForSure ( const char * key,
const char * message1 = 0,
const char * message2 = 0,
int code = 0 ) const
throw ( Exception )
{
const char * value;
if ( !(value = get( key)) ) {
throw Exception( __FILE__, __LINE__, key, message1, message2, code);
}
return value;
}
/*------------------------------------------------------------------------------
* Add a configuration line
*----------------------------------------------------------------------------*/
bool
ConfigSection :: addLine ( const char * line ) throw ( Exception )
{
if ( !line ) {
throw Exception( __FILE__, __LINE__, "no line");
}
string::size_type ix;
string str( line);
/* delete everything after the first # */
if ( (ix = str.find( '#')) != str.npos ) {
str.erase( ix);
}
/* eat up all white space from the front */
if ( (ix = str.find_first_not_of( ' ')) != str.npos ) {
str.erase( 0, ix);
}
/* eat up all white space from the end */
if ( (ix = str.find_last_not_of( ' ')) != str.npos ) {
str.erase( ix + 1);
}
/* find the '=' delimiter between key and value */
if ( (ix = str.find( '=')) == str.npos ) {
return false;
}
string key( str, 0, ix);
string value( str, ix + 1);
/* eat up all white space from the front of value */
if ( (ix = value.find_first_not_of( ' ')) != value.npos ) {
value.erase( 0, ix);
}
/* eat up all white space from the end of key */
if ( (ix = key.find_last_not_of( ' ')) != key.npos ) {
key.erase( ix + 1);
}
/* now add the new key / value pair */
return add( key.c_str(), value.c_str());
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/13 18:46:50 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/09 22:08:17 darkeye
added function getForSure
Revision 1.1 2000/11/08 17:29:50 darkeye
added configuration file reader
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:49 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,205 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell ConfigSection
File : ConfigSection.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef CONFIG_SECTION_H
#define CONFIG_SECTION_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include <hash_map>
#include <string>
#include "Referable.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A configuration file representation. The file is of the syntax:
*
* <pre>
* # this is a whole line comment
* key = value
* an ugly key name = long value # this end is a comment too
* </pre>
*
* also empty lines are ignored and all white space is removed
* from the front and end of keys / values
*
* Knwon problem: you can't use '#' in any part of a key / value pair
*
* @author $Author$
* @version $Revision$
*/
class ConfigSection : public virtual Referable
{
private:
/**
* Type of the hash table used in this class.
*/
typedef hash_map<string, string> TableType;
/**
* Hash table holding the configuration information.
*/
TableType table;
protected:
public:
/**
* Default constructor.
*
* @exception Exception
*/
inline
ConfigSection ( void ) throw ( Exception )
{
}
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~ConfigSection ( void ) throw ( Exception )
{
}
/* TODO
inline
ConfigSection ( const ConfigSection & di ) throw ( Exception )
{
}
inline ConfigSection &
operator= ( const ConfigSection * di ) throw ( Exception )
{
}
*/
/**
* Add a key / value pair to the configuration information.
*
* @param key the key to add the value by
* @param value the value to add for the key
* @return true if adding was successful, false otherwise
* @exception Exception
*/
virtual bool
add ( const char * key,
const char * value ) throw ( Exception );
/**
* Get a value for a key.
*
* @param key the key to get the value for
* @return the value for the key, or NULL if the key doesn't exist.
* @exception Exception
*/
virtual const char *
get ( const char * key ) const throw ( Exception );
/**
* Get a value for a key, or throw an Exception.
*
* @param key the key to get the value for
* @param message1 message part 1 of the Exception to be thrown.
* @param message2 message part 2 of the Exception to be thrown.
* @param code error code of the Exception to be thrown.
* @return the value for the key. The return value is never NULL.
* @exception Exception
*/
virtual const char *
getForSure ( const char * key,
const char * message1 = 0,
const char * message2 = 0,
int code = 0 ) const
throw ( Exception );
/**
* Add a line of configuration information.
*
* @param line the line to add.
* @return true if a new key was added, false otherwise.
* @exception Exception
*/
virtual bool
addLine ( const char * line ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* CONFIG_SECTION_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/13 18:46:50 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/09 22:08:17 darkeye
added function getForSure
Revision 1.1 2000/11/08 17:29:50 darkeye
added configuration file reader
Revision 1.1.1.1 2000/11/05 10:05:50 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,351 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Connector.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include "Exception.h"
#include "Connector.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
Connector :: init ( Source * source ) throw ( Exception )
{
this->source = source;
this->sinks = 0;
this->numSinks = 0;
}
/*------------------------------------------------------------------------------
* De-initialize the object
*----------------------------------------------------------------------------*/
void
Connector :: strip ( void ) throw ( Exception )
{
source = 0;
if ( sinks ) {
unsigned int u;
for ( u = 0; u < numSinks; ++u ) {
sinks[u] = 0;
}
delete[] sinks;
}
}
/*------------------------------------------------------------------------------
* Constructor
*----------------------------------------------------------------------------*/
Connector :: Connector ( const Connector & connector ) throw ( Exception )
{
unsigned int u;
init( connector.source.get());
for ( u = 0; u < connector.numSinks; ++u ) {
attach( connector.sinks[u].get() );
}
}
/*------------------------------------------------------------------------------
* Assignment operator
*----------------------------------------------------------------------------*/
Connector &
Connector :: operator= ( const Connector & connector ) throw ( Exception )
{
if ( this != &connector ) {
unsigned int u;
/* first free everything */
strip();
/* then fill in */
init( connector.source.get() );
for ( u = 0; u < connector.numSinks; ++u ) {
attach( connector.sinks[u].get() );
}
}
return *this;
}
/*------------------------------------------------------------------------------
* Attach a sink to the connector
*----------------------------------------------------------------------------*/
void
Connector :: attach ( Sink * sink ) throw ( Exception )
{
if ( !sinks ) {
numSinks = 1;
sinks = new Ref<Sink>[1];
sinks[0] = sink;
} else {
unsigned int u;
Ref<Sink> * s = new Ref<Sink>[numSinks + 1];
for ( u = 0; u < numSinks; ++u ) {
s[u] = sinks[u].get();
}
s[numSinks] = sink;
delete[] sinks;
sinks = s;
++numSinks;
}
}
/*------------------------------------------------------------------------------
* Detach a sink to the connector
*----------------------------------------------------------------------------*/
bool
Connector :: detach ( Sink * sink ) throw ( Exception )
{
if ( numSinks == 0 ) {
return false;
} else if ( numSinks == 1 ) {
sinks[0] = 0;
delete[] sinks;
sinks = 0;
return true;
} else {
unsigned int u;
unsigned int v;
unsigned int ix;
Ref<Sink> * s;
ix = numSinks;
for ( u = 0; u < numSinks; ++u ) {
if ( sinks[u].get() == sink ) {
ix = u;
break;
}
}
if ( ix == numSinks ) {
return false;
}
s = new Ref<Sink>[numSinks - 1];
for ( u = 0, v = 0; u < numSinks; ++u ) {
if ( u != ix ) {
s[v++] = sinks[u];
}
}
sinks[ix] = 0;
delete[] sinks;
sinks = s;
--numSinks;
return true;
}
}
/*------------------------------------------------------------------------------
* Open the source and all the sinks if needed
*----------------------------------------------------------------------------*/
bool
Connector :: open ( void ) throw ( Exception )
{
unsigned int u;
if ( !source->isOpen() ) {
if ( !source->open() ) {
return false;
}
}
for ( u = 0; u < numSinks; ++u ) {
if ( !sinks[u]->isOpen() ) {
if ( !sinks[u]->open() ) {
break;
}
}
}
/* if not all could be opened, close those that were */
if ( u < numSinks ) {
unsigned int v;
for ( v = 0; v < u; ++v ) {
sinks[v]->close();
}
source->close();
return false;
}
return true;
}
/*------------------------------------------------------------------------------
* Transfer some data from the source to the sink
*----------------------------------------------------------------------------*/
unsigned int
Connector :: transfer ( unsigned long bytes,
unsigned int bufSize,
unsigned int sec,
unsigned int usec ) throw ( Exception )
{
unsigned int u;
unsigned long b;
unsigned char buf[bufSize];
if ( numSinks == 0 ) {
return 0;
}
if ( bufSize == 0 ) {
return 0;
}
reportEvent( 6, "Connector :: tranfer, bytes", bytes);
for ( b = 0; b < bytes; ) {
unsigned int d = 0;
unsigned int e = 0;
if ( source->canRead( sec, usec) ) {
d = source->read( buf, bufSize);
/* check for EOF */
if ( d == 0 ) {
reportEvent( 3, "Connector :: transfer, EOF");
break;
}
for ( u = 0; u < numSinks; ++u ) {
if ( sinks[u]->canWrite( sec, usec) ) {
e = sinks[u]->write( buf, d);
} else {
sinks[u]->close();
detach( sinks[u].get() );
/* with the call to detach, numSinks gets 1 lower,
* and the next sink comes to sinks[u] */
--u;
reportEvent( 5,
"Connector :: transfer, sink removed, remaining", u);
if ( numSinks == 0 ) {
reportEvent( 4, "Connector :: transfer, no more sinks");
break;
}
}
}
b += d;
} else {
reportEvent( 3, "Connector :: transfer, can't read");
break;
}
}
return b;
}
/*------------------------------------------------------------------------------
* Open the source and all the sinks if needed
*----------------------------------------------------------------------------*/
void
Connector :: close ( void ) throw ( Exception )
{
unsigned int u;
source->close();
for ( u = 0; u < numSinks; ++u ) {
sinks[u]->close();
}
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/15 18:37:37 darkeye
changed the transferable number of bytes to unsigned long
Revision 1.3 2000/11/15 18:08:43 darkeye
added multiple verbosity-level event reporting and verbosity command
line option
Revision 1.2 2000/11/13 18:46:50 darkeye
added kdoc-style documentation comments
Revision 1.1.1.1 2000/11/05 10:05:49 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,276 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Connector.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef CONNECTOR_H
#define CONNECTOR_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Referable.h"
#include "Ref.h"
#include "Reporter.h"
#include "Source.h"
#include "Sink.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Connects a source to one or more sinks.
*
* @author $Author$
* @version $Revision$
*/
class Connector : public virtual Referable, public virtual Reporter
{
private:
/**
* The source to read from.
*/
Ref<Source> source;
/**
* The sinks to connect the source to.
*/
Ref<Sink> * sinks;
/**
* Total number of sinks.
*/
unsigned int numSinks;
/**
* Initialize the object.
*
* @param source the source to read from.
* @exception Exception
*/
void
init ( Source * source ) throw ( Exception );
/**
* De-initialize the object.
*
* @exception Exception
*/
void
strip ( void ) throw ( Exception );
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
Connector ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
public:
/**
* Constructor based on a Source.
*
* @param source the source to connect to the sinks.
* @exception Exception
*/
inline
Connector ( Source * source ) throw ( Exception )
{
init( source);
}
/**
* Constructor based on a Source and a Sink.
*
* @param source the source to connect to the sinks.
* @param sink a sink to connect to the source.
* @exception Exception
*/
inline
Connector ( Source * source,
Sink * sink ) throw ( Exception )
{
init( source);
attach( sink);
}
/**
* Copy constructor.
*
* @param connector the object to copy.
* @exception Exception
*/
Connector ( const Connector & connector ) throw ( Exception );
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~Connector( void ) throw ( Exception )
{
strip();
}
/**
* Assignment operator.
*
* @param connector the object to assign to this one.
* @return a reference to this object.
* @exception Exception
*/
virtual Connector &
operator= ( const Connector & connector ) throw ( Exception );
/**
* Get the number of Sinks in the Connector.
*
* @return the number of Sinks in the Connector.
* @exception Exception
*/
inline unsigned int
getNumSinks ( void ) const throw ()
{
return numSinks;
}
/**
* Attach a Sink to the Source of this Connector.
*
* @param sink the Sink to attach.
* @exception Exception
*/
void
attach ( Sink * sink ) throw ( Exception );
/**
* Detach an already attached Sink from the Source of this Connector.
*
* @param sink the Sink to detach.
* @return true if the detachment was successful, false otherwise.
* @exception Exception
*/
bool
detach ( Sink * sink ) throw ( Exception );
/**
* Open the connector. Opens the Source and the Sinks if necessary.
*
* @return true if opening was successful, false otherwise.
* @exception Exception
*/
bool
open ( void ) throw ( Exception );
/**
* Transfer a given amount of data from the Source to all the
* Sinks attached.
* If an attached Sink closes or encounteres an error during the
* process, it is detached and the function carries on with the
* rest of the Sinks. If no Sinks remain, or an error is encountered
* with the Source, the function returns prematurely.
*
* @param bytes the amount of data to transfer, in bytes
* @param bufSize the size of the buffer to use for transfering.
* This amount of data is read from the Source and
* written to each Sink on each turn.
* @param sec the number of seconds to wait for the Source to have
* data available in each turn, and the number of seconds
* to wait for the Sinks to accept data.
* @param usec the number of micros seconds to wait for the Source to
* have data available in each turn, and the number of
* micro seconds to wait for the Sinks to accept data.
* @return the number of bytes read from the Source.
* @exception Exception
*/
unsigned int
transfer ( unsigned long bytes,
unsigned int bufSize,
unsigned int sec,
unsigned int usec ) throw ( Exception );
/**
* Close the Connector. The Source and all Sinks are closed.
*
* @exception Exception
*/
void
close ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* CONNECTOR_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/15 18:37:37 darkeye
changed the transferable number of bytes to unsigned long
Revision 1.3 2000/11/15 18:08:43 darkeye
added multiple verbosity-level event reporting and verbosity command
line option
Revision 1.2 2000/11/13 18:46:50 darkeye
added kdoc-style documentation comments
Revision 1.1.1.1 2000/11/05 10:05:49 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,526 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : DarkIce.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#else
#error need stdlib.h
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistd.h
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#else
#error need sys/wait.h
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#else
#error need errno.h
#endif
#ifdef HAVE_SCHED_H
#include <sched.h>
#else
#error need sched.h
#endif
#include <hash_map>
#include <string>
#include "Util.h"
#include "DarkIce.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/*------------------------------------------------------------------------------
* Make sure wait-related stuff is what we expect
*----------------------------------------------------------------------------*/
#ifndef WEXITSTATUS
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
#endif
#ifndef WIFEXITED
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
#endif
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
DarkIce :: init ( const Config & config ) throw ( Exception )
{
unsigned int bufferSecs;
const ConfigSection * cs;
const char * str;
unsigned int sampleRate;
unsigned int bitsPerSample;
unsigned int channel;
const char * device;
unsigned int u;
// the [general] section
if ( !(cs = config.get( "general")) ) {
throw Exception( __FILE__, __LINE__, "no section [general] in config");
}
str = cs->getForSure( "duration", " missing in section [general]");
duration = Util::strToL( str);
str = cs->getForSure( "bufferSecs", " missing in section [general]");
bufferSecs = Util::strToL( str);
// the [input] section
if ( !(cs = config.get( "input")) ) {
throw Exception( __FILE__, __LINE__, "no section [general] in config");
}
str = cs->getForSure( "sampleRate", " missing in section [input]");
sampleRate = Util::strToL( str);
str = cs->getForSure( "bitsPerSample", " missing in section [input]");
bitsPerSample = Util::strToL( str);
str = cs->getForSure( "channel", " missing in section [input]");
channel = Util::strToL( str);
device = cs->getForSure( "device", " missing in section [input]");
dsp = new OssDspSource( device,
sampleRate,
bitsPerSample,
channel );
encConnector = new Connector( dsp.get());
// look for lame encoder output streams, sections [lame0], [lame1], etc.
char lame[] = "lame ";
size_t lameLen = Util::strLen( lame);
char * pipeOutExt = ".out";
size_t pipeOutExtLen = Util::strLen( pipeOutExt);
char * pipeInExt = ".in";
size_t pipeInExtLen = Util::strLen( pipeInExt);
for ( u = 0; u < maxOutput; ++u ) {
// ugly hack to change the section name to "lame0", "lame1", etc.
lame[lameLen-1] = '0' + u;
if ( !(cs = config.get( lame)) ) {
break;
}
const char * encoder = 0;
unsigned int bitrate = 0;
const char * server = 0;
unsigned int port = 0;
const char * password = 0;
const char * mountPoint = 0;
const char * remoteDumpFile = 0;
const char * name = 0;
const char * description = 0;
const char * url = 0;
const char * genre = 0;
bool isPublic = false;
unsigned int lowpass = 0;
unsigned int highpass = 0;
encoder = cs->getForSure( "encoder", " missing in section ", lame);
str = cs->getForSure( "bitrate", " missing in section ", lame);
bitrate = Util::strToL( str);
server = cs->getForSure( "server", " missing in section ", lame);
str = cs->getForSure( "port", " missing in section ", lame);
port = Util::strToL( str);
password = cs->getForSure( "password", " missing in section ", lame);
mountPoint = cs->getForSure( "mountPoint"," missing in section ",lame);
remoteDumpFile = cs->get( "remoteDumpFile");
name = cs->getForSure( "name", " missing in section ", lame);
description = cs->getForSure("description"," missing in section ",lame);
url = cs->getForSure( "url", " missing in section ", lame);
genre = cs->getForSure( "genre", " missing in section ", lame);
str = cs->getForSure( "public", " missing in section ", lame);
isPublic = Util::strEq( str, "yes") ? true : false;
str = cs->get( "lowpass");
lowpass = str ? Util::strToL( str) : 0;
str = cs->get( "highpass");
highpass = str ? Util::strToL( str) : 0;
// generate the pipe names
char pipeOutName[lameLen + pipeOutExtLen + 1];
char pipeInName[lameLen + pipeInExtLen + 1];
Util::strCpy( pipeOutName, lame);
Util::strCat( pipeOutName, pipeOutExt);
Util::strCpy( pipeInName, lame);
Util::strCat( pipeInName, pipeInExt);
// go on and create the things
outputs[u].pid = 0;
// the pipes
outputs[u].encOutPipe = new PipeSource( pipeOutName);
outputs[u].encInPipe = new PipeSink( pipeInName);
if ( !outputs[u].encOutPipe->exists() ) {
if ( !outputs[u].encOutPipe->create() ) {
throw Exception( __FILE__, __LINE__,
"can't create out pipe ",
pipeOutName );
}
}
if ( !outputs[u].encInPipe->exists() ) {
if ( !outputs[u].encInPipe->create() ) {
throw Exception( __FILE__, __LINE__,
"can't create in pipe",
pipeInName );
}
}
// encoder related stuff
unsigned int bs = bufferSecs *
(bitsPerSample / 8) * channel * sampleRate;
outputs[u].encIn = new BufferedSink( outputs[u].encInPipe.get(),
bs,
(bitsPerSample / 8) * channel );
reportEvent( 6, "using buffer size", bs);
encConnector->attach( outputs[u].encIn.get());
outputs[u].encoder = new LameEncoder( encoder,
outputs[u].encInPipe->getFileName(),
dsp.get(),
outputs[u].encOutPipe->getFileName(),
bitrate,
sampleRate,
channel,
lowpass,
highpass );
// streaming related stuff
outputs[u].socket = new TcpSocket( server, port);
outputs[u].ice = new IceCast( outputs[u].socket.get(),
password,
mountPoint,
remoteDumpFile,
name,
description,
url,
genre,
bitrate,
isPublic );
outputs[u].shoutConnector = new Connector( outputs[u].encOutPipe.get(),
outputs[u].ice.get());
}
noOutputs = u;
}
/*------------------------------------------------------------------------------
* Set POSIX real-time scheduling, if super-user
*----------------------------------------------------------------------------*/
void
DarkIce :: setRealTimeScheduling ( void ) throw ( Exception )
{
uid_t euid;
euid = geteuid();
if ( euid == 0 ) {
int high_priority;
struct sched_param param;
/* store the old scheduling parameters */
if ( (origSchedPolicy = sched_getscheduler(0)) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_getscheduler", errno);
}
if ( sched_getparam( 0, &param) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
}
origSchedPriority = param.sched_priority;
/* set SCHED_FIFO with max - 1 priority */
if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) {
throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno);
}
reportEvent( 8, "scheduler high priority", high_priority);
param.sched_priority = high_priority - 1;
if ( sched_setscheduler( 0, SCHED_FIFO, &param) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_setscheduler", errno);
}
/* ask the new priortiy and report it */
if ( sched_getparam( 0, &param) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
}
reportEvent( 1,
"Using POSIX real-time scheduling, priority",
param.sched_priority );
} else {
reportEvent( 1,
"Not running as super-user, unable to use POSIX real-time scheduling" );
reportEvent( 1,
"It is recommended that you run this program as super-user");
}
}
/*------------------------------------------------------------------------------
* Set the original scheduling of the process, the one prior to the
* setRealTimeScheduling call.
* WARNING: make sure you don't call this before setRealTimeScheduling!!
*----------------------------------------------------------------------------*/
void
DarkIce :: setOriginalScheduling ( void ) throw ( Exception )
{
uid_t euid;
euid = geteuid();
if ( euid == 0 ) {
struct sched_param param;
if ( sched_getparam( 0, &param) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
}
param.sched_priority = origSchedPriority;
if ( sched_setscheduler( 0, origSchedPolicy, &param) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_setscheduler", errno);
}
reportEvent( 5, "reverted to original scheduling");
}
}
/*------------------------------------------------------------------------------
* Run the encoder
*----------------------------------------------------------------------------*/
bool
DarkIce :: encode ( void ) throw ( Exception )
{
unsigned int len;
unsigned int u;
unsigned long bytes;
for ( u = 0; u < noOutputs; ++u ) {
outputs[u].encoder->start();
}
sleep( 1 );
if ( !encConnector->open() ) {
throw Exception( __FILE__, __LINE__, "can't open connector");
}
bytes = dsp->getSampleRate() *
(dsp->getBitsPerSample() / 8UL) *
dsp->getChannel() *
duration;
len = encConnector->transfer( bytes, 4096, 1, 0 );
reportEvent( 1, len, "bytes transfered to the encoders");
encConnector->close();
for ( u = 0; u < noOutputs; ++u ) {
outputs[u].encoder->stop();
}
return true;
}
/*------------------------------------------------------------------------------
* Run the encoder
*----------------------------------------------------------------------------*/
bool
DarkIce :: shout ( unsigned int ix ) throw ( Exception )
{
unsigned int len;
unsigned long bytes;
if ( ix >= noOutputs ) {
return false;
}
if ( !outputs[ix].shoutConnector->open() ) {
throw Exception( __FILE__, __LINE__, "can't open connector");
}
bytes = outputs[ix].encoder->getOutBitrate() * (1024UL / 8UL) * duration;
len = outputs[ix].shoutConnector->transfer ( bytes, 4096, 10, 0 );
reportEvent( 1, len, "bytes transfered to stream", ix);
outputs[ix].shoutConnector->close();
return true;
}
/*------------------------------------------------------------------------------
* Run
*----------------------------------------------------------------------------*/
int
DarkIce :: run ( void ) throw ( Exception )
{
unsigned int u;
for ( u = 0; u < noOutputs; ++u ) {
outputs[u].pid = fork();
if ( outputs[u].pid == -1 ) {
throw Exception( __FILE__, __LINE__, "fork error", errno);
} else if ( outputs[u].pid == 0 ) {
// this is the child
sleep ( 1 );
reportEvent( 3, "shouting", u);
shout( u);
reportEvent( 3, "shouting ends", u);
exit(0);
}
}
// this is the parent
reportEvent( 3, "encoding");
setRealTimeScheduling();
encode();
setOriginalScheduling();
reportEvent( 3, "encoding ends");
for ( u = 0; u < noOutputs; ++u ) {
int status;
waitpid( outputs[u].pid, &status, 0);
if ( !WIFEXITED(status) ) {
throw Exception( __FILE__, __LINE__,
"child exited abnormally", WEXITSTATUS(status));
}
}
return 0;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.12 2000/12/20 12:36:47 darkeye
added POSIX real-time scheduling
Revision 1.11 2000/11/18 11:13:27 darkeye
removed direct reference to cout, except from main.cpp
all class use the Reporter interface to report events
Revision 1.10 2000/11/17 15:50:48 darkeye
added -Wall flag to compiler and eleminated new warnings
Revision 1.9 2000/11/15 18:37:37 darkeye
changed the transferable number of bytes to unsigned long
Revision 1.8 2000/11/15 18:08:43 darkeye
added multiple verbosity-level event reporting and verbosity command
line option
Revision 1.7 2000/11/13 19:38:55 darkeye
moved command line parameter parsing from DarkIce.cpp to main.cpp
Revision 1.6 2000/11/13 18:46:50 darkeye
added kdoc-style documentation comments
Revision 1.5 2000/11/10 20:16:21 darkeye
first real tests with multiple streaming
Revision 1.4 2000/11/09 22:09:46 darkeye
added multiple outputs
added configuration reading
added command line processing
Revision 1.3 2000/11/08 17:29:50 darkeye
added configuration file reader
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:49 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,293 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : DarkIce.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef DARK_ICE_H
#define DARK_ICE_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistd.h
#endif
#include <iostream.h>
#include "Referable.h"
#include "Reporter.h"
#include "Exception.h"
#include "Ref.h"
#include "OssDspSource.h"
#include "PipeSink.h"
#include "BufferedSink.h"
#include "Connector.h"
#include "LameEncoder.h"
#include "PipeSource.h"
#include "TcpSocket.h"
#include "IceCast.h"
#include "Config.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Program main object.
*
* @author $Author$
* @version $Revision$
*/
class DarkIce : public virtual Referable, public virtual Reporter
{
private:
/**
* The maximum number of supported outputs.
*/
static const unsigned int maxOutput = 8;
/**
* Type describing each output.
*/
typedef struct {
Ref<PipeSink> encInPipe;
Ref<BufferedSink> encIn;
Ref<LameEncoder> encoder;
Ref<PipeSource> encOutPipe;
Ref<TcpSocket> socket;
Ref<IceCast> ice;
Ref<Connector> shoutConnector;
pid_t pid;
} Output;
/**
* Duration of playing, in seconds.
*/
unsigned int duration;
/**
* The dsp to record from.
*/
Ref<OssDspSource> dsp;
/**
* The encoding Connector, connecting the dsp to the encoders.
*/
Ref<Connector> encConnector;
/**
* The outputs.
*/
Output outputs[maxOutput];
/**
* Number of outputs.
*/
unsigned int noOutputs;
/**
* Original scheduling policy
*/
int origSchedPolicy;
/**
* Original scheduling priority
*/
int origSchedPriority;
/**
* Initialize the object.
*
* @param config the config Object to read initialization
* information from.
* @exception Exception
*/
void
init ( const Config & config ) throw ( Exception );
/**
* Set POSIX real-time scheduling for the encoding process,
* if user permissions enable it.
*
* @exception Exception
*/
void
setRealTimeScheduling ( void ) throw ( Exception );
/**
* Set the scheduling that was before setting real-time scheduling.
* This function must be called _only_ after setRealTimeScheduling.
*
* @exception Exception
*/
void
setOriginalScheduling ( void ) throw ( Exception );
/**
* Start encoding. Spawns all encoders, opens the dsp and
* starts sending data to the encoders.
*
* @return if encoding was successful.
* @exception Exception
*/
bool
encode ( void ) throw ( Exception );
/**
* Start shouting. fork()-s a process for each output, reads
* the output of the encoders and sends them to an IceCast server.
*
* @return if shouting was successful.
* @exception Exception
*/
bool
shout ( unsigned int ) throw ( Exception );
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
DarkIce ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
public:
/**
* Constructor based on a configuration object.
*
* @param config the config Object to read initialization
* information from.
* @exception Exception
*/
inline
DarkIce ( const Config & config ) throw ( Exception )
{
init( config);
}
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~DarkIce ( void ) throw ( Exception )
{
}
/* TODO
inline
DarkIce ( const DarkIce & di ) throw ( Exception )
{
}
inline DarkIce &
operator= ( const DarkIce * di ) throw ( Exception )
{
}
*/
/**
* Run the process of recording / encoding / sending to the servers.
*
* @return 0 on success
* @exception Exception
*/
virtual int
run ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* DARK_ICE_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.7 2000/12/20 12:36:47 darkeye
added POSIX real-time scheduling
Revision 1.6 2000/11/15 18:08:43 darkeye
added multiple verbosity-level event reporting and verbosity command
line option
Revision 1.5 2000/11/13 19:38:55 darkeye
moved command line parameter parsing from DarkIce.cpp to main.cpp
Revision 1.4 2000/11/13 18:46:50 darkeye
added kdoc-style documentation comments
Revision 1.3 2000/11/10 20:16:21 darkeye
first real tests with multiple streaming
Revision 1.2 2000/11/09 22:09:46 darkeye
added multiple outputs
added configuration reading
added command line processing
Revision 1.1.1.1 2000/11/05 10:05:50 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,220 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Exception.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include "Exception.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Constructor
*----------------------------------------------------------------------------*/
Exception :: Exception ( const char * file,
unsigned int line,
const char * description1,
const char * description2,
int code = 0 ) throw ()
{
size_t len = 0;
if ( description1 ) {
len += strlen( description1);
}
if ( description2 ) {
len += strlen( description2);
}
if ( len ) {
char str[len+1];
str[0] = '\0';
if ( description1 ) {
strcat( str, description1);
}
if ( description2 ) {
strcat( str, description2);
}
init( file, line, str, code);
} else {
init( file, line, 0, code);
}
}
/*------------------------------------------------------------------------------
* Constructor
*----------------------------------------------------------------------------*/
Exception :: Exception ( const char * file,
unsigned int line,
const char * description1,
const char * description2,
const char * description3,
int code = 0 ) throw ()
{
size_t len = 0;
if ( description1 ) {
len += strlen( description1);
}
if ( description2 ) {
len += strlen( description2);
}
if ( description3 ) {
len += strlen( description3);
}
if ( len ) {
char str[len+1];
str[0] = '\0';
if ( description1 ) {
strcat( str, description1);
}
if ( description2 ) {
strcat( str, description2);
}
if ( description3 ) {
strcat( str, description3);
}
init( file, line, str, code);
} else {
init( file, line, 0, code);
}
}
/*------------------------------------------------------------------------------
* Initialize the class
*----------------------------------------------------------------------------*/
void
Exception :: init ( const char * file,
unsigned int line,
const char * description = 0,
int code = 0 ) throw ()
{
if ( !file ) {
this->file = 0;
} else {
size_t len;
len = strlen( file ) + 1;
this->file = new char[len];
if ( this->file ) {
memcpy( this->file, file, len);
}
}
if ( !description ) {
this->description = 0;
} else {
size_t len;
len = strlen( description ) + 1;
this->description = new char[len];
if ( this->description ) {
memcpy( this->description, description, len);
}
}
this->line = line;
this->code = code;
}
/*------------------------------------------------------------------------------
* De-initialize the class
*----------------------------------------------------------------------------*/
void
Exception :: strip ( void ) throw ()
{
if ( description ) {
delete[] description;
}
if ( file ) {
delete[] file;
}
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.3 2000/11/09 22:05:44 darkeye
added multiple-string constructors
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:50 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,322 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Exception.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef EXCEPTION_H
#define EXCEPTION_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include <iostream.h>
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An exception class.
*
* This class should not depend on any other class
* should not throw any exceptions itself.
*
* Typical usage:
*
* <pre>
* throw Exception( __FILE__, __LINE__, "describe the exception", code);
* </pre>
*
* @author $Author$
* @version $Revision$
*/
class Exception
{
private:
/**
* Source file the exception was thrown in.
*/
char * file;
/**
* Line number in the source file the exception was thrown in.
*/
unsigned int line;
/**
* Textual description of the exception.
*/
char * description;
/**
* Numerical error code.
*/
int code;
/**
* Initalize the object.
*
* @param file the source file the exception was thrown in.
* @param line the line in the source file.
* @param description textual description of the exception.
* @param code numerical error code.
*/
void
init ( const char * file,
unsigned int line,
const char * description,
int code ) throw ();
/**
* De-initalize the object.
*/
void
strip () throw ();
protected:
public:
/**
* Default constructor.
*/
inline
Exception ( void ) throw ()
{
init( 0, 0, 0, 0);
}
/**
* Copy constructor.
*/
inline
Exception ( const Exception & e ) throw ()
{
init( e.file, e.line, e.description, e.code);
}
/**
* Construct by a description and error code.
*
* @param description textual description of the exception.
* @param code numerical error code.
*/
inline
Exception ( const char * description,
int code = 0 ) throw ()
{
init( 0, 0, description, code);
}
/**
* Construct by source file information, a description and error code.
*
* @param file the source file the exception was thrown in.
* @param line the line in the source file.
* @param description textual description of the exception.
* @param code numerical error code.
*/
inline
Exception ( const char * file,
unsigned int line,
const char * description = 0,
int code = 0 ) throw ()
{
init( file, line, description, code);
}
/**
* Construct by source file information, a description and error code.
* The description is constructed from two strings, any of which
* may be NULL.
*
* @param file the source file the exception was thrown in.
* @param line the line in the source file.
* @param description1 textual description of the exception part 1.
* @param description2 textual description of the exception part 2.
* @param code numerical error code.
*/
Exception ( const char * file,
unsigned int line,
const char * description1,
const char * description2,
int code = 0 ) throw ();
/**
* Construct by source file information, a description and error code.
* The description is constructed from three strings, any of
* which may be NULL.
*
* @param file the source file the exception was thrown in.
* @param line the line in the source file.
* @param description1 textual description of the exception part 1.
* @param description2 textual description of the exception part 2.
* @param description3 textual description of the exception part 3.
* @param code numerical error code.
*/
Exception ( const char * file,
unsigned int line,
const char * description1,
const char * description2,
const char * description3,
int code = 0 ) throw ();
/**
* Desctructor.
*/
inline
~Exception ( void ) throw ()
{
strip();
}
/**
* Assignment operator.
*
* @param e the Exception to assign this to.
* @return a reference to this Exception.
*/
inline Exception &
operator= ( const Exception & e ) throw ()
{
if ( this != &e ) {
strip();
init( e.file, e.line, e.description, e.code);
}
return *this;
}
/**
* Return the textual description of the Exception.
*
* @return the textual description of the Exception.
*/
inline const char *
getDescription( void ) const throw ()
{
return description;
}
/**
* Return the line number in the source file this Exception was
* thrown in.
*
* @return the line number in the source file this Exception was
* thrown in.
*/
inline unsigned int
getLine ( void ) const throw ()
{
return line;
}
/**
* Return the source file this Exception was thrown in.
*
* @return the source file this Exception was thrown in.
*/
inline const char *
getFile ( void ) const throw ()
{
return file;
}
/**
* Return the numerical code of the Exception.
*
* @return the numerical code of the Exception.
*/
inline int
getCode ( void ) const throw ()
{
return code;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
/**
* Print an Exception to an ostream.
*
* @param os the output stream to print to.
* @param e the Exception to print.
* @return a reference to the supplied output stream.
*/
inline ostream &
operator<< ( ostream & os,
const Exception & e )
{
os << e.getFile() << ":" << e.getLine() << ": "
<< e.getDescription() << " [" << e.getCode() << "]";
return os;
}
#endif /* EXCEPTION_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.5 2000/11/17 15:33:54 darkeye
bug fix: ostream << operator overload didn't return the ostream
Revision 1.4 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.3 2000/11/09 22:05:44 darkeye
added multiple-string constructors
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:50 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,218 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : ExternalEncoder.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistd.h
#endif
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#else
#error need signal.h
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#else
#error need errno.h
#endif
#include "Exception.h"
#include "Util.h"
#include "ExternalEncoder.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
#define ARG_LEN 64
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the class
*----------------------------------------------------------------------------*/
void
ExternalEncoder :: init ( const char * encoderName,
const char * inFileName,
const char * outFileName ) throw ( Exception )
{
unsigned int u;
for ( u = 0; u < numCmdArgs; ++u ) {
cmdArgs[u] = 0;
}
this->encoderName = Util::strDup( encoderName);
this->inFileName = Util::strDup( inFileName);
this->outFileName = Util::strDup( outFileName);
this->child = 0;
}
/*------------------------------------------------------------------------------
* De-initialize the class
*----------------------------------------------------------------------------*/
void
ExternalEncoder :: strip ( void ) throw ( Exception )
{
unsigned int u;
if ( isRunning() ) {
stop();
}
for ( u = 0; u < numCmdArgs; ++u ) {
if ( cmdArgs[u] ) {
delete[] cmdArgs[u];
}
}
delete[] encoderName;
delete[] inFileName;
delete[] outFileName;
child = 0;
}
/*------------------------------------------------------------------------------
* Set the nth command line argument
*----------------------------------------------------------------------------*/
void
ExternalEncoder :: setArg ( const char * str,
unsigned int index ) throw ( Exception )
{
if ( index >= numCmdArgs ) {
throw Exception( __FILE__, __LINE__, "index >= numCmdArgs", index);
}
cmdArgs[index] = str ? Util::strDup( str) : 0;
}
/*------------------------------------------------------------------------------
* Start the encoding
*----------------------------------------------------------------------------*/
bool
ExternalEncoder :: start ( void ) throw ( Exception )
{
pid_t pid;
if ( isRunning() ) {
return false;
}
pid = fork();
if ( pid == -1 ) {
throw Exception( __FILE__, __LINE__, "fork error");
} else if ( pid == 0 ) {
reportEvent( 5, "child process", getpid(), "started");
makeArgs();
execvp( getEncoderName(), cmdArgs);
throw Exception( __FILE__, __LINE__, "exec returned");
} else {
child = pid;
reportEvent( 5, "parent", getpid(), "started child process", child);
return true;
}
}
/*------------------------------------------------------------------------------
* End the encoding
*----------------------------------------------------------------------------*/
void
ExternalEncoder :: stop ( void ) throw ( Exception )
{
if ( !isRunning() ) {
return;
}
if ( kill( child, SIGHUP) == -1 ) {
throw Exception( __FILE__, __LINE__, "kill", errno);
}
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/18 11:13:27 darkeye
removed direct reference to cout, except from main.cpp
all class use the Reporter interface to report events
Revision 1.3 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:50 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,382 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : ExternalEncoder.h
Version : $Revision$
Author : $Author$
Location : $ExternalEncoder$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef EXTERNAL_ENCODER_H
#define EXTERNAL_ENCODER_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#include "Exception.h"
#include "Reporter.h"
#include "AudioEncoder.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing an external audio encoder which is invoked
* with a frok() and an exec() call
*
* @author $Author$
* @version $Revision$
*/
class ExternalEncoder : public AudioEncoder, public virtual Reporter
{
private:
/**
* Name of the encoder (the command to invoke the encoder with).
*/
char * encoderName;
/**
* Input file parameter for the encoder.
*/
char * inFileName;
/**
* Output file parameter for the encoder.
*/
char * outFileName;
/**
* Maximum number of command line arguments.
*/
static const unsigned int numCmdArgs = 64;
/**
* Array of command line arguments.
*/
char * cmdArgs[numCmdArgs];
/**
* Process ID of the encoder process.
*/
pid_t child;
/**
* Initialize the object.
*
* @param encoderName name of the encoder.
* @param inFileName input file parameter for the encoder.
* @param outFileName output file parameter for the encoder.
* @exception Exception
*/
void
init ( const char * encoderName,
const char * inFileName,
const char * outFileName ) throw ( Exception );
/**
* De-initialize the object.
*
* @exception Exception
*/
void
strip ( void ) throw ( Exception );
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
ExternalEncoder ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Set a command line argument in the argument array.
*
* @param str the argument to set.
* @param index the place in the array to set the argument.
* @exception Exception
*/
void
setArg ( const char * str,
unsigned int index ) throw ( Exception );
/**
* Fill in the list of command line arguments. Puts a 0
* as the last in the list of args.
*
* @return the number of arguments filled.
* @exception Exception
*/
virtual unsigned int
makeArgs ( void ) throw ( Exception ) = 0;
public:
/**
* Constructor.
*
* @param encoderName name of the encoder.
* (the command to invoke the encoder with)
* @param inFileName input file parameter for the encoder.
* @param inSampleRate sample rate of the input.
* @param inBitsPerSample number of bits per sample of the input.
* @param inChannel number of channels of the input.
* @param outFileName output file parameter for the encoder.
* @param outBitrate bit rate of the output (bits/sec).
* @param outSampleRate sample rate of the output.
* If 0, inSampleRate is used.
* @param outChannel number of channels of the output.
* If 0, inChannel is used.
* @exception Exception
*/
inline
ExternalEncoder ( const char * encoderName,
const char * inFileName,
unsigned int inSampleRate,
unsigned int inBitsPerSample,
unsigned int inChannel,
const char * outFileName,
unsigned int outBitrate,
unsigned int outSampleRate = 0,
unsigned int outChannel = 0 )
throw ( Exception )
: AudioEncoder ( inSampleRate,
inBitsPerSample,
inChannel,
outBitrate,
outSampleRate,
outChannel )
{
init ( encoderName, inFileName, outFileName );
}
/**
* Constructor.
*
* @param encoderName name of the encoder.
* (the command to invoke the encoder with)
* @param inFileName input file parameter for the encoder.
* @param as get input sample rate, bits per sample and channels
* from this AudioSource.
* @param outFileName output file parameter for the encoder.
* @param outBitrate bit rate of the output (bits/sec).
* @param outSampleRate sample rate of the output.
* If 0, input sample rate is used.
* @param outChannel number of channels of the output.
* If 0, input channel is used.
* @exception Exception
*/
inline
ExternalEncoder ( const char * encoderName,
const char * inFileName,
const AudioSource * as,
const char * outFileName,
unsigned int outBitrate,
unsigned int outSampleRate = 0,
unsigned int outChannel = 0 )
throw ( Exception )
: AudioEncoder ( as,
outBitrate,
outSampleRate,
outChannel )
{
init ( encoderName, inFileName, outFileName );
}
/**
* Copy constructor.
*
* @param encoder the ExternalEncoder to copy.
*/
inline
ExternalEncoder ( const ExternalEncoder & encoder )
throw ( Exception )
: AudioEncoder( encoder )
{
init( encoder.encoderName,
encoder.inFileName,
encoder.outFileName );
}
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~ExternalEncoder ( void ) throw ( Exception )
{
strip();
}
/**
* Assignment operator.
*
* @param encoder the ExternalEncoder to assign this to.
* @return a reference to this ExternalEncoder.
* @exception Exception
*/
inline virtual ExternalEncoder &
operator= ( const ExternalEncoder & encoder ) throw ( Exception )
{
if ( this != &encoder ) {
strip();
AudioEncoder::operator=( encoder);
init( encoder.encoderName,
encoder.inFileName,
encoder.outFileName );
}
return *this;
}
/**
* Get the name of the encoder
* (the command to invoke the encoder with).
*
* @return the name of the encoder.
*/
const char *
getEncoderName ( void ) const throw ()
{
return encoderName;
}
/**
* Get the input file parameter for the encoder.
*
* @return the input file parameter for the encoder.
*/
const char *
getInFileName ( void ) const throw ()
{
return inFileName;
}
/**
* Get the output file parameter for the encoder.
*
* @return the output file parameter for the encoder.
*/
const char *
getOutFileName ( void ) const throw ()
{
return outFileName;
}
/**
* Check wether encoding is in progress.
*
* @return true if encoding is in progress, false otherwise.
*/
inline virtual bool
isRunning ( void ) const throw ()
{
return child != 0;
}
/**
* Start encoding. This function returns as soon as possible,
* with encoding started as a separate process in the
* background.
*
* @return true if encoding has started, false otherwise.
* @exception Exception
*/
virtual bool
start ( void ) throw ( Exception );
/**
* Stop encoding. Stops the encoding running in the background.
*
* @exception Exception
*/
virtual void
stop ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* EXTERNAL_ENCODER_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.5 2000/11/18 11:13:27 darkeye
removed direct reference to cout, except from main.cpp
all class use the Reporter interface to report events
Revision 1.4 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.3 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:50 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,320 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : FileSink.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistd.h
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#else
#error need stdlib.h
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#else
#error need errno.h
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#else
#error need sys/stat.h
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#error need fcntl.h
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#error need sys/time.h
#endif
#include "Util.h"
#include "Exception.h"
#include "FileSink.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
FileSink :: init ( const char * name ) throw ( Exception )
{
fileName = Util::strDup( name);
fileDescriptor = 0;
}
/*------------------------------------------------------------------------------
* De-initialize the object
*----------------------------------------------------------------------------*/
void
FileSink :: strip ( void) throw ( Exception )
{
if ( isOpen() ) {
close();
}
delete[] fileName;
}
/*------------------------------------------------------------------------------
* Copy Constructor
*----------------------------------------------------------------------------*/
FileSink :: FileSink ( const FileSink & fs ) throw ( Exception )
: Sink( fs )
{
int fd;
init( fs.fileName);
if ( (fd = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0) == -1 ) {
strip();
throw Exception( __FILE__, __LINE__, "dup failure");
}
fileDescriptor = fd;
}
/*------------------------------------------------------------------------------
* Assignment operator
*----------------------------------------------------------------------------*/
FileSink &
FileSink :: operator= ( const FileSink & fs ) throw ( Exception )
{
if ( this != &fs ) {
int fd;
/* first strip */
strip();
/* then build up */
Sink::operator=( fs );
init( fs.fileName);
if ( (fd = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0) == -1 ) {
strip();
throw Exception( __FILE__, __LINE__, "dup failure");
}
fileDescriptor = fd;
}
return *this;
}
/*------------------------------------------------------------------------------
* Check wether a file exists
*----------------------------------------------------------------------------*/
bool
FileSink :: exists ( void ) const throw ()
{
struct stat st;
if ( stat( (const char*)fileName, &st) == -1 ) {
return false;
}
return true;
}
/*------------------------------------------------------------------------------
* Create a file, truncate if already exists
*----------------------------------------------------------------------------*/
bool
FileSink :: create ( void ) throw ( Exception )
{
int fd;
if ( isOpen() ) {
return false;
}
if ( (fd = ::creat( fileName, S_IRUSR | S_IWUSR)) == -1 ) {
throw Exception( __FILE__, __LINE__, "creat error", errno);
}
::close( fd);
return true;
}
/*------------------------------------------------------------------------------
* Open the file
*----------------------------------------------------------------------------*/
bool
FileSink :: open ( void ) throw ( Exception )
{
if ( isOpen() ) {
return false;
}
if ( (fileDescriptor = ::open( fileName, O_WRONLY | O_TRUNC, 0)) == -1 ) {
fileDescriptor = 0;
return false;
}
return true;
}
/*------------------------------------------------------------------------------
* Check wether read() would return anything
*----------------------------------------------------------------------------*/
bool
FileSink :: canWrite ( unsigned int sec,
unsigned int usec ) throw ( Exception )
{
fd_set fdset;
struct timeval tv;
int ret;
if ( !isOpen() ) {
return false;
}
FD_ZERO( &fdset);
FD_SET( fileDescriptor, &fdset);
tv.tv_sec = sec;
tv.tv_usec = usec;
ret = select( fileDescriptor + 1, NULL, &fdset, NULL, &tv);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "select error");
}
return ret > 0;
}
/*------------------------------------------------------------------------------
* Read from the audio source
*----------------------------------------------------------------------------*/
unsigned int
FileSink :: write ( const void * buf,
unsigned int len ) throw ( Exception )
{
ssize_t ret;
if ( !isOpen() ) {
return 0;
}
ret = ::write( fileDescriptor, buf, len);
if ( ret == -1 ) {
if ( errno == EAGAIN ) {
ret = 0;
} else {
throw Exception( __FILE__, __LINE__, "write error", errno);
}
}
return ret;
}
/*------------------------------------------------------------------------------
* Close the audio source
*----------------------------------------------------------------------------*/
void
FileSink :: close ( void ) throw ( Exception )
{
if ( !isOpen() ) {
return;
}
flush();
::close( fileDescriptor);
fileDescriptor = 0;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:51 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,264 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : FileSink.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef FILE_SINK_H
#define FILE_SINK_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Sink.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* File data output
*
* @author $Author$
* @version $Revision$
*/
class FileSink : public Sink
{
private:
/**
* Name of the file represented by the FileSink.
*/
char * fileName;
/**
* Initialize the object.
*
* @param name name of the file to be represented by the object.
* @exception Exception
*/
void
init ( const char * name ) throw ( Exception );
/**
* De-initialize the object.
*
* @exception Exception
*/
void
strip ( void ) throw ( Exception );
protected:
/**
* Low-level file descriptor for the file represented by this object.
*/
int fileDescriptor;
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
FileSink ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
public:
/**
* Constructor by a file name.
*
* @param name name of the file to be represented by the object.
* @exception Exception
*/
inline
FileSink( const char * name ) throw ( Exception )
{
init( name);
}
/**
* Copy constructor.
*
* @param fsink the FileSink to copy.
* @exception Exception
*/
FileSink( const FileSink & fsink ) throw ( Exception );
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~FileSink( void ) throw ( Exception )
{
strip();
}
/**
* Assignment operator.
*
* @param fs the FileSink to assign to this object.
* @return a reference to this object.
* @exception Exception
*/
virtual FileSink &
operator= ( const FileSink & fs ) throw ( Exception );
/**
* Get the file name this FileSink represents.
*
* @return the file name this FileSink represents.
*/
inline const char *
getFileName ( void ) const throw ()
{
return fileName;
}
/**
* Check for the existence of the file this FileSink represents.
*
* @return true if the file exists, false otherwise.
*/
virtual bool
exists ( void ) const throw ();
/**
* Create the file.
*
* @return true if creation was successful, false otherwise.
* @exception Exception
*/
virtual bool
create ( void ) throw ( Exception );
/**
* Open the file. Truncates the file.
*
* @return true if opening was successful, false otherwise.
* @exception Exception
*/
virtual bool
open ( void ) throw ( Exception );
/**
* Check if the FileSink is open.
*
* @return true if the FileSink is open, false otherwise.
*/
inline virtual bool
isOpen ( void ) const throw ()
{
return fileDescriptor != 0;
}
/**
* Check if the FileSink is ready to accept data.
* Blocks until the specified time for data to be available.
*
* @param sec the maximum seconds to block.
* @param usec micro seconds to block after the full seconds.
* @return true if the Sink is ready to accept data, false otherwise.
* @exception Exception
*/
virtual bool
canWrite ( unsigned int sec,
unsigned int usec ) throw ( Exception );
/**
* Write data to the FileSink.
*
* @param buf the data to write.
* @param len number of bytes to write from buf.
* @return the number of bytes written (may be less than len).
* @exception Exception
*/
virtual unsigned int
write ( const void * buf,
unsigned int len ) throw ( Exception );
/**
* This is a no-op in this FileSink.
*
* @exception Exception
*/
inline virtual void
flush ( void ) throw ( Exception )
{
}
/**
* Close the FileSink.
*
* @exception Exception
*/
virtual void
close ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* FILE_SINK_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.2 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.1.1.1 2000/11/05 10:05:51 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,270 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : FileSource.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistd.h
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#else
#error need sys/stat.h
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#error need fcntl.h
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#error need sys/time.h
#endif
#include "Exception.h"
#include "Util.h"
#include "FileSource.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
FileSource :: init ( const char * name ) throw ( Exception )
{
fileName = Util::strDup( name);
fileDescriptor = 0;
}
/*------------------------------------------------------------------------------
* De-initialize the object
*----------------------------------------------------------------------------*/
void
FileSource :: strip ( void ) throw ( Exception )
{
if ( isOpen() ) {
close();
}
delete[] fileName;
fileDescriptor = 0;
}
/*------------------------------------------------------------------------------
* Copy Constructor
*----------------------------------------------------------------------------*/
FileSource :: FileSource ( const FileSource & fs ) throw ( Exception )
{
init( fs.fileName);
fileDescriptor = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0;
if ( fileDescriptor == -1 ) {
strip();
throw Exception( __FILE__, __LINE__, "dup failure");
}
}
/*------------------------------------------------------------------------------
* Assignment operator
*----------------------------------------------------------------------------*/
FileSource &
FileSource :: operator= ( const FileSource & fs ) throw ( Exception )
{
if ( this != &fs ) {
init( fs.fileName);
fileDescriptor = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0;
if ( fileDescriptor == -1 ) {
strip();
throw Exception( __FILE__, __LINE__, "dup failure");
}
}
return *this;
}
/*------------------------------------------------------------------------------
* Check wether a file exists
*----------------------------------------------------------------------------*/
bool
FileSource :: exists ( void ) const throw ()
{
struct stat st;
if ( stat( (const char*)fileName, &st) == -1 ) {
return false;
}
return true;
}
/*------------------------------------------------------------------------------
* Open the source
*----------------------------------------------------------------------------*/
bool
FileSource :: open ( void ) throw ( Exception )
{
if ( isOpen() ) {
return false;
}
if ( (fileDescriptor = ::open( fileName, O_RDONLY)) == -1 ) {
fileDescriptor = 0;
return false;
}
return true;
}
/*------------------------------------------------------------------------------
* Check wether read() would return anything
*----------------------------------------------------------------------------*/
bool
FileSource :: canRead ( unsigned int sec,
unsigned int usec ) throw ( Exception )
{
fd_set fdset;
struct timeval tv;
int ret;
if ( !isOpen() ) {
return false;
}
FD_ZERO( &fdset);
FD_SET( fileDescriptor, &fdset);
tv.tv_sec = sec;
tv.tv_usec = usec;
ret = select( fileDescriptor + 1, &fdset, NULL, NULL, &tv);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "select error");
}
return ret > 0;
}
/*------------------------------------------------------------------------------
* Read from the audio source
*----------------------------------------------------------------------------*/
unsigned int
FileSource :: read ( void * buf,
unsigned int len ) throw ( Exception )
{
ssize_t ret;
if ( !isOpen() ) {
return 0;
}
ret = ::read( fileDescriptor, buf, len);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "read error");
}
return ret;
}
/*------------------------------------------------------------------------------
* Close the audio source
*----------------------------------------------------------------------------*/
void
FileSource :: close ( void ) throw ( Exception )
{
if ( !isOpen() ) {
return;
}
::close( fileDescriptor);
fileDescriptor = 0;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:51 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,243 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : FileSource.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef FILE_SOURCE_H
#define FILE_SOURCE_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Source.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A data source based on a file
*
* @author $Author$
* @version $Revision$
*/
class FileSource : public Source
{
private:
/**
* Name of the file represented by the FileSource.
*/
char * fileName;
/**
* Initialize the object.
*
* @param name name of the file to be represented by the object.
* @exception Exception
*/
void
init ( const char * name ) throw ( Exception );
/**
* De-initialize the object.
*
* @exception Exception
*/
void
strip ( void ) throw ( Exception );
protected:
/**
* Low-level file descriptor for the file represented by this object.
*/
int fileDescriptor;
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
FileSource ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
public:
/**
* Constructor by a file name.
*
* @param name name of the file to be represented by the object.
* @exception Exception
*/
inline
FileSource ( const char * name ) throw ( Exception )
{
init( name);
}
/**
* Copy constructor.
*
* @param fs the FileSource to copy.
* @exception Exception
*/
FileSource ( const FileSource & fs ) throw ( Exception );
/**
* Destructor.
*
* @exception Exception
*/
inline
~FileSource ( void ) throw ( Exception )
{
strip();
}
/**
* Assignment operator.
*
* @param fs the FileSource to assign to this object.
* @return a reference to this object.
* @exception Exception
*/
inline virtual FileSource &
operator= ( const FileSource & fs ) throw ( Exception );
/**
* Get the file name this FileSource represents.
*
* @return the file name this FileSource represents.
*/
inline virtual const char *
getFileName ( void ) const throw ()
{
return fileName;
}
/**
* Check for the existence of the file this FileSource represents.
*
* @return true if the file exists, false otherwise.
*/
virtual bool
exists ( void ) const throw ();
/**
* Open the file.
*
* @return true if opening was successful, false otherwise.
* @exception Exception
*/
virtual bool
open ( void ) throw ( Exception );
/**
* Check if the FileSource is open.
*
* @return true if the FileSource is open, false otherwise.
*/
inline virtual bool
isOpen ( void ) const throw ()
{
return fileDescriptor != 0;
}
/**
* Check if the FileSource has data available.
* Blocks until the specified time for data to be available.
*
* @param sec the maximum seconds to block.
* @param usec micro seconds to block after the full seconds.
* @return true if the FileSource has data to be read,
* false otherwise.
* @exception Exception
*/
virtual bool
canRead ( unsigned int sec,
unsigned int usec ) throw ( Exception );
/**
* Read from the FileSource.
*
* @param buf the buffer to read into.
* @param len the number of bytes to read into buf
* @return the number of bytes read (may be less than len).
* @exception Exception
*/
virtual unsigned int
read ( void * buf,
unsigned int len ) throw ( Exception );
/**
* Close the FileSource.
*
* @exception Exception
*/
virtual void
close ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* FILE_SOURCE_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.2 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.1.1.1 2000/11/05 10:05:51 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,203 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : IceCast.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#else
#error need stdio.h
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include "Exception.h"
#include "Source.h"
#include "Sink.h"
#include "IceCast.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/*------------------------------------------------------------------------------
* Size of string conversion buffer
*----------------------------------------------------------------------------*/
#define STRBUF_SIZE 32
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
bool
IceCast :: sendLogin ( void ) throw ( Exception )
{
Sink * sink = getSink();
Source * source = getSocket();
const char * str;
char resp[STRBUF_SIZE];
unsigned int len;
if ( !source->isOpen() ) {
return false;
}
if ( !sink->isOpen() ) {
return false;
}
/* send the request, a string like:
* "SOURCE <password> /<mountpoint>\n\n" */
str = "SOURCE ";
sink->write( str, strlen( str));
str = getPassword();
sink->write( str, strlen( str));
str = " /";
sink->write( str, strlen( str));
str = getMountPoint();
sink->write( str, strlen( str));
str = "\n\n";
sink->write( str, strlen( str));
sink->flush();
/* read the anticipated response: "OK" */
len = source->read( resp, STRBUF_SIZE);
if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
return false;
}
/* suck anything that the other side has to say */
while ( source->canRead( 0, 0) &&
(len = source->read( resp, STRBUF_SIZE)) ) {
;
}
/* send the x-audiocast headers */
str = "x-audiocast-name: ";
sink->write( str, strlen( str));
str = getName();
sink->write( str, strlen( str));
str = "\nx-audiocast-description: ";
sink->write( str, strlen( str));
str = getDescription();
sink->write( str, strlen( str));
str = "\nx-audiocast-url: ";
sink->write( str, strlen( str));
str = getUrl();
sink->write( str, strlen( str));
str = "\nx-audiocast-genre: ";
sink->write( str, strlen( str));
str = getGenre();
sink->write( str, strlen( str));
str = "\nx-audiocast-bitrate: ";
sink->write( str, strlen( str));
if ( snprintf( resp, STRBUF_SIZE, "%d", getBitRate()) == -1 ) {
throw Exception( __FILE__, __LINE__, "snprintf overflow");
}
sink->write( resp, strlen( resp));
str = "\nx-audiocast-public: ";
sink->write( str, strlen( str));
str = getIsPublic() ? "yes" : "no";
sink->write( str, strlen( str));
if ( getRemoteDumpFile() ) {
str = "\nx-audiocast-dumpfile: ";
sink->write( str, strlen( str));
str = getRemoteDumpFile();
sink->write( str, strlen( str));
}
str = "\n\n";
sink->write( str, strlen( str));
sink->flush();
/* read the anticipated response: "OK" */
len = source->read( resp, STRBUF_SIZE);
if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
return false;
}
/* suck anything that the other side has to say */
while ( source->canRead( 0, 0) &&
(len = source->read( resp, STRBUF_SIZE)) ) {
;
}
return true;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.3 2000/11/10 20:14:11 darkeye
added support for remote dump file
Revision 1.2 2000/11/05 14:08:28 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:52 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,201 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : IceCast.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef ICE_CAST_H
#define ICE_CAST_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Sink.h"
#include "TcpSocket.h"
#include "CastSink.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Class representing output to an IceCast server with
* x-audiocast login
*
* @author $Author$
* @version $Revision$
*/
class IceCast : public CastSink
{
private:
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
IceCast ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Log in to the server using the socket avialable.
*
* @return true if login was successful, false otherwise.
* @exception Exception
*/
virtual bool
sendLogin ( void ) throw ( Exception );
public:
/**
* Constructor.
*
* @param socket socket connection to the server.
* @param password password to the server.
* @param mountPoint mount point of the stream on the server.
* @param remoteDumpFile remote dump file (may be NULL).
* @param name name of the stream.
* @param description description of the stream.
* @param url URL associated with the stream.
* @param genre genre of the stream.
* @param bitRate bitrate of the stream (e.g. mp3 bitrate).
* @param isPublic is the stream public?
* @param bufferDuration duration of the BufferedSink buffer
* in seconds.
* @exception Exception
*/
inline
IceCast ( TcpSocket * socket,
const char * password,
const char * mountPoint,
const char * remoteDumpFile,
const char * name,
const char * description,
const char * url,
const char * genre,
unsigned int bitRate,
bool isPublic,
unsigned int bufferDuration = 10 )
throw ( Exception )
: CastSink( socket,
password,
mountPoint,
remoteDumpFile,
name,
description,
url,
genre,
bitRate,
isPublic,
bufferDuration )
{
}
/**
* Copy constructor.
*
* @param cs the IceCast to copy.
*/
inline
IceCast( const IceCast & cs ) throw ( Exception )
: CastSink( cs )
{
}
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~IceCast( void ) throw ( Exception )
{
}
/**
* Assignment operator.
*
* @param cs the IceCast to assign this to.
* @return a reference to this IceCast.
* @exception Exception
*/
inline virtual IceCast &
operator= ( const IceCast & cs ) throw ( Exception )
{
if ( this != &cs ) {
CastSink::operator=( cs );
}
return *this;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* ICE_CAST_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.3 2000/11/10 20:14:11 darkeye
added support for remote dump file
Revision 1.2 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.1.1.1 2000/11/05 10:05:52 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,160 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : LameEncoder.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#else
#error need stdio.h
#endif
#include "Exception.h"
#include "LameEncoder.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
#define ARG_LEN 64
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize command line parameters
*----------------------------------------------------------------------------*/
unsigned int
LameEncoder :: makeArgs ( void ) throw ( Exception )
{
unsigned int u;
char str[ARG_LEN];
u = 0;
setArg( getEncoderName(), u++); // name of the command
setArg( "-S", u++); // make it silent
setArg( "-r", u++); // input is raw PCM
setArg( "-x", u++); // input is little endian
setArg( "-h", u++); // high quality
/* set input sample rate */
if ( snprintf( str, ARG_LEN, "%.3f",
((double)getInSampleRate()) / 1000.0 ) == -1 ) {
throw Exception( __FILE__, __LINE__, "snprintf overflow");
}
setArg( "-s", u++);
setArg( str, u++);
/* set stereo / mono */
setArg( "-m", u++);
setArg( getOutChannel() == 1 ? "m" : "j", u++);
/* set output bitrate */
if ( snprintf( str, ARG_LEN, "%d", getOutBitrate()) == -1 ) {
throw Exception( __FILE__, __LINE__, "snprintf overflow");
}
setArg( "-b", u++);
setArg( str, u++);
/* set output sample rate */
if ( snprintf( str, ARG_LEN, "%.3f",
((double)getOutSampleRate()) / 1000.0 ) == -1 ) {
throw Exception( __FILE__, __LINE__, "snprintf overflow");
}
setArg( "--resample", u++);
setArg( str, u++);
/* set lowpass filter if needed */
if ( lowpass ) {
if ( snprintf( str, ARG_LEN, "%.3f",
((double)getLowpass()) / 1000.0 ) == -1 ) {
throw Exception( __FILE__, __LINE__, "snprintf overflow");
}
setArg( "--lowpass", u++);
setArg( str, u++);
}
/* set highpass filter if needed */
if ( highpass ) {
if ( snprintf( str, ARG_LEN, "%.3f",
((double)getHighpass()) / 1000.0 ) == -1 ) {
throw Exception( __FILE__, __LINE__, "snprintf overflow");
}
setArg( "--highpass", u++);
setArg( str, u++);
}
setArg( getInFileName(), u++); // input file
setArg( getOutFileName(), u++); // output file
setArg( 0, u++); // terminating zero
return u;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 14:08:28 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:52 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,362 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : LameEncoder.h
Version : $Revision$
Author : $Author$
Location : $LameEncoder$
Abstract :
A class representing the lame mp3 encoder
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef LAME_ENCODER_H
#define LAME_ENCODER_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Exception.h"
#include "ExternalEncoder.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing the lame mp3 encoder
*
* @author $Author$
* @version $Revision$
*/
class LameEncoder : public ExternalEncoder
{
private:
/**
* Highpass filter. Sound frequency in Hz, from where up the
* input is cut.
*/
unsigned int lowpass;
/**
* Lowpass filter. Sound frequency in Hz, from where down the
* input is cut.
*/
unsigned int highpass;
protected:
/**
* Fill in the list of command line arguments. Puts a 0
* as the last in the list of args.
*
* @return the number of arguments filled.
* @exception Exception
*/
virtual unsigned int
makeArgs ( void ) throw ( Exception );
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
LameEncoder ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Initialize the object.
*
* @param lowpass lowpass filter range.
* @param highpass highpass filter range.
* @exception Exception
*/
inline void
init ( unsigned int lowpass,
unsigned int highpass ) throw ( Exception )
{
this->lowpass = lowpass;
this->highpass = highpass;
}
/**
* De-initialize the object.
*
* @exception Exception
*/
inline void
strip ( void ) throw ( Exception )
{
}
public:
/**
* Constructor.
*
* @param encoderName name of the encoder.
* (the command to invoke the encoder with)
* @param inFileName input file parameter for the encoder.
* @param inSampleRate sample rate of the input.
* @param inBitsPerSample number of bits per sample of the input.
* @param inChannel number of channels of the input.
* @param outFileName output file parameter for the encoder.
* @param outBitrate bit rate of the output (bits/sec).
* @param outSampleRate sample rate of the output.
* If 0, inSampleRate is used.
* @param outChannel number of channels of the output.
* If 0, inChannel is used.
* @param lowpass frequency threshold for the lowpass filter.
* Input above this frequency is cut.
* If 0, lame's default values are used,
* which depends on the out sample rate.
* @param highpass frequency threshold for the highpass filter.
* Input below this frequency is cut.
* If 0, lame's default values are used,
* which depends on the out sample rate.
* @exception Exception
*/
inline
LameEncoder ( const char * encoderName,
const char * inFileName,
unsigned int inSampleRate,
unsigned int inBitsPerSample,
unsigned int inChannel,
const char * outFileName,
unsigned int outBitrate,
unsigned int outSampleRate = 0,
unsigned int outChannel = 0,
unsigned int lowpass = 0,
unsigned int highpass = 0 )
throw ( Exception )
: ExternalEncoder ( encoderName,
inFileName,
inSampleRate,
inBitsPerSample,
inChannel,
outFileName,
outBitrate,
outSampleRate,
outChannel )
{
init( lowpass, highpass);
}
/**
* Constructor.
*
* @param encoderName name of the encoder.
* (the command to invoke the encoder with)
* @param inFileName input file parameter for the encoder.
* @param as get input sample rate, bits per sample and channels
* from this AudioSource.
* @param outFileName output file parameter for the encoder.
* @param outBitrate bit rate of the output (bits/sec).
* @param outSampleRate sample rate of the output.
* If 0, inSampleRate is used.
* @param outChannel number of channels of the output.
* If 0, inChannel is used.
* @param lowpass frequency threshold for the lowpass filter.
* Input above this frequency is cut.
* If 0, lame's default values are used,
* which depends on the out sample rate.
* @param highpass frequency threshold for the highpass filter.
* Input below this frequency is cut.
* If 0, lame's default values are used,
* which depends on the out sample rate.
* @exception Exception
*/
inline
LameEncoder ( const char * encoderName,
const char * inFileName,
const AudioSource * as,
const char * outFileName,
unsigned int outBitrate,
unsigned int outSampleRate = 0,
unsigned int outChannel = 0,
unsigned int lowpass = 0,
unsigned int highpass = 0 )
throw ( Exception )
: ExternalEncoder ( encoderName,
inFileName,
as,
outFileName,
outBitrate,
outSampleRate,
outChannel )
{
init( lowpass, highpass);
}
/**
* Copy constructor.
*
* @param encoder the LameEncoder to copy.
*/
inline
LameEncoder ( const LameEncoder & encoder ) throw ( Exception )
: ExternalEncoder( encoder )
{
init( encoder.lowpass, encoder.highpass);
}
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~LameEncoder ( void ) throw ( Exception )
{
strip();
}
/**
* Assignment operator.
*
* @param encoder the LameEncoder to assign this to.
* @return a reference to this LameEncoder.
* @exception Exception
*/
inline virtual LameEncoder &
operator= ( const LameEncoder & encoder ) throw ( Exception )
{
if ( this != &encoder ) {
strip();
ExternalEncoder::operator=( encoder);
init( encoder.lowpass, encoder.highpass);
}
return *this;
}
/**
* Get the lowpass filter threshold. Sound frequency in Hz,
* from where up the input is cut.
*
* @return the lowpass filter threshold.
*/
inline unsigned int
getLowpass ( void ) const throw ()
{
return lowpass;
}
/**
* Set the lowpass filter threshold. Sound frequency in Hz,
* from where up the input is cut.
* Can be only set if encoding is not in progress.
*
* @param lowpass the lowpass filter threshold.
* @return if setting is successful.
*/
inline bool
setLowpass ( unsigned int lowpass ) throw ()
{
if ( isRunning() ) {
return false;
} else {
this->lowpass = lowpass;
return true;
}
}
/**
* Get the highpass filter threshold. Sound frequency in Hz,
* from where down the input is cut.
*
* @return the highpass filter threshold.
*/
inline unsigned int
getHighpass ( void ) const throw ()
{
return highpass;
}
/**
* Set the highpass filter threshold. Sound frequency in Hz,
* from where down the input is cut.
* Can be only set if encoding is not in progress.
*
* @param highpass the highpass filter threshold.
* @return if setting is successful.
*/
inline bool
setHighpass ( unsigned int highpass ) throw ()
{
if ( isRunning() ) {
return false;
} else {
this->highpass = highpass;
return true;
}
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* LAME_ENCODER_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.1.1.1 2000/11/05 10:05:52 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,48 @@
bin_PROGRAMS = darkice
INCLUDES = -I../stl
CXXFLAGS = -g -Wall
darkice_SOURCES = AudioEncoder.h\
AudioSource.h\
BufferedSink.cpp\
BufferedSink.h\
CastSink.cpp\
CastSink.h\
Connector.cpp\
Connector.h\
DarkIce.cpp\
DarkIce.h\
Exception.cpp\
Exception.h\
ExternalEncoder.cpp\
ExternalEncoder.h\
FileSink.cpp\
FileSink.h\
FileSource.cpp\
FileSource.h\
IceCast.cpp\
IceCast.h\
LameEncoder.cpp\
LameEncoder.h\
OssDspSource.cpp\
OssDspSource.h\
PipeSink.cpp\
PipeSink.h\
PipeSource.cpp\
PipeSource.h\
Ref.h\
Referable.h\
Sink.h\
Source.h\
TcpSocket.cpp\
TcpSocket.h\
Util.cpp\
Util.h\
ConfigSection.h\
ConfigSection.cpp\
Config.h\
Config.cpp\
Reporter.h\
Reporter.cpp\
main.cpp

View File

@ -0,0 +1,289 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : OssDspSource.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistd.h
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#else
#error need sys/stat.h
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#error need fcntl.h
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#error need sys/time.h
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#else
#error need sys/ioctl.h
#endif
#ifdef HAVE_SYS_SOUNDCARD_H
#include <sys/soundcard.h>
#else
#error need sys/soundcard.h
#endif
#include "Util.h"
#include "Exception.h"
#include "OssDspSource.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
OssDspSource :: init ( const char * name ) throw ( Exception )
{
fileName = Util::strDup( name);
fileDescriptor = 0;
running = false;
}
/*------------------------------------------------------------------------------
* De-initialize the object
*----------------------------------------------------------------------------*/
void
OssDspSource :: strip ( void ) throw ( Exception )
{
if ( isOpen() ) {
close();
}
delete[] fileName;
}
/*------------------------------------------------------------------------------
* Open the audio source
*----------------------------------------------------------------------------*/
bool
OssDspSource :: open ( void ) throw ( Exception )
{
int format;
int i;
unsigned int u;
if ( isOpen() ) {
return false;
}
switch ( getBitsPerSample() ) {
case 8:
format = AFMT_U8;
break;
case 16:
format = AFMT_S16_LE;
break;
default:
return false;
}
if ( (fileDescriptor = ::open( fileName, O_RDONLY)) == -1 ) {
fileDescriptor = 0;
return false;
}
i = format;
if ( ioctl( fileDescriptor, SNDCTL_DSP_SETFMT, &i) == -1 ||
i != format ) {
close();
throw Exception( __FILE__, __LINE__, "can't set format", i);
}
u = getChannel();
if ( ioctl( fileDescriptor, SNDCTL_DSP_CHANNELS, &u) == -1 ||
u != getChannel() ) {
close();
throw Exception( __FILE__, __LINE__, "can't set channels", u);
}
u = getSampleRate();
if ( ioctl( fileDescriptor, SNDCTL_DSP_SPEED, &u) == -1 ||
u != getSampleRate() ) {
close();
throw Exception( __FILE__, __LINE__, "can't set speed", u);
}
return true;
}
/*------------------------------------------------------------------------------
* Check wether read() would return anything
*----------------------------------------------------------------------------*/
bool
OssDspSource :: canRead ( unsigned int sec,
unsigned int usec ) throw ( Exception )
{
fd_set fdset;
struct timeval tv;
int ret;
if ( !isOpen() ) {
return false;
}
if ( !running ) {
/* ugly workaround to get the dsp into recording state */
unsigned char b[getChannel()*getBitsPerSample()/8];
read( b, getChannel()*getBitsPerSample()/8);
}
FD_ZERO( &fdset);
FD_SET( fileDescriptor, &fdset);
tv.tv_sec = sec;
tv.tv_usec = usec;
ret = select( fileDescriptor + 1, &fdset, NULL, NULL, &tv);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "select error");
}
return ret > 0;
}
/*------------------------------------------------------------------------------
* Read from the audio source
*----------------------------------------------------------------------------*/
unsigned int
OssDspSource :: read ( void * buf,
unsigned int len ) throw ( Exception )
{
ssize_t ret;
if ( !isOpen() ) {
return 0;
}
ret = ::read( fileDescriptor, buf, len);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "read error");
}
running = true;
return ret;
}
/*------------------------------------------------------------------------------
* Close the audio source
*----------------------------------------------------------------------------*/
void
OssDspSource :: close ( void ) throw ( Exception )
{
if ( !isOpen() ) {
return;
}
::close( fileDescriptor);
fileDescriptor = 0;
running = false;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.6 2000/12/01 15:03:28 darkeye
bug fix in error reporting
Revision 1.5 2000/11/17 15:50:48 darkeye
added -Wall flag to compiler and eleminated new warnings
Revision 1.4 2000/11/13 20:05:07 darkeye
changed to workaround to start recording so that it reads one sample
per channel, as opposed to only one sample (which misalignes the channels)
Revision 1.3 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 14:08:28 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:53 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,264 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : OssDspSource.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef OSS_DSP_SOURCE_H
#define OSS_DSP_SOURCE_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "AudioSource.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An audio input based on /dev/dsp-like raw devices
*
* @author $Author$
* @version $Revision$
*/
class OssDspSource : public AudioSource
{
private:
/**
* The file name of the OSS DSP device (e.g. /dev/dsp or /dev/dsp0).
*/
char * fileName;
/**
* The low-level file descriptor of the OSS DSP device.
*/
int fileDescriptor;
/**
* Indicates wether the low-level OSS DSP device is in a recording
* state.
*/
bool running;
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
OssDspSource ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Initialize the object
*
* @param name the file name of the OSS DSP device.
* @exception Exception
*/
void
init ( const char * name ) throw ( Exception );
/**
* De-iitialize the object
*
* @exception Exception
*/
void
strip ( void ) throw ( Exception );
public:
/**
* Constructor.
*
* @param name the file name of the OSS DSP device
* (e.g. /dev/dsp or /dev/dsp0).
* @param sampleRate samples per second (e.g. 44100 for 44.1kHz).
* @param bitsPerSample bits per sample (e.g. 16 bits).
* @param channel number of channels of the audio source
* (e.g. 1 for mono, 2 for stereo, etc.).
* @exception Exception
*/
inline
OssDspSource ( const char * name,
int sampleRate = 44100,
int bitsPerSample = 16,
int channel = 2 )
throw ( Exception )
: AudioSource( sampleRate, bitsPerSample, channel)
{
init( name);
}
/**
* Copy Constructor.
*
* @param source the object to copy.
* @exception Exception
*/
inline
OssDspSource ( const OssDspSource & ds ) throw ( Exception )
: AudioSource( ds )
{
init( ds.fileName);
}
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~OssDspSource ( void ) throw ( Exception )
{
strip();
}
/**
* Assignment operator.
*
* @param ds the object to assign to this one.
* @return a reference to this object.
* @exception Exception
*/
inline virtual OssDspSource &
operator= ( const OssDspSource & ds ) throw ( Exception )
{
if ( this != &ds ) {
strip();
AudioSource::operator=( ds);
init( ds.fileName);
}
return *this;
}
/**
* Open the OssDspSource.
* This does not put the OSS DSP device into recording mode.
* To start getting samples, call either canRead() or read().
*
* @return true if opening was successful, false otherwise
* @exception Exception
*
* @see #canRead
* @see #read
*/
virtual bool
open ( void ) throw ( Exception );
/**
* Check if the OssDspSource is open.
*
* @return true if the OssDspSource is open, false otherwise.
*/
inline virtual bool
isOpen ( void ) const throw ()
{
return fileDescriptor != 0;
}
/**
* Check if the OssDspSource can be read from.
* Blocks until the specified time for data to be available.
* Puts the OSS DSP device into recording mode.
*
* @param sec the maximum seconds to block.
* @param usec micro seconds to block after the full seconds.
* @return true if the OssDspSource is ready to be read from,
* false otherwise.
* @exception Exception
*/
virtual bool
canRead ( unsigned int sec,
unsigned int usec ) throw ( Exception );
/**
* Read from the OssDspSource.
* Puts the OSS DSP device into recording mode.
*
* @param buf the buffer to read into.
* @param len the number of bytes to read into buf
* @return the number of bytes read (may be less than len).
* @exception Exception
*/
virtual unsigned int
read ( void * buf,
unsigned int len ) throw ( Exception );
/**
* Close the OssDspSource.
*
* @exception Exception
*/
virtual void
close ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* OSS_DSP_SOURCE_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.1.1.1 2000/11/05 10:05:53 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,144 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : PipeSink.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#else
#error need sys/stat.h
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#error need fcntl.h
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#else
#error need errno.h
#endif
#include "Exception.h"
#include "PipeSink.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Create a pipe
*----------------------------------------------------------------------------*/
bool
PipeSink :: create ( void ) throw ( Exception )
{
if ( isOpen() ) {
return false;
}
if ( mkfifo( getFileName(), S_IRUSR | S_IWUSR) == -1 ) {
if ( errno == EEXIST ) {
return true;
}
throw Exception( __FILE__, __LINE__, "mkfifo error", errno);
}
return true;
}
/*------------------------------------------------------------------------------
* Open the file
*----------------------------------------------------------------------------*/
bool
PipeSink :: open ( void ) throw ( Exception )
{
if ( isOpen() ) {
return false;
}
if ( (fileDescriptor = ::open( getFileName(), O_WRONLY, 0)) == -1 ) {
fileDescriptor = 0;
return false;
}
return true;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.5 2000/11/17 15:50:48 darkeye
added -Wall flag to compiler and eleminated new warnings
Revision 1.4 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.3 2000/11/10 20:10:46 darkeye
changed from non-blocking to blocking
Revision 1.2 2000/11/05 14:08:28 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:53 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,174 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : PipeSink.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef PIPE_SINK_H
#define PIPE_SINK_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "FileSink.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* FIFO pipe data output
*
* @author $Author$
* @version $Revision$
*/
class PipeSink : public FileSink
{
private:
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
PipeSink ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
public:
/**
* Constructor by a pipe name.
*
* @param name name of the pipe to be represented by the object.
* @exception Exception
*/
inline
PipeSink ( const char * name ) throw ( Exception )
: FileSink( name )
{
}
/**
* Copy constructor.
*
* @param fsink the PipeSink to copy.
* @exception Exception
*/
inline
PipeSink ( const PipeSink & ps ) throw ( Exception )
: FileSink( ps )
{
}
/**
* Assignment operator.
*
* @param ps the PipeSink to assign to this object.
* @return a reference to this object.
* @exception Exception
*/
inline virtual PipeSink &
operator= ( const PipeSink & ps ) throw ( Exception )
{
if ( this != &ps ) {
FileSink::operator=( ps );
}
return *this;
}
/**
* Destructor.
*
* @exception Exception
*/
virtual inline
~PipeSink( void ) throw ( Exception )
{
}
/**
* Create the pipe.
*
* @return true if creation was successful, false otherwise.
* @exception Exception
*/
virtual bool
create ( void ) throw ( Exception );
/**
* Open the pipe.
*
* @return true if opening was successful, false otherwise.
* @exception Exception
*/
virtual bool
open ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* PIPE_SINK_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.2 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.1.1.1 2000/11/05 10:05:53 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,122 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : PipeSource.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#else
#error need sys/stat.h
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#error need fcntl.h
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#else
#error need errno.h
#endif
#include "Exception.h"
#include "PipeSource.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Create a pipe
*----------------------------------------------------------------------------*/
bool
PipeSource :: create ( void ) throw ( Exception )
{
if ( isOpen() ) {
return false;
}
if ( mkfifo( getFileName(), S_IRUSR | S_IWUSR) == -1 ) {
if ( errno == EEXIST ) {
return true;
}
throw Exception( __FILE__, __LINE__, "mkfifo error", errno);
}
return true;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/17 15:50:48 darkeye
added -Wall flag to compiler and eleminated new warnings
Revision 1.3 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 14:08:28 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:53 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,169 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : PipeSource.h
Version : $Revision$
Author : $Author$
Location : $Source$
Abstract :
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef PIPE_SOURCE_H
#define PIPE_SOURCE_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "FileSource.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* FIFO pipe data input
*
* @author $Author$
* @version $Revision$
*/
class PipeSource : public FileSource
{
private:
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
PipeSource ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
public:
/**
* Constructor by a file name.
*
* @param name name of the file to be represented by the object.
* @exception Exception
*/
inline
PipeSource ( const char * name ) throw ( Exception )
: FileSource( name )
{
}
/**
* Copy constructor.
*
* @param ps the PipeSource to copy.
* @exception Exception
*/
inline
PipeSource ( const PipeSource & ps ) throw ( Exception )
: FileSource( ps )
{
}
/**
* Assignment operator.
*
* @param ps the PipeSource to assign to this object.
* @return a reference to this object.
* @exception Exception
*/
inline virtual PipeSource &
operator= ( const PipeSource & ps ) throw ( Exception )
{
if ( this != &ps ) {
FileSource::operator=( ps );
}
return *this;
}
/**
* Destructor.
*
* @exception Exception
*/
virtual inline
~PipeSource( void ) throw ( Exception )
{
}
/**
* Create the pipe.
*
* @return true if creation was successful, false otherwise.
* @exception Exception
*/
virtual bool
create ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* PIPE_SOURCE_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.1.1.1 2000/11/05 10:05:53 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,288 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Ref.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef REF_H
#define REF_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Exception.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Java-like object reference class.
* Objects used with this reference class have to be descandents
* of class Referable.
*
* sample usage:
*
* <pre>
* #include "Ref.h"
* #include "Referable.h"
*
* class A : public virtual Referable;
*
* ...
*
* A * a = new A();
* Ref<A> ref1 = a; // 1 reference to a
* Ref<A> ref2 = ref1; // 2 references to a
*
* ref1 = 0; // 1 reference to a
* ref2 = 0; // at this point object a is destroyed
* </pre>
*
* Based on Tima Saarinen's work,
* http://gamma.nic.fi/~timosa/comp/refcount.html
*
* @ref Referable
*
* @author $Author$
* @version $Revision$
*/
template <class T>
class Ref
{
private:
/**
* The object referenced by this Ref.
* Must be a descandant of Referable.
*/
T* object;
protected:
public:
/**
* Default constructor.
*/
inline
Ref ( void ) throw ()
{
object = NULL;
}
/**
* Copy constructor.
*
* @param other the Ref to copy.
* @exception Exception
*/
inline
Ref ( const Ref<T> & other ) throw ( Exception )
{
object = NULL;
set( other.object);
}
/**
* Constructor based on an object to reference.
*
* @param obj the object to reference.
* @exception Exception
*/
inline
Ref ( T * obj ) throw ( Exception )
{
object = obj;
obj->increaseReferenceCount();
}
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~Ref ( void ) throw ( Exception )
{
set( 0 );
}
/**
* Operator overload to make the reference seem like a pointer.
*
* @return the pointer to the object referenced.
*/
inline T*
operator->() const throw ()
{
if ( !object ) {
throw Exception( __FILE__, __LINE__,
"reference to NULL object");
}
return object;
}
/**
* Assignment operator.
*
* @param other the Ref to assign to this one.
* @return a reference to this Ref.
* @exception Exception
*/
inline Ref<T> &
operator= ( Ref<T> other ) throw ( Exception )
{
set( other.object);
return *this;
}
/**
* Assignment operator.
*
* @param obj pointer to the object to assign to this Ref.
* @return a reference to this Ref.
* @exception Exception
*/
inline Ref<T> &
operator= ( T* obj ) throw ( Exception )
{
set( obj);
return *this;
}
/**
* Set the object referenced.
* Deletes the old referenced object is this was it's last reference.
*
* @param newobj pointer to the object to reference by this Ref.
* @exception Exception
*/
inline void
set ( T* newobj ) throw ( Exception )
{
// If equal do nothing
if ( newobj == object ) {
return;
}
// Increase reference count
if ( newobj ) {
newobj->increaseReferenceCount();
}
// Decrease the reference count of the old referable
if ( object ) {
if ( object->decreaseReferenceCount() == 0 ) {
delete object;
}
}
// Assign
object = newobj;
}
/**
* Return object pointer. This method should be used with
* care because it breaks the encapsulation.
* Typically this method is needed for the method calls
* which require literal object pointer.
*
* It may not be bad idea to pass the Ref
* objects as method arguments.
*
* @return Object pointer or NULL.
*/
inline T*
get ( void ) const throw ()
{
return object;
}
/**
* Equality operator.
*
* @param other the Ref to compare this with.
* @return true is the two Refs refer to the same object,
* false otherwise.
*/
inline bool
operator== ( const Ref<T> & other ) const throw ()
{
return object == other.object;
}
/**
* Unequality operator.
*
* @param other the Ref to compare this with.
* @return false is the two Refs refer to the same object,
* true otherwise.
*/
inline bool
operator!= ( const Ref<T> & other ) const throw ()
{
return object != other.object;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* REF_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/11 14:55:31 darkeye
minor bugfix
Revision 1.2 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.1.1.1 2000/11/05 10:05:54 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,185 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Referable.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef REFERABLE_H
#define REFERABLE_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Exception.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Base class for an object for which references can be made
* with the reference class Ref.
*
* usage:
*
* <pre>
* class A : public virtual Referable
* {
* ...
* };
* </pre>
*
* @ref Ref
*
* @author $Author$
* @version $Revision$
*/
class Referable
{
private:
/**
* Number of references to the object.
*/
unsigned int referenceCount;
/**
* Maximum number of references before an overflow occurs.
*/
static const
unsigned int maxCount = ~((unsigned int)0);
protected:
/**
* Default constructor.
*/
inline
Referable ( void ) throw ()
{
referenceCount = 0;
}
/**
* Desctructor.
*
* @exception Exception
*/
inline virtual
~Referable ( void ) throw ( Exception )
{
if ( referenceCount > 0 ) {
throw Exception( __FILE__, __LINE__,
"reference count positive in destructor",
referenceCount);
}
}
public:
/**
* Increase reference count.
*
* @return the new reference count.
* @exception Exception
*/
inline unsigned int
increaseReferenceCount ( void ) throw ( Exception )
{
if ( referenceCount >= maxCount ) {
throw Exception( __FILE__,
__LINE__,
"reference count overflow",
referenceCount );
}
return ++referenceCount;
}
/**
* Decrease reference count.
*
* @return the new reference count.
* @exception Exception
*/
inline unsigned int
decreaseReferenceCount ( void ) throw ( Exception )
{
if ( referenceCount == 0 ) {
throw Exception( __FILE__, __LINE__,
"reference count underflow",
referenceCount );
}
return --referenceCount;
}
/**
* Get the reference count.
*
* @return the reference count.
*/
inline unsigned int
getReferenceCount ( void ) const throw ()
{
return referenceCount;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* REFERABLE_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.2 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.1.1.1 2000/11/05 10:05:54 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,74 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell Reporter
File : Reporter.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include <iostream.h>
#include "Reporter.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/*------------------------------------------------------------------------------
* Initial values for static members of the class
*----------------------------------------------------------------------------*/
unsigned int Reporter::verbosity = 1;
ostream * Reporter::os = &cout;
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.1 2000/11/16 08:48:43 darkeye
added multiple verbosity-level event reporting and verbosity command
line option
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,325 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell Reporter
File : Reporter.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef REPORTER_H
#define REPORTER_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistdt.h
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#else
#error need time.h
#endif
#include <iostream.h>
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Class for reporting events. All objects of this class share
* the same verbosity level. Typical usage is to inherit this class
* and use the report() function to report events. Only reports
* which are of suffucient importance are really reported.
*
* The default verbosity is 1, and the default ostream is cout.
*
* Known problems: this class is not thread-safe.
*
* @author $Author$
* @version $Revision$
*/
class Reporter
{
private:
/**
* Verbosity level shared among all Reporter objects
*/
static unsigned int verbosity;
/**
* The output stream to report to.
*/
static ostream * os;
/**
* Print timestamp for every report only if verbosity level
* is above this value.
*/
static const unsigned int prefixVerbosity = 3;
/**
* Print a prefix to each report.
*/
void
printPrefix( void ) throw ()
{
if ( verbosity > prefixVerbosity ) {
char str[32];
time_t now;
now = time(NULL);
strftime( str, 32, "%H:%M:%S: ", localtime(&now) );
(*(Reporter::os)) << str;
}
}
protected:
public:
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~Reporter ( void ) throw ()
{
(Reporter::os)->flush();
}
/**
* Set the verbosity level. This sets the verbosity for all
* Reporter objects.
*
* @param verbosity the new verbosity level.
*/
inline void
setReportVerbosity ( unsigned int verbosity ) throw ()
{
Reporter::verbosity = verbosity;
}
/**
* Get the verbosity level.
*
* @return the current verbosity level.
*/
inline unsigned int
getReportVerbosity ( void ) throw ()
{
return Reporter::verbosity;
}
/**
* Set the output stream to report to. This setting effects all
* Reporter objects.
*
* @param os the output stream
*/
inline void
setReportOutputStream ( ostream & os ) throw ()
{
Reporter::os = &os;
}
/**
* Get the output stream to report to.
*
* @return the output stream
*/
inline ostream &
getReportOutputStream ( void ) throw ()
{
return *(Reporter::os);
}
/**
* Report an event with a given verbosity.
*
* @param verbosity the importance of the event, with 0 being
* the most important.
* @param t the object to report. Must have an
* <code>ostream & operator<<( ostream&, const T)</code>
* operator overload.
*/
template<class T>
inline void
reportEvent ( unsigned int verbosity,
const T t ) throw ()
{
if ( Reporter::verbosity >= verbosity ) {
printPrefix();
(*(Reporter::os)) << t << endl;
}
}
/**
* Report an event with a given verbosity.
*
* @param verbosity the importance of the event, with 0 being
* the most important.
* @param t the object 1 to report. Must have an
* <code>ostream & operator<<( ostream&, const T)</code>
* operator overload.
* @param u the object 2 to report. Must have an
* <code>ostream & operator<<( ostream&, const U)</code>
* operator overload.
*/
template<class T, class U>
inline void
reportEvent ( unsigned int verbosity,
const T t,
const U u ) throw ()
{
if ( Reporter::verbosity >= verbosity ) {
printPrefix();
(*(Reporter::os)) << t << " "
<< u << endl;
}
}
/**
* Report an event with a given verbosity.
*
* @param verbosity the importance of the event, with 0 being
* the most important.
* @param t the object 1 to report. Must have an
* <code>ostream & operator<<( ostream&, const T)</code>
* operator overload.
* @param u the object 2 to report. Must have an
* <code>ostream & operator<<( ostream&, const U)</code>
* operator overload.
* @param v the object 3 to report. Must have an
* <code>ostream & operator<<( ostream&, const V)</code>
* operator overload.
*/
template<class T, class U, class V>
inline void
reportEvent ( unsigned int verbosity,
const T t,
const U u,
const V v ) throw ()
{
if ( Reporter::verbosity >= verbosity ) {
printPrefix();
(*(Reporter::os)) << t << " "
<< u << " "
<< v << endl;
}
}
/**
* Report an event with a given verbosity.
*
* @param verbosity the importance of the event, with 0 being
* the most important.
* @param t the object 1 to report. Must have an
* <code>ostream & operator<<( ostream&, const T)</code>
* operator overload.
* @param u the object 2 to report. Must have an
* <code>ostream & operator<<( ostream&, const U)</code>
* operator overload.
* @param v the object 3 to report. Must have an
* <code>ostream & operator<<( ostream&, const V)</code>
* operator overload.
* @param w the object 4 to report. Must have an
* <code>ostream & operator<<( ostream&, const W)</code>
* operator overload.
*/
template<class T, class U, class V, class W>
inline void
reportEvent ( unsigned int verbosity,
const T t,
const U u,
const V v,
const W w ) throw ()
{
if ( Reporter::verbosity >= verbosity ) {
printPrefix();
(*(Reporter::os)) << t << " "
<< u << " "
<< v << " "
<< w << endl;
}
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* REPORTER_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/12/20 12:47:40 darkeye
added prefixVerbosity value. in a low verbosity setting no time-stamp
prefix is displayed
Revision 1.2 2000/11/18 11:12:01 darkeye
added timestamp display, removed process id display in reports
changed reportEvent functions to template functions
Revision 1.1 2000/11/16 08:48:43 darkeye
added multiple verbosity-level event reporting and verbosity command
line option
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,198 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Sink.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef SINK_H
#define SINK_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Referable.h"
#include "Exception.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A general data sink
*
* @author $Author$
* @version $Revision$
*/
class Sink : public virtual Referable
{
private:
protected:
/**
* Default constructor.
*/
inline
Sink ( void ) throw ()
{
}
/**
* Copy constructor.
*
* @param sink the Sink to copy.
*/
inline
Sink ( const Sink & sink ) throw ()
{
}
/**
* Assignment operator.
*
* @param sink the Sink to assign this to.
* @return a reference to this Sink.
* @exception Exception
*/
inline virtual Sink &
operator= ( const Sink & sink ) throw ( Exception )
{
return *this;
}
public:
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~Sink ( void ) throw ( Exception )
{
}
/**
* Open the sink.
*
* @return true if opening was successfull, false otherwise.
* @exception Exception
*/
virtual bool
open ( void ) throw ( Exception ) = 0;
/**
* Check if the Sink is open.
*
* @return true if the Sink is open, false otherwise.
*/
virtual bool
isOpen ( void ) const throw () = 0;
/**
* Check if the Sink is ready to accept data.
* Blocks until the specified time for data to be available.
*
* @param sec the maximum seconds to block.
* @param usec micro seconds to block after the full seconds.
* @return true if the Sink is ready to accept data, false otherwise.
* @exception Exception
*/
virtual bool
canWrite ( unsigned int sec,
unsigned int usec ) throw ( Exception ) = 0;
/**
* Write data to the Sink.
*
* @param buf the data to write.
* @param len number of bytes to write from buf.
* @return the number of bytes written (may be less than len).
* @exception Exception
*/
virtual unsigned int
write ( const void * buf,
unsigned int len ) throw ( Exception ) = 0;
/**
* Flush all data that was written to the Sink to the underlying
* construct.
*
* @exception Exception
*/
virtual void
flush ( void ) throw ( Exception ) = 0;
/**
* Close the Sink.
*
* @exception Exception
*/
virtual void
close ( void ) throw ( Exception ) = 0;
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* SINK_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/12 14:54:25 darkeye
added Exception to throws clause for the destructor and assignment operator
Revision 1.3 2000/11/12 13:31:16 darkeye
minor change in documentation
Revision 1.2 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.1.1.1 2000/11/05 10:05:54 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,186 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Source.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef SOURCE_H
#define SOURCE_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Referable.h"
#include "Exception.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A general data source
*
* @author $Author$
* @version $Revision$
*/
class Source : public virtual Referable
{
private:
protected:
/**
* Default Constructor.
*
* @exception Exception
*/
inline
Source ( void ) throw ( Exception )
{
}
/**
* Copy Constructor.
*
* @param source the object to copy.
* @exception Exception
*/
inline
Source ( const Source & source ) throw ( Exception )
{
}
/**
* Assignment operator.
*
* @param source the object to assign to this one.
* @return a reference to this object.
* @exception Exception
*/
inline virtual Source &
operator= ( const Source & source ) throw ( Exception )
{
return *this;
}
public:
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~Source ( void ) throw ( Exception )
{
}
/**
* Open the Source.
*
* @return true if opening was successful, false otherwise
* @exception Exception
*/
virtual bool
open ( void ) throw ( Exception ) = 0;
/**
* Check if the Source is open.
*
* @return true if the Source is open, false otherwise.
*/
virtual bool
isOpen ( void ) const throw () = 0;
/**
* Check if the Source can be read from.
* Blocks until the specified time for data to be available.
*
* @param sec the maximum seconds to block.
* @param usec micro seconds to block after the full seconds.
* @return true if the Source is ready to be read from,
* false otherwise.
* @exception Exception
*/
virtual bool
canRead ( unsigned int sec,
unsigned int usec ) throw ( Exception ) = 0;
/**
* Read from the Source.
*
* @param buf the buffer to read into.
* @param len the number of bytes to read into buf
* @return the number of bytes read (may be less than len).
* @exception Exception
*/
virtual unsigned int
read ( void * buf,
unsigned int len ) throw ( Exception ) = 0;
/**
* Close the Source.
*
* @exception Exception
*/
virtual void
close ( void ) throw ( Exception ) = 0;
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* SOURCE_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.2 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.1.1.1 2000/11/05 10:05:54 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,365 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : TcpSocket.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#else
#error need errno.h
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#else
#error need sys/socket.h
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#else
#error need netinet/in.h
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#else
#error need netdb.h
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistd.h
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#error need sys/time.h
#endif
#include "Util.h"
#include "Exception.h"
#include "TcpSocket.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
TcpSocket :: init ( const char * host,
unsigned short port ) throw ( Exception )
{
this->host = Util::strDup( host);
this->port = port;
this->sockfd = 0;
}
/*------------------------------------------------------------------------------
* De-initialize the object
*----------------------------------------------------------------------------*/
void
TcpSocket :: strip ( void) throw ( Exception )
{
if ( isOpen() ) {
close();
}
delete[] host;
}
/*------------------------------------------------------------------------------
* Copy Constructor
*----------------------------------------------------------------------------*/
TcpSocket :: TcpSocket ( const TcpSocket & ss ) throw ( Exception )
: Source( ss), Sink( ss )
{
int fd;
init( ss.host, ss.port);
if ( (fd = ss.sockfd ? dup( ss.sockfd) : 0) == -1 ) {
strip();
throw Exception( __FILE__, __LINE__, "dup failure");
}
sockfd = fd;
}
/*------------------------------------------------------------------------------
* Assignment operator
*----------------------------------------------------------------------------*/
TcpSocket &
TcpSocket :: operator= ( const TcpSocket & ss ) throw ( Exception )
{
if ( this != &ss ) {
int fd;
/* first strip */
strip();
/* then build up */
Sink::operator=( ss );
Source::operator=( ss );
init( ss.host, ss.port);
if ( (fd = ss.sockfd ? dup( ss.sockfd) : 0) == -1 ) {
strip();
throw Exception( __FILE__, __LINE__, "dup failure");
}
sockfd = fd;
}
return *this;
}
/*------------------------------------------------------------------------------
* Open the file
*----------------------------------------------------------------------------*/
bool
TcpSocket :: open ( void ) throw ( Exception )
{
struct sockaddr_in addr;
struct hostent * pHostEntry;
if ( isOpen() ) {
return false;
}
if ( !(pHostEntry = gethostbyname( host)) ) {
throw Exception( __FILE__, __LINE__, "gethostbyname error", errno);
}
if ( (sockfd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 ) {
throw Exception( __FILE__, __LINE__, "socket error", errno);
}
memset( &addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = *((long*) pHostEntry->h_addr_list[0]);
if ( connect( sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1 ) {
::close( sockfd);
throw Exception( __FILE__, __LINE__, "connect error", errno);
}
return true;
}
/*------------------------------------------------------------------------------
* Check wether read() would return anything
*----------------------------------------------------------------------------*/
bool
TcpSocket :: canRead ( unsigned int sec,
unsigned int usec ) throw ( Exception )
{
fd_set fdset;
struct timeval tv;
int ret;
if ( !isOpen() ) {
return false;
}
FD_ZERO( &fdset);
FD_SET( sockfd, &fdset);
tv.tv_sec = sec;
tv.tv_usec = usec;
ret = select( sockfd + 1, &fdset, NULL, NULL, &tv);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "select error");
}
return ret > 0;
}
/*------------------------------------------------------------------------------
* Read from the socket
*----------------------------------------------------------------------------*/
unsigned int
TcpSocket :: read ( void * buf,
unsigned int len ) throw ( Exception )
{
int ret;
if ( !isOpen() ) {
return 0;
}
ret = recv( sockfd, buf, len, 0);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "recv error", errno);
}
return ret;
}
/*------------------------------------------------------------------------------
* Check wether read() would return anything
*----------------------------------------------------------------------------*/
bool
TcpSocket :: canWrite ( unsigned int sec,
unsigned int usec ) throw ( Exception )
{
fd_set fdset;
struct timeval tv;
int ret;
if ( !isOpen() ) {
return false;
}
FD_ZERO( &fdset);
FD_SET( sockfd, &fdset);
tv.tv_sec = sec;
tv.tv_usec = usec;
ret = select( sockfd + 1, NULL, &fdset, NULL, &tv);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "select error");
}
return ret > 0;
}
/*------------------------------------------------------------------------------
* Write to the socket
*----------------------------------------------------------------------------*/
unsigned int
TcpSocket :: write ( const void * buf,
unsigned int len ) throw ( Exception )
{
int ret;
if ( !isOpen() ) {
return 0;
}
// ret = send( sockfd, buf, len, MSG_DONTWAIT);
ret = send( sockfd, buf, len, 0);
if ( ret == -1 ) {
if ( errno == EAGAIN ) {
ret = 0;
} else {
throw Exception( __FILE__, __LINE__, "send error", errno);
}
}
return ret;
}
/*------------------------------------------------------------------------------
* Close the socket
*----------------------------------------------------------------------------*/
void
TcpSocket :: close ( void ) throw ( Exception )
{
if ( !isOpen() ) {
return;
}
flush();
::close( sockfd);
sockfd = 0;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/17 15:50:48 darkeye
added -Wall flag to compiler and eleminated new warnings
Revision 1.3 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 14:08:28 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:55 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,297 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : TcpSocket.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef TCP_SOCKET_H
#define TCP_SOCKET_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Source.h"
#include "Sink.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A TCP network socket
*
* @author $Author$
* @version $Revision$
*/
class TcpSocket : public Source, public Sink
{
private:
/**
* Name of the host this socket connects to.
*/
char * host;
/**
* Port to connect to.
*/
unsigned short port;
/**
* Low-level socket descriptor.
*/
int sockfd;
/**
* Initialize the object.
*
* @param host name of the host this socket connects to.
* @param port port to connect to.
* @exception Exception
*/
void
init ( const char * host,
unsigned short port ) throw ( Exception );
/**
* De-initialize the object.
*
* @exception Exception
*/
void
strip ( void ) throw ( Exception );
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
TcpSocket ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
public:
/**
* Constructor.
*
* @param host name of the host this socket connects to.
* @param port port to connect to.
* @exception Exception
*/
inline
TcpSocket( const char * host,
unsigned short port ) throw ( Exception )
{
init( host, port);
}
/**
* Copy constructor.
*
* @param ss the TcpSocket to copy.
* @exception Exception
*/
TcpSocket( const TcpSocket & ss ) throw ( Exception );
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~TcpSocket( void ) throw ( Exception )
{
strip();
}
/**
* Assignment operator.
*
* @param ss the TcpSocket to assign this to.
* @return a reference to this TcpSocket.
* @exception Exception
*/
inline virtual TcpSocket &
operator= ( const TcpSocket & ss ) throw ( Exception );
/**
* Get the host this socket connects to.
*
* @return the host this socket connects to.
*/
inline const char *
getHost ( void ) const throw ()
{
return host;
}
/**
* Get the port this socket connects to.
*
* @return the port this socket connects to.
*/
inline unsigned int
getPort ( void ) const throw ()
{
return port;
}
/**
* Open the TcpSocket.
*
* @return true if opening was successfull, false otherwise.
* @exception Exception
*/
virtual bool
open ( void ) throw ( Exception );
/**
* Check if the TcpSocket is open.
*
* @return true if the TcpSocket is open, false otherwise.
*/
inline virtual bool
isOpen ( void ) const throw ()
{
return sockfd != 0;
}
/**
* Check if the TcpScoket can be read from.
* Blocks until the specified time for data to be available.
*
* @param sec the maximum seconds to block.
* @param usec micro seconds to block after the full seconds.
* @return true if the TcpSocket is ready to be read from,
* false otherwise.
* @exception Exception
*/
virtual bool
canRead ( unsigned int sec,
unsigned int usec ) throw ( Exception );
/**
* Read from the TcpSocket.
*
* @param buf the buffer to read into.
* @param len the number of bytes to read into buf
* @return the number of bytes read (may be less than len).
* @exception Exception
*/
virtual unsigned int
read ( void * buf,
unsigned int len ) throw ( Exception );
/**
* Check if the TcpSocket is ready to accept data.
* Blocks until the specified time for data to be available.
*
* @param sec the maximum seconds to block.
* @param usec micro seconds to block after the full seconds.
* @return true if the TcpSocket is ready to accept data,
* false otherwise.
* @exception Exception
*/
virtual bool
canWrite ( unsigned int sec,
unsigned int usec ) throw ( Exception );
/**
* Write data to the TcpSocket.
*
* @param buf the data to write.
* @param len number of bytes to write from buf.
* @return the number of bytes written (may be less than len).
* @exception Exception
*/
virtual unsigned int
write ( const void * buf,
unsigned int len ) throw ( Exception );
/**
* Flush all data that was written to the TcpSocket to the underlying
* connection.
*
* @exception Exception
*/
inline virtual void
flush ( void ) throw ( Exception )
{
}
/**
* Close the TcpSocket.
*
* @exception Exception
*/
virtual void
close ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* TCP_SOCKET_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/12 14:54:50 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 17:37:24 darkeye
removed clone() functions
Revision 1.1.1.1 2000/11/05 10:05:55 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,206 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Util.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#else
#error need stdlib.h
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#else
#error need limits.h
#endif
#include "Util.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Calculate the length of a zero-terminated C string,
* w/o the zero-termination
*----------------------------------------------------------------------------*/
unsigned int
Util :: strLen( const char * str ) throw ( Exception )
{
size_t len;
if ( !str ) {
throw Exception( __FILE__, __LINE__, "no str");
}
len = strlen( str);
return len;
}
/*------------------------------------------------------------------------------
* Copy the contents of a string into another
*----------------------------------------------------------------------------*/
void
Util :: strCpy ( char * dest,
const char * src ) throw ( Exception )
{
if ( !dest || !src ) {
throw Exception( __FILE__, __LINE__, "no src or dest");
}
strcpy( dest, src);
}
/*------------------------------------------------------------------------------
* Concatenate the contents of a string onto another
*----------------------------------------------------------------------------*/
void
Util :: strCat ( char * dest,
const char * src ) throw ( Exception )
{
if ( !dest || !src ) {
throw Exception( __FILE__, __LINE__, "no src or dest");
}
strcat( dest, src);
}
/*------------------------------------------------------------------------------
* Duplicate a string by allocating space with new[]
* The returned string must be freed with delete[]
*----------------------------------------------------------------------------*/
char *
Util :: strDup( const char * str ) throw ( Exception )
{
size_t len;
char * s;
if ( !str ) {
throw Exception( __FILE__, __LINE__, "no str");
}
len = strlen( str) + 1;
s = new char[len];
memcpy( s, str, len);
return s;
}
/*------------------------------------------------------------------------------
* Check wether two strings are equal
*----------------------------------------------------------------------------*/
bool
Util :: strEq( const char * str1,
const char * str2 ) throw ( Exception )
{
if ( !str1 || !str2 ) {
throw Exception( __FILE__, __LINE__, "no str1 or no str2");
}
return !strcmp( str1, str2);
}
/*------------------------------------------------------------------------------
* Convert a string to a long integer
*----------------------------------------------------------------------------*/
long int
Util :: strToL( const char * str,
int base ) throw ( Exception )
{
long int val;
char * s;
if ( !str ) {
throw Exception( __FILE__, __LINE__, "no str");
}
val = strtol( str, &s, base);
if ( s == str || val == LONG_MIN || val == LONG_MAX ) {
throw Exception( __FILE__, __LINE__, "number conversion error");
}
return val;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.5 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.4 2000/11/09 22:04:33 darkeye
added functions strLen strCpy and strCat
Revision 1.3 2000/11/09 06:44:21 darkeye
added strEq and strToL functions
Revision 1.2 2000/11/05 14:08:28 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:55 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,222 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : Util.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
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.
------------------------------------------------------------------------------*/
#ifndef UTIL_H
#define UTIL_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Exception.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Widely used utilities.
* This class can not be instantiated, but contains useful (?) static
* functions.
*
* Typical usage:
*
* <pre>
* #include "Util.h"
*
* char * str = Util::strDup( otherStr);
* </pre>
*
* @author $Author$
* @version $Revision$
*/
class Util
{
private:
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
Util ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Copy constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
Util ( const Util & e ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Destructor. Always throws an Exception.
*
* @exception Exception
*/
inline
~Util ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Assignment operator. Always throws an Exception.
*
* @param u the object to assign to this one.
* @exception Exception
*/
inline Util &
operator= ( const Util & u ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
public:
/**
* Determine a C string's length.
*
* @param str a zero-terminated C string.
* @return length of str
* @exception Exception
*/
static unsigned int
strLen ( const char * str ) throw ( Exception );
/**
* Copy a C string into another.
*
* @param dest place for the copy. Storage size must be at least
* Util::strLen(src) + 1 long.
* @param str the string to copy.
* @exception Exception
*/
static void
strCpy ( char * dest,
const char * src ) throw ( Exception );
/**
* Concatenate a string to another's end.
*
* @param dest the string to concatenate to.
* Storage size of dest must be at least
* Util::strLen(dest) + Util::strLen(src) + 1 long.
* @param str the string to concatenate.
* @exception Exception
*/
static void
strCat ( char * dest,
const char * src ) throw ( Exception );
/**
* Duplicate a string by allocating space with new[].
* The returned string must be freed with delete[].
*
* @param str the string to duplicate.
* @exception Exception
*/
static char *
strDup ( const char * str ) throw ( Exception );
/**
* Determine wether two string are equal.
*
* @param str1 one of the strings.
* @param str2 the other string.
* @return true if the two strings are equal, false othersize.
* @exception Exception
*/
static bool
strEq ( const char * str1,
const char * str2 ) throw ( Exception );
/**
* Convert a string to long.
*
* @param str the string to convert.
* @param base numeric base of number in str.
* @return the value of str as a long int
* @exception Exception
*/
static long int
strToL ( const char * str,
int base = 10 ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* UTIL_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.4 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.3 2000/11/09 22:04:33 darkeye
added functions strLen strCpy and strCat
Revision 1.2 2000/11/09 06:44:21 darkeye
added strEq and strToL functions
Revision 1.1.1.1 2000/11/05 10:05:55 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,192 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : main.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Abstract :
Program entry point
Copyright notice:
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.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
#error need getopt.h
#endif
#include <iostream.h>
#include <fstream.h>
#include "Ref.h"
#include "Exception.h"
#include "Util.h"
#include "DarkIce.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/*------------------------------------------------------------------------------
* Show program usage
*----------------------------------------------------------------------------*/
static void
showUsage ( ostream & os );
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Program entry point
*----------------------------------------------------------------------------*/
int
main (
int argc,
char * argv[] )
{
int res = -1;
cout << "DarkIce " << VERSION
<< " live audio streamer, http://darkice.sourceforge.net" << endl;
cout << "Copyright (C) 2000, Tyrell Hungary, http://tyrell.hu" << endl;
cout << endl;
try {
const char * configFileName = 0;
unsigned int verbosity = 1;
int i;
const char opts[] = "hc:v:";
static struct option long_options[] = {
{ "config", 1, 0, 'c'},
{ "help", 0, 0, 'h'},
{ "verbosity", 1, 0, 'v'},
{ 0, 0, 0, 0}
};
while ( (i = getopt_long( argc, argv, opts, long_options, 0)) != -1 ) {
switch ( i ) {
case 'c':
configFileName = optarg;
break;
case 'v':
verbosity = Util::strToL( optarg);
break;
default:
case ':':
case '?':
case 'h':
showUsage( cout);
return 1;
}
}
if ( !configFileName ) {
throw Exception( __FILE__, __LINE__,
"no configuration file specified");
}
cout << "Using config file: " << configFileName << endl;
ifstream configFile( configFileName);
Config config( configFile);
Ref<DarkIce> di = new DarkIce( config);
di->setReportVerbosity( verbosity );
di->setReportOutputStream( cout );
res = di->run();
} catch ( Exception & e ) {
cout << "DarkIce: " << e << endl << flush;
}
return res;
}
/*------------------------------------------------------------------------------
* Show program usage
*----------------------------------------------------------------------------*/
static void
showUsage ( ostream & os )
{
os
<< "usage: darkice -c config.file"
<< endl
<< endl
<< "options:"
<< endl
<< " -c, --config=config.file use configuration file config.file"
<< endl
<< " -v, --verbosity=number verbosity level (0 = silent, 10 = loud)"
<< endl
<< " -h, --help print this message and exit"
<< endl
<< endl;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.5 2000/11/15 18:08:43 darkeye
added multiple verbosity-level event reporting and verbosity command
line option
Revision 1.4 2000/11/13 20:21:29 darkeye
added program version display on startup
Revision 1.3 2000/11/13 19:38:55 darkeye
moved command line parameter parsing from DarkIce.cpp to main.cpp
Revision 1.2 2000/11/08 17:29:50 darkeye
added configuration file reader
Revision 1.1.1.1 2000/11/05 10:05:52 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1 @@
timestamp

View File

@ -0,0 +1,114 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_ALGO_H
#define __SGI_STL_ALGO_H
#include <algobase.h>
#include <tempbuf.h>
#include <stl_algo.h>
#include <stl_numeric.h>
#ifdef __STL_USE_NAMESPACES
// Names from <stl_algo.h>
using __STD::for_each;
using __STD::find;
using __STD::find_if;
using __STD::adjacent_find;
using __STD::count;
using __STD::count_if;
using __STD::search;
using __STD::search_n;
using __STD::swap_ranges;
using __STD::transform;
using __STD::replace;
using __STD::replace_if;
using __STD::replace_copy;
using __STD::replace_copy_if;
using __STD::generate;
using __STD::generate_n;
using __STD::remove;
using __STD::remove_if;
using __STD::remove_copy;
using __STD::remove_copy_if;
using __STD::unique;
using __STD::unique_copy;
using __STD::reverse;
using __STD::reverse_copy;
using __STD::rotate;
using __STD::rotate_copy;
using __STD::random_shuffle;
using __STD::random_sample;
using __STD::random_sample_n;
using __STD::partition;
using __STD::stable_partition;
using __STD::sort;
using __STD::stable_sort;
using __STD::partial_sort;
using __STD::partial_sort_copy;
using __STD::nth_element;
using __STD::lower_bound;
using __STD::upper_bound;
using __STD::equal_range;
using __STD::binary_search;
using __STD::merge;
using __STD::inplace_merge;
using __STD::includes;
using __STD::set_union;
using __STD::set_intersection;
using __STD::set_difference;
using __STD::set_symmetric_difference;
using __STD::min_element;
using __STD::max_element;
using __STD::next_permutation;
using __STD::prev_permutation;
using __STD::find_first_of;
using __STD::find_end;
using __STD::is_sorted;
using __STD::is_heap;
// Names from stl_heap.h
using __STD::push_heap;
using __STD::pop_heap;
using __STD::make_heap;
using __STD::sort_heap;
// Names from <stl_numeric.h>
using __STD::accumulate;
using __STD::inner_product;
using __STD::partial_sum;
using __STD::adjacent_difference;
using __STD::power;
using __STD::iota;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_ALGO_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,71 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_ALGOBASE_H
#define __SGI_STL_ALGOBASE_H
#ifndef __SGI_STL_PAIR_H
#include <pair.h>
#endif
#ifndef __SGI_STL_ITERATOR_H
#include <iterator.h>
#endif
#ifndef __SGI_STL_INTERNAL_ALGOBASE_H
#include <stl_algobase.h>
#endif
#ifndef __SGI_STL_INTERNAL_UNINITIALIZED_H
#include <stl_uninitialized.h>
#endif
#ifdef __STL_USE_NAMESPACES
// Names from stl_algobase.h
using __STD::iter_swap;
using __STD::swap;
using __STD::min;
using __STD::max;
using __STD::copy;
using __STD::copy_backward;
using __STD::copy_n;
using __STD::fill;
using __STD::fill_n;
using __STD::mismatch;
using __STD::equal;
using __STD::lexicographical_compare;
using __STD::lexicographical_compare_3way;
// Names from stl_uninitialized.h
using __STD::uninitialized_copy;
using __STD::uninitialized_copy_n;
using __STD::uninitialized_fill;
using __STD::uninitialized_fill_n;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_ALGOBASE_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,40 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_ALGORITHM
#define __SGI_STL_ALGORITHM
#include <stl_algobase.h>
#include <stl_construct.h>
#include <stl_uninitialized.h>
#include <stl_tempbuf.h>
#include <stl_algo.h>
#endif /* __SGI_STL_ALGORITHM */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 1996-1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_ALLOC_H
#define __SGI_STL_ALLOC_H
#ifndef __STL_CONFIG_H
#include <stl_config.h>
#endif
#ifndef __SGI_STL_INTERNAL_ALLOC_H
#include <stl_alloc.h>
#endif
#ifdef __STL_USE_NAMESPACES
using __STD::__malloc_alloc_template;
using __STD::malloc_alloc;
using __STD::simple_alloc;
using __STD::debug_alloc;
using __STD::__default_alloc_template;
using __STD::alloc;
using __STD::single_client_alloc;
#ifdef __STL_STATIC_TEMPLATE_MEMBER_BUG
using __STD::__malloc_alloc_oom_handler;
#endif /* __STL_STATIC_TEMPLATE_MEMBER_BUG */
#ifdef __STL_USE_STD_ALLOCATORS
using __STD::allocator;
#endif /* __STL_USE_STD_ALLOCATORS */
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_ALLOC_H */
// Local Variables:
// mode:C++
// End:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_BVECTOR_H
#define __SGI_STL_BVECTOR_H
#include <stl_range_errors.h>
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
#include <vector.h>
#else
#include <algobase.h>
#include <alloc.h>
#endif
#include <stl_bvector.h>
#ifdef __STL_USE_NAMESPACES
using __STD::bit_vector;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_BVECTOR_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,152 @@
/*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_CHAR_TRAITS_H
#define __SGI_STL_CHAR_TRAITS_H
#include <string.h>
#include <wchar.h>
#if defined(__STL_USE_NEW_IOSTREAMS) && !defined(__SGI_STL_IOSFWD)
#include <iosfwd>
#endif /* use new iostreams */
__STL_BEGIN_NAMESPACE
// Class __char_traits_base.
template <class _CharT, class _IntT> class __char_traits_base {
public:
typedef _CharT char_type;
typedef _IntT int_type;
#ifdef __STL_USE_NEW_IOSTREAMS
typedef streamoff off_type;
typedef streampos pos_type;
typedef mbstate_t state_type;
#endif /* __STL_USE_NEW_IOSTREAMS */
static void assign(char_type& __c1, const char_type& __c2) { __c1 = __c2; }
static bool eq(const _CharT& __c1, const _CharT& __c2)
{ return __c1 == __c2; }
static bool lt(const _CharT& __c1, const _CharT& __c2)
{ return __c1 < __c2; }
static int compare(const _CharT* __s1, const _CharT* __s2, size_t __n) {
for (size_t __i = 0; __i < __n; ++__i)
if (!eq(__s1[__i], __s2[__i]))
return __s1[__i] < __s2[__i] ? -1 : 1;
return 0;
}
static size_t length(const _CharT* __s) {
const _CharT __nullchar = _CharT();
size_t __i;
for (__i = 0; !eq(__s[__i], __nullchar); ++__i)
{}
return __i;
}
static const _CharT* find(const _CharT* __s, size_t __n, const _CharT& __c)
{
for ( ; __n > 0 ; ++__s, --__n)
if (eq(*__s, __c))
return __s;
return 0;
}
static _CharT* move(_CharT* __s1, const _CharT* __s2, size_t __n) {
memmove(__s1, __s2, __n * sizeof(_CharT));
return __s1;
}
static _CharT* copy(_CharT* __s1, const _CharT* __s2, size_t __n) {
memcpy(__s1, __s2, __n * sizeof(_CharT));
return __s1;
}
static _CharT* assign(_CharT* __s, size_t __n, _CharT __c) {
for (size_t __i = 0; __i < __n; ++__i)
__s[__i] = __c;
return __s;
}
static int_type not_eof(const int_type& __c) {
return !eq_int_type(__c, eof()) ? __c : 0;
}
static char_type to_char_type(const int_type& __c) {
return static_cast<char_type>(__c);
}
static int_type to_int_type(const char_type& __c) {
return static_cast<int_type>(__c);
}
static bool eq_int_type(const int_type& __c1, const int_type& __c2) {
return __c1 == __c2;
}
static int_type eof() {
return static_cast<int_type>(-1);
}
};
// Generic char_traits class. Note that this class is provided only
// as a base for explicit specialization; it is unlikely to be useful
// as is for any particular user-defined type. In particular, it
// *will not work* for a non-POD type.
template <class _CharT> class char_traits
: public __char_traits_base<_CharT, _CharT>
{};
// Specialization for char.
__STL_TEMPLATE_NULL class char_traits<char>
: public __char_traits_base<char, int>
{
public:
static char_type to_char_type(const int_type& __c) {
return static_cast<char_type>(static_cast<unsigned char>(__c));
}
static int_type to_int_type(const char_type& __c) {
return static_cast<unsigned char>(__c);
}
static int compare(const char* __s1, const char* __s2, size_t __n)
{ return memcmp(__s1, __s2, __n); }
static size_t length(const char* __s) { return strlen(__s); }
static void assign(char& __c1, const char& __c2) { __c1 = __c2; }
static char* assign(char* __s, size_t __n, char __c)
{ memset(__s, __c, __n); return __s; }
};
// Specialization for wchar_t.
__STL_TEMPLATE_NULL class char_traits<wchar_t>
: public __char_traits_base<wchar_t, wint_t>
{};
__STL_END_NAMESPACE
#endif /* __SGI_STL_CHAR_TRAITS_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,811 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __CONCEPT_CHECKS_H
#define __CONCEPT_CHECKS_H
/*
Use these macro like assertions, but they assert properties
on types (usually template arguments). In technical terms they
verify whether a type "models" a "concept".
This set of requirements and the terminology used here is derived
from the book "Generic Programming and the STL" by Matt Austern
(Addison Wesley). For further information please consult that
book. The requirements also are intended to match the ANSI/ISO C++
standard.
This file covers the basic concepts and the iterator concepts.
There are several other files that provide the requirements
for the STL containers:
container_concepts.h
sequence_concepts.h
assoc_container_concepts.h
Jeremy Siek, 1999
TO DO:
- some issues with regards to concept classification and mutability
including AssociativeContianer -> ForwardContainer
and SortedAssociativeContainer -> ReversibleContainer
- HashedAssociativeContainer
- Allocator
- Function Object Concepts
*/
#ifndef __STL_USE_CONCEPT_CHECKS
// Some compilers lack the features that are necessary for concept checks.
// On those compilers we define the concept check macros to do nothing.
#define __STL_REQUIRES(__type_var, __concept) do {} while(0)
#define __STL_CLASS_REQUIRES(__type_var, __concept) \
static int __##__type_var##_##__concept
#define __STL_CONVERTIBLE(__type_x, __type_y) do {} while(0)
#define __STL_REQUIRES_SAME_TYPE(__type_x, __type_y) do {} while(0)
#define __STL_CLASS_REQUIRES_SAME_TYPE(__type_x, __type_y) \
static int __##__type_x##__type_y##_require_same_type
#define __STL_GENERATOR_CHECK(__func, __ret) do {} while(0)
#define __STL_CLASS_GENERATOR_CHECK(__func, __ret) \
static int __##__func##__ret##_generator_check
#define __STL_UNARY_FUNCTION_CHECK(__func, __ret, __arg) do {} while(0)
#define __STL_CLASS_UNARY_FUNCTION_CHECK(__func, __ret, __arg) \
static int __##__func##__ret##__arg##_unary_function_check
#define __STL_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
do {} while(0)
#define __STL_CLASS_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
static int __##__func##__ret##__first##__second##_binary_function_check
#define __STL_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
do {} while(0)
#define __STL_CLASS_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
static int __##__opname##__ret##__first##__second##_require_binary_op
#else /* __STL_USE_CONCEPT_CHECKS */
// This macro tests whether the template argument "__type_var"
// satisfies the requirements of "__concept". Here is a list of concepts
// that we know how to check:
// _Allocator
// _Assignable
// _DefaultConstructible
// _EqualityComparable
// _LessThanComparable
// _TrivialIterator
// _InputIterator
// _OutputIterator
// _ForwardIterator
// _BidirectionalIterator
// _RandomAccessIterator
// _Mutable_TrivialIterator
// _Mutable_ForwardIterator
// _Mutable_BidirectionalIterator
// _Mutable_RandomAccessIterator
#define __STL_REQUIRES(__type_var, __concept) \
do { \
void (*__x)( __type_var ) = __concept##_concept_specification< __type_var >\
::__concept##_requirement_violation; __x = __x; } while (0)
// Use this to check whether type X is convertible to type Y
#define __STL_CONVERTIBLE(__type_x, __type_y) \
do { \
void (*__x)( __type_x , __type_y ) = _STL_CONVERT_ERROR< __type_x , \
__type_y >::__type_X_is_not_convertible_to_type_Y; \
__x = __x; } while (0)
// Use this to test whether two template arguments are the same type
#define __STL_REQUIRES_SAME_TYPE(__type_x, __type_y) \
do { \
void (*__x)( __type_x , __type_y ) = _STL_SAME_TYPE_ERROR< __type_x, \
__type_y >::__type_X_not_same_as_type_Y; \
__x = __x; } while (0)
// function object checks
#define __STL_GENERATOR_CHECK(__func, __ret) \
do { \
__ret (*__x)( __func&) = \
_STL_GENERATOR_ERROR< \
__func, __ret>::__generator_requirement_violation; \
__x = __x; } while (0)
#define __STL_UNARY_FUNCTION_CHECK(__func, __ret, __arg) \
do { \
__ret (*__x)( __func&, const __arg& ) = \
_STL_UNARY_FUNCTION_ERROR< \
__func, __ret, __arg>::__unary_function_requirement_violation; \
__x = __x; } while (0)
#define __STL_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
do { \
__ret (*__x)( __func&, const __first&, const __second& ) = \
_STL_BINARY_FUNCTION_ERROR< \
__func, __ret, __first, __second>::__binary_function_requirement_violation; \
__x = __x; } while (0)
#define __STL_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
do { \
__ret (*__x)( __first&, __second& ) = _STL_BINARY##__opname##_ERROR< \
__ret, __first, __second>::__binary_operator_requirement_violation; \
__ret (*__y)( const __first&, const __second& ) = \
_STL_BINARY##__opname##_ERROR< __ret, __first, __second>:: \
__const_binary_operator_requirement_violation; \
__y = __y; __x = __x; } while (0)
#ifdef __STL_NO_FUNCTION_PTR_IN_CLASS_TEMPLATE
#define __STL_CLASS_REQUIRES(__type_var, __concept)
#define __STL_CLASS_REQUIRES_SAME_TYPE(__type_x, __type_y)
#define __STL_CLASS_GENERATOR_CHECK(__func, __ret)
#define __STL_CLASS_UNARY_FUNCTION_CHECK(__func, __ret, __arg)
#define __STL_CLASS_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second)
#define __STL_CLASS_REQUIRES_BINARY_OP(__opname, __ret, __first, __second)
#else
// Use this macro inside of template classes, where you would
// like to place requirements on the template arguments to the class
// Warning: do not pass pointers and such (e.g. T*) in as the __type_var,
// since the type_var is used to construct identifiers. Instead typedef
// the pointer type, then use the typedef name for the __type_var.
#define __STL_CLASS_REQUIRES(__type_var, __concept) \
typedef void (* __func##__type_var##__concept)( __type_var ); \
template <__func##__type_var##__concept _Tp1> \
struct __dummy_struct_##__type_var##__concept { }; \
static __dummy_struct_##__type_var##__concept< \
__concept##_concept_specification< \
__type_var>::__concept##_requirement_violation> \
__dummy_ptr_##__type_var##__concept
#define __STL_CLASS_REQUIRES_SAME_TYPE(__type_x, __type_y) \
typedef void (* __func_##__type_x##__type_y##same_type)( __type_x, \
__type_y ); \
template < __func_##__type_x##__type_y##same_type _Tp1> \
struct __dummy_struct_##__type_x##__type_y##_same_type { }; \
static __dummy_struct_##__type_x##__type_y##_same_type< \
_STL_SAME_TYPE_ERROR<__type_x, __type_y>::__type_X_not_same_as_type_Y> \
__dummy_ptr_##__type_x##__type_y##_same_type
#define __STL_CLASS_GENERATOR_CHECK(__func, __ret) \
typedef __ret (* __f_##__func##__ret##_generator)( __func& ); \
template <__f_##__func##__ret##_generator _Tp1> \
struct __dummy_struct_##__func##__ret##_generator { }; \
static __dummy_struct_##__func##__ret##_generator< \
_STL_GENERATOR_ERROR< \
__func, __ret>::__generator_requirement_violation> \
__dummy_ptr_##__func##__ret##_generator
#define __STL_CLASS_UNARY_FUNCTION_CHECK(__func, __ret, __arg) \
typedef __ret (* __f_##__func##__ret##__arg##_unary_check)( __func&, \
const __arg& ); \
template <__f_##__func##__ret##__arg##_unary_check _Tp1> \
struct __dummy_struct_##__func##__ret##__arg##_unary_check { }; \
static __dummy_struct_##__func##__ret##__arg##_unary_check< \
_STL_UNARY_FUNCTION_ERROR< \
__func, __ret, __arg>::__unary_function_requirement_violation> \
__dummy_ptr_##__func##__ret##__arg##_unary_check
#define __STL_CLASS_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
typedef __ret (* __f_##__func##__ret##__first##__second##_binary_check)( __func&, const __first&,\
const __second& ); \
template <__f_##__func##__ret##__first##__second##_binary_check _Tp1> \
struct __dummy_struct_##__func##__ret##__first##__second##_binary_check { }; \
static __dummy_struct_##__func##__ret##__first##__second##_binary_check< \
_STL_BINARY_FUNCTION_ERROR<__func, __ret, __first, __second>:: \
__binary_function_requirement_violation> \
__dummy_ptr_##__func##__ret##__first##__second##_binary_check
#define __STL_CLASS_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
typedef __ret (* __f_##__func##__ret##__first##__second##_binary_op)(const __first&, \
const __second& ); \
template <__f_##__func##__ret##__first##__second##_binary_op _Tp1> \
struct __dummy_struct_##__func##__ret##__first##__second##_binary_op { }; \
static __dummy_struct_##__func##__ret##__first##__second##_binary_op< \
_STL_BINARY##__opname##_ERROR<__ret, __first, __second>:: \
__binary_operator_requirement_violation> \
__dummy_ptr_##__func##__ret##__first##__second##_binary_op
#endif
/* helper class for finding non-const version of a type. Need to have
something to assign to etc. when testing constant iterators. */
template <class _Tp>
struct _Mutable_trait {
typedef _Tp _Type;
};
template <class _Tp>
struct _Mutable_trait<const _Tp> {
typedef _Tp _Type;
};
/* helper function for avoiding compiler warnings about unused variables */
template <class _Type>
void __sink_unused_warning(_Type) { }
template <class _TypeX, class _TypeY>
struct _STL_CONVERT_ERROR {
static void
__type_X_is_not_convertible_to_type_Y(_TypeX __x, _TypeY) {
_TypeY __y = __x;
__sink_unused_warning(__y);
}
};
template <class _Type> struct __check_equal { };
template <class _TypeX, class _TypeY>
struct _STL_SAME_TYPE_ERROR {
static void
__type_X_not_same_as_type_Y(_TypeX , _TypeY ) {
__check_equal<_TypeX> t1 = __check_equal<_TypeY>();
}
};
// Some Functon Object Checks
template <class _Func, class _Ret>
struct _STL_GENERATOR_ERROR {
static _Ret __generator_requirement_violation(_Func& __f) {
return __f();
}
};
template <class _Func>
struct _STL_GENERATOR_ERROR<_Func, void> {
static void __generator_requirement_violation(_Func& __f) {
__f();
}
};
template <class _Func, class _Ret, class _Arg>
struct _STL_UNARY_FUNCTION_ERROR {
static _Ret
__unary_function_requirement_violation(_Func& __f,
const _Arg& __arg) {
return __f(__arg);
}
};
template <class _Func, class _Arg>
struct _STL_UNARY_FUNCTION_ERROR<_Func, void, _Arg> {
static void
__unary_function_requirement_violation(_Func& __f,
const _Arg& __arg) {
__f(__arg);
}
};
template <class _Func, class _Ret, class _First, class _Second>
struct _STL_BINARY_FUNCTION_ERROR {
static _Ret
__binary_function_requirement_violation(_Func& __f,
const _First& __first,
const _Second& __second) {
return __f(__first, __second);
}
};
template <class _Func, class _First, class _Second>
struct _STL_BINARY_FUNCTION_ERROR<_Func, void, _First, _Second> {
static void
__binary_function_requirement_violation(_Func& __f,
const _First& __first,
const _Second& __second) {
__f(__first, __second);
}
};
#define __STL_DEFINE_BINARY_OP_CHECK(_OP, _NAME) \
template <class _Ret, class _First, class _Second> \
struct _STL_BINARY##_NAME##_ERROR { \
static _Ret \
__const_binary_operator_requirement_violation(const _First& __first, \
const _Second& __second) { \
return __first _OP __second; \
} \
static _Ret \
__binary_operator_requirement_violation(_First& __first, \
_Second& __second) { \
return __first _OP __second; \
} \
}
__STL_DEFINE_BINARY_OP_CHECK(==, _OP_EQUAL);
__STL_DEFINE_BINARY_OP_CHECK(!=, _OP_NOT_EQUAL);
__STL_DEFINE_BINARY_OP_CHECK(<, _OP_LESS_THAN);
__STL_DEFINE_BINARY_OP_CHECK(<=, _OP_LESS_EQUAL);
__STL_DEFINE_BINARY_OP_CHECK(>, _OP_GREATER_THAN);
__STL_DEFINE_BINARY_OP_CHECK(>=, _OP_GREATER_EQUAL);
__STL_DEFINE_BINARY_OP_CHECK(+, _OP_PLUS);
__STL_DEFINE_BINARY_OP_CHECK(*, _OP_TIMES);
__STL_DEFINE_BINARY_OP_CHECK(/, _OP_DIVIDE);
__STL_DEFINE_BINARY_OP_CHECK(-, _OP_SUBTRACT);
__STL_DEFINE_BINARY_OP_CHECK(%, _OP_MOD);
// ...
// TODO, add unary operators (prefix and postfix)
/*
The presence of this class is just to trick EDG into displaying
these error messages before any other errors. Without the
classes, the errors in the functions get reported after
other class errors deep inside the library. The name
choice just makes for an eye catching error message :)
*/
struct _STL_ERROR {
template <class _Type>
static _Type
__default_constructor_requirement_violation(_Type) {
return _Type();
}
template <class _Type>
static _Type
__assignment_operator_requirement_violation(_Type __a) {
__a = __a;
return __a;
}
template <class _Type>
static _Type
__copy_constructor_requirement_violation(_Type __a) {
_Type __c(__a);
return __c;
}
template <class _Type>
static _Type
__const_parameter_required_for_copy_constructor(_Type /* __a */,
const _Type& __b) {
_Type __c(__b);
return __c;
}
template <class _Type>
static _Type
__const_parameter_required_for_assignment_operator(_Type __a,
const _Type& __b) {
__a = __b;
return __a;
}
template <class _Type>
static _Type
__less_than_comparable_requirement_violation(_Type __a, _Type __b) {
if (__a < __b || __a > __b || __a <= __b || __a >= __b) return __a;
return __b;
}
template <class _Type>
static _Type
__equality_comparable_requirement_violation(_Type __a, _Type __b) {
if (__a == __b || __a != __b) return __a;
return __b;
}
template <class _Iterator>
static void
__dereference_operator_requirement_violation(_Iterator __i) {
__sink_unused_warning(*__i);
}
template <class _Iterator>
static void
__dereference_operator_and_assignment_requirement_violation(_Iterator __i) {
*__i = *__i;
}
template <class _Iterator>
static void
__preincrement_operator_requirement_violation(_Iterator __i) {
++__i;
}
template <class _Iterator>
static void
__postincrement_operator_requirement_violation(_Iterator __i) {
__i++;
}
template <class _Iterator>
static void
__predecrement_operator_requirement_violation(_Iterator __i) {
--__i;
}
template <class _Iterator>
static void
__postdecrement_operator_requirement_violation(_Iterator __i) {
__i--;
}
template <class _Iterator, class _Type>
static void
__postincrement_operator_and_assignment_requirement_violation(_Iterator __i,
_Type __t) {
*__i++ = __t;
}
template <class _Iterator, class _Distance>
static _Iterator
__iterator_addition_assignment_requirement_violation(_Iterator __i,
_Distance __n) {
__i += __n;
return __i;
}
template <class _Iterator, class _Distance>
static _Iterator
__iterator_addition_requirement_violation(_Iterator __i, _Distance __n) {
__i = __i + __n;
__i = __n + __i;
return __i;
}
template <class _Iterator, class _Distance>
static _Iterator
__iterator_subtraction_assignment_requirement_violation(_Iterator __i,
_Distance __n) {
__i -= __n;
return __i;
}
template <class _Iterator, class _Distance>
static _Iterator
__iterator_subtraction_requirement_violation(_Iterator __i, _Distance __n) {
__i = __i - __n;
return __i;
}
template <class _Iterator, class _Distance>
static _Distance
__difference_operator_requirement_violation(_Iterator __i, _Iterator __j,
_Distance __n) {
__n = __i - __j;
return __n;
}
template <class _Exp, class _Type, class _Distance>
static _Type
__element_access_operator_requirement_violation(_Exp __x, _Type*,
_Distance __n) {
return __x[__n];
}
template <class _Exp, class _Type, class _Distance>
static void
__element_assignment_operator_requirement_violation(_Exp __x,
_Type* __t,
_Distance __n) {
__x[__n] = *__t;
}
}; /* _STL_ERROR */
/* Associated Type Requirements */
__STL_BEGIN_NAMESPACE
template <class _Iterator> struct iterator_traits;
__STL_END_NAMESPACE
template <class _Iter>
struct __value_type_type_definition_requirement_violation {
typedef typename __STD::iterator_traits<_Iter>::value_type value_type;
};
template <class _Iter>
struct __difference_type_type_definition_requirement_violation {
typedef typename __STD::iterator_traits<_Iter>::difference_type
difference_type;
};
template <class _Iter>
struct __reference_type_definition_requirement_violation {
typedef typename __STD::iterator_traits<_Iter>::reference reference;
};
template <class _Iter>
struct __pointer_type_definition_requirement_violation {
typedef typename __STD::iterator_traits<_Iter>::pointer pointer;
};
template <class _Iter>
struct __iterator_category_type_definition_requirement_violation {
typedef typename __STD::iterator_traits<_Iter>::iterator_category
iterator_category;
};
/* Assignable Requirements */
template <class _Type>
struct _Assignable_concept_specification {
static void _Assignable_requirement_violation(_Type __a) {
_STL_ERROR::__assignment_operator_requirement_violation(__a);
_STL_ERROR::__copy_constructor_requirement_violation(__a);
_STL_ERROR::__const_parameter_required_for_copy_constructor(__a,__a);
_STL_ERROR::__const_parameter_required_for_assignment_operator(__a,__a);
}
};
/* DefaultConstructible Requirements */
template <class _Type>
struct _DefaultConstructible_concept_specification {
static void _DefaultConstructible_requirement_violation(_Type __a) {
_STL_ERROR::__default_constructor_requirement_violation(__a);
}
};
/* EqualityComparable Requirements */
template <class _Type>
struct _EqualityComparable_concept_specification {
static void _EqualityComparable_requirement_violation(_Type __a) {
_STL_ERROR::__equality_comparable_requirement_violation(__a, __a);
}
};
/* LessThanComparable Requirements */
template <class _Type>
struct _LessThanComparable_concept_specification {
static void _LessThanComparable_requirement_violation(_Type __a) {
_STL_ERROR::__less_than_comparable_requirement_violation(__a, __a);
}
};
/* TrivialIterator Requirements */
template <class _TrivialIterator>
struct _TrivialIterator_concept_specification {
static void
_TrivialIterator_requirement_violation(_TrivialIterator __i) {
typedef typename
__value_type_type_definition_requirement_violation<_TrivialIterator>::
value_type __T;
// Refinement of Assignable
_Assignable_concept_specification<_TrivialIterator>::
_Assignable_requirement_violation(__i);
// Refinement of DefaultConstructible
_DefaultConstructible_concept_specification<_TrivialIterator>::
_DefaultConstructible_requirement_violation(__i);
// Refinement of EqualityComparable
_EqualityComparable_concept_specification<_TrivialIterator>::
_EqualityComparable_requirement_violation(__i);
// Valid Expressions
_STL_ERROR::__dereference_operator_requirement_violation(__i);
}
};
template <class _TrivialIterator>
struct _Mutable_TrivialIterator_concept_specification {
static void
_Mutable_TrivialIterator_requirement_violation(_TrivialIterator __i) {
_TrivialIterator_concept_specification<_TrivialIterator>::
_TrivialIterator_requirement_violation(__i);
// Valid Expressions
_STL_ERROR::__dereference_operator_and_assignment_requirement_violation(__i);
}
};
/* InputIterator Requirements */
template <class _InputIterator>
struct _InputIterator_concept_specification {
static void
_InputIterator_requirement_violation(_InputIterator __i) {
// Refinement of TrivialIterator
_TrivialIterator_concept_specification<_InputIterator>::
_TrivialIterator_requirement_violation(__i);
// Associated Types
__difference_type_type_definition_requirement_violation<_InputIterator>();
__reference_type_definition_requirement_violation<_InputIterator>();
__pointer_type_definition_requirement_violation<_InputIterator>();
__iterator_category_type_definition_requirement_violation<_InputIterator>();
// Valid Expressions
_STL_ERROR::__preincrement_operator_requirement_violation(__i);
_STL_ERROR::__postincrement_operator_requirement_violation(__i);
}
};
/* OutputIterator Requirements */
template <class _OutputIterator>
struct _OutputIterator_concept_specification {
static void
_OutputIterator_requirement_violation(_OutputIterator __i) {
// Refinement of Assignable
_Assignable_concept_specification<_OutputIterator>::
_Assignable_requirement_violation(__i);
// Associated Types
__iterator_category_type_definition_requirement_violation<_OutputIterator>();
// Valid Expressions
_STL_ERROR::__dereference_operator_requirement_violation(__i);
_STL_ERROR::__preincrement_operator_requirement_violation(__i);
_STL_ERROR::__postincrement_operator_requirement_violation(__i);
_STL_ERROR::
__postincrement_operator_and_assignment_requirement_violation(__i, *__i);
}
};
/* ForwardIterator Requirements */
template <class _ForwardIterator>
struct _ForwardIterator_concept_specification {
static void
_ForwardIterator_requirement_violation(_ForwardIterator __i) {
// Refinement of InputIterator
_InputIterator_concept_specification<_ForwardIterator>::
_InputIterator_requirement_violation(__i);
}
};
template <class _ForwardIterator>
struct _Mutable_ForwardIterator_concept_specification {
static void
_Mutable_ForwardIterator_requirement_violation(_ForwardIterator __i) {
_ForwardIterator_concept_specification<_ForwardIterator>::
_ForwardIterator_requirement_violation(__i);
// Refinement of OutputIterator
_OutputIterator_concept_specification<_ForwardIterator>::
_OutputIterator_requirement_violation(__i);
}
};
/* BidirectionalIterator Requirements */
template <class _BidirectionalIterator>
struct _BidirectionalIterator_concept_specification {
static void
_BidirectionalIterator_requirement_violation(_BidirectionalIterator __i) {
// Refinement of ForwardIterator
_ForwardIterator_concept_specification<_BidirectionalIterator>::
_ForwardIterator_requirement_violation(__i);
// Valid Expressions
_STL_ERROR::__predecrement_operator_requirement_violation(__i);
_STL_ERROR::__postdecrement_operator_requirement_violation(__i);
}
};
template <class _BidirectionalIterator>
struct _Mutable_BidirectionalIterator_concept_specification {
static void
_Mutable_BidirectionalIterator_requirement_violation(
_BidirectionalIterator __i)
{
_BidirectionalIterator_concept_specification<_BidirectionalIterator>::
_BidirectionalIterator_requirement_violation(__i);
// Refinement of mutable_ForwardIterator
_Mutable_ForwardIterator_concept_specification<_BidirectionalIterator>::
_Mutable_ForwardIterator_requirement_violation(__i);
typedef typename
__value_type_type_definition_requirement_violation<
_BidirectionalIterator>::value_type __T;
typename _Mutable_trait<__T>::_Type* __tmp_ptr = 0;
// Valid Expressions
_STL_ERROR::
__postincrement_operator_and_assignment_requirement_violation(__i,
*__tmp_ptr);
}
};
/* RandomAccessIterator Requirements */
template <class _RandAccIter>
struct _RandomAccessIterator_concept_specification {
static void
_RandomAccessIterator_requirement_violation(_RandAccIter __i) {
// Refinement of BidirectionalIterator
_BidirectionalIterator_concept_specification<_RandAccIter>::
_BidirectionalIterator_requirement_violation(__i);
// Refinement of LessThanComparable
_LessThanComparable_concept_specification<_RandAccIter>::
_LessThanComparable_requirement_violation(__i);
typedef typename
__value_type_type_definition_requirement_violation<_RandAccIter>
::value_type
value_type;
typedef typename
__difference_type_type_definition_requirement_violation<_RandAccIter>
::difference_type
_Dist;
typedef typename _Mutable_trait<_Dist>::_Type _MutDist;
// Valid Expressions
_STL_ERROR::__iterator_addition_assignment_requirement_violation(__i,
_MutDist());
_STL_ERROR::__iterator_addition_requirement_violation(__i,
_MutDist());
_STL_ERROR::
__iterator_subtraction_assignment_requirement_violation(__i,
_MutDist());
_STL_ERROR::__iterator_subtraction_requirement_violation(__i,
_MutDist());
_STL_ERROR::__difference_operator_requirement_violation(__i, __i,
_MutDist());
typename _Mutable_trait<value_type>::_Type* __dummy_ptr = 0;
_STL_ERROR::__element_access_operator_requirement_violation(__i,
__dummy_ptr,
_MutDist());
}
};
template <class _RandAccIter>
struct _Mutable_RandomAccessIterator_concept_specification {
static void
_Mutable_RandomAccessIterator_requirement_violation(_RandAccIter __i)
{
_RandomAccessIterator_concept_specification<_RandAccIter>::
_RandomAccessIterator_requirement_violation(__i);
// Refinement of mutable_BidirectionalIterator
_Mutable_BidirectionalIterator_concept_specification<_RandAccIter>::
_Mutable_BidirectionalIterator_requirement_violation(__i);
typedef typename
__value_type_type_definition_requirement_violation<_RandAccIter>
::value_type
value_type;
typedef typename
__difference_type_type_definition_requirement_violation<_RandAccIter>
::difference_type
_Dist;
typename _Mutable_trait<value_type>::_Type* __tmp_ptr = 0;
// Valid Expressions
_STL_ERROR::__element_assignment_operator_requirement_violation(__i,
__tmp_ptr, _Dist());
}
};
#define __STL_TYPEDEF_REQUIREMENT(__REQUIREMENT) \
template <class Type> \
struct __##__REQUIREMENT##__typedef_requirement_violation { \
typedef typename Type::__REQUIREMENT __REQUIREMENT; \
}
__STL_TYPEDEF_REQUIREMENT(value_type);
__STL_TYPEDEF_REQUIREMENT(difference_type);
__STL_TYPEDEF_REQUIREMENT(size_type);
__STL_TYPEDEF_REQUIREMENT(reference);
__STL_TYPEDEF_REQUIREMENT(const_reference);
__STL_TYPEDEF_REQUIREMENT(pointer);
__STL_TYPEDEF_REQUIREMENT(const_pointer);
template <class _Alloc>
struct _Allocator_concept_specification {
static void
_Allocator_requirement_violation(_Alloc __a) {
// Refinement of DefaultConstructible
_DefaultConstructible_concept_specification<_Alloc>::
_DefaultConstructible_requirement_violation(__a);
// Refinement of EqualityComparable
_EqualityComparable_concept_specification<_Alloc>::
_EqualityComparable_requirement_violation(__a);
// Associated Types
__value_type__typedef_requirement_violation<_Alloc>();
__difference_type__typedef_requirement_violation<_Alloc>();
__size_type__typedef_requirement_violation<_Alloc>();
__reference__typedef_requirement_violation<_Alloc>();
__const_reference__typedef_requirement_violation<_Alloc>();
__pointer__typedef_requirement_violation<_Alloc>();
__const_pointer__typedef_requirement_violation<_Alloc>();
typedef typename _Alloc::value_type _Tp;
//__STL_REQUIRES_SAME_TYPE(typename _Alloc::__STL_TEMPLATE rebind<_Tp>::other,
// _Alloc);
}
};
#endif /* __STL_USE_CONCEPT_CHECKS */
#endif /* __CONCEPT_CHECKS_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,247 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __STL_CONTAINER_CONCEPTS_H
#define __STL_CONTAINER_CONCEPTS_H
#include <concept_checks.h>
#ifdef __STL_USE_CONCEPT_CHECKS
// This file covers the following concepts:
// _Container
// _ForwardContainer
// _ReversibleContainer
// _const_ReversibleContainer
// _RandomAccessContainer
//
struct _ERROR_IN_STL_CONTAINER {
/* Container expresssions */
template <class _Container>
static void
__begin_iterator_accessor_requirement_violation(_Container __c) {
__c.begin();
}
template <class _Container>
static void
__const_begin_iterator_accessor_requirement_violation(const _Container& __c) {
__c.begin();
}
template <class _Container>
static void
__end_iterator_accessor_requirement_violation(_Container __c) {
__c.end();
}
template <class _Container>
static void
__const_end_iterator_accessor_requirement_violation(const _Container& __c) {
__c.end();
}
template <class _Container>
static void
__rbegin_iterator_accessor_requirement_violation(_Container __c) {
__c.rbegin();
}
template <class _Container>
static void
__const_rbegin_iterator_accessor_requirement_violation(const _Container& __c) {
__c.rbegin();
}
template <class _Container>
static void
__rend_iterator_accessor_requirement_violation(_Container __c) {
__c.rend();
}
template <class _Container>
static void
__const_rend_iterator_accessor_requirement_violation(const _Container& __c) {
__c.rend();
}
template <class _Container>
static void
__size_function_must_be_const(const _Container& __c) {
__c.size();
}
template <class _Container>
static void
__size_function_requirement_violation(_Container& __c) {
__c.size();
__size_function_must_be_const(__c);
}
template <class _Container>
static void
__max_size_function_must_be_const(const _Container& __c) {
__c.max_size();
}
template <class _Container>
static void
__max_size_function_requirement_violation(_Container& __c) {
__c.max_size();
__max_size_function_must_be_const(__c);
}
template <class _Container>
static void
__empty_function_must_be_const(const _Container& __c) {
__c.empty();
}
template <class _Container>
static void
__empty_function_requirement_violation(_Container& __c) {
__c.empty();
__empty_function_must_be_const(__c);
}
template <class _Container>
static void
__swap_function_requirement_violation(_Container& __c) {
__c.swap(__c);
}
};
__STL_TYPEDEF_REQUIREMENT(iterator);
__STL_TYPEDEF_REQUIREMENT(const_iterator);
/* Containers */
template <class _Container>
struct _Container_concept_specification {
static void
_Container_requirement_violation(_Container __c) {
// Refinement of Assignable
_Assignable_concept_specification<_Container>::_Assignable_requirement_violation(__c);
// Associated Types
__value_type__typedef_requirement_violation<_Container>();
__difference_type__typedef_requirement_violation<_Container>();
__size_type__typedef_requirement_violation<_Container>();
__reference__typedef_requirement_violation<_Container>();
__const_reference__typedef_requirement_violation<_Container>();
__pointer__typedef_requirement_violation<_Container>();
__const_pointer__typedef_requirement_violation<_Container>();
__iterator__typedef_requirement_violation<_Container>();
__const_iterator__typedef_requirement_violation<_Container>();
// Valid Expressions
_ERROR_IN_STL_CONTAINER::__const_begin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__const_end_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__begin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__end_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__size_function_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__max_size_function_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__empty_function_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__swap_function_requirement_violation(__c);
// Requirements on Iterators
typedef typename _Container::iterator iter;
typedef typename _Container::const_iterator const_iter;
_InputIterator_concept_specification<const_iter>::_InputIterator_requirement_violation(const_iter());
_InputIterator_concept_specification<iter>::_InputIterator_requirement_violation(iter());
}
};
template <class _ForwardContainer>
struct _ForwardContainer_concept_specification {
static void
_ForwardContainer_requirement_violation(_ForwardContainer __c) {
// Refinement of Container
_Container_concept_specification<_ForwardContainer>::_Container_requirement_violation(__c);
// Requirements on Iterators
typedef typename _ForwardContainer::iterator iter;
typedef typename _ForwardContainer::const_iterator const_iter;
_ForwardIterator_concept_specification<const_iter>::_ForwardIterator_requirement_violation(const_iter());
_Mutable_ForwardIterator_concept_specification<iter>::_Mutable_ForwardIterator_requirement_violation(iter());
}
};
__STL_TYPEDEF_REQUIREMENT(reverse_iterator);
__STL_TYPEDEF_REQUIREMENT(const_reverse_iterator);
template <class _ReversibleContainer>
struct _ReversibleContainer_concept_specification {
static void
_ReversibleContainer_requirement_violation(_ReversibleContainer __c) {
// Refinement of ForwardContainer
_ForwardContainer_concept_specification<_ReversibleContainer>::_ForwardContainer_requirement_violation(__c);
// Associated types
__reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
__const_reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
// Valid Expressions
_ERROR_IN_STL_CONTAINER::__const_rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__const_rend_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rend_iterator_accessor_requirement_violation(__c);
// Requirements on Iterators
typedef typename _ReversibleContainer::iterator iter;
typedef typename _ReversibleContainer::const_iterator const_iter;
_BidirectionalIterator_concept_specification<const_iter>::_BidirectionalIterator_requirement_violation(const_iter());
_Mutable_BidirectionalIterator_concept_specification<iter>::_Mutable_BidirectionalIterator_requirement_violation(iter());
}
};
template <class _ReversibleContainer>
struct _const_ReversibleContainer_concept_specification {
static void
_const_ReversibleContainer_requirement_violation(_ReversibleContainer __c) {
// Refinement of Container (JGS, not ForwardContainer)
_Container_concept_specification<_ReversibleContainer>::_Container_requirement_violation(__c);
// Associated types
__reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
__const_reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
// Valid Expressions
_ERROR_IN_STL_CONTAINER::__const_rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__const_rend_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rend_iterator_accessor_requirement_violation(__c);
// Requirements on Iterators
typedef typename _ReversibleContainer::iterator iter;
typedef typename _ReversibleContainer::const_iterator const_iter;
// This line won't compile on gcc 2.91 due to a compiler bug.
#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 91)
__BidirectionalIterator_concept_specification<const_iter>::_BidirectionalIterator_requirement_violation(const_iter());
#endif
}
};
template <class _RandomAccessContainer>
struct _RandomAccessContainer_concept_specification {
static void
_RandomAccessContainer_requirement_violation(_RandomAccessContainer __c) {
// Refinement of ReversibleContainer
_ReversibleContainer_concept_specification<_RandomAccessContainer>::_ReversibleContainer_requirement_violation(__c);
// Valid Expressions
typedef typename _RandomAccessContainer::value_type __T;
typedef typename _RandomAccessContainer::difference_type _Dist;
typedef typename _Mutable_trait<__T>::_Type Type;
typedef Type* _TypePtr;
typedef typename _Mutable_trait<_Dist>::_Type Dist;
_STL_ERROR::__element_access_operator_requirement_violation(__c,
_TypePtr(),
Dist());
// Requirements on Iterators
typedef typename _RandomAccessContainer::iterator iter;
typedef typename _RandomAccessContainer::const_iterator const_iter;
_RandomAccessIterator_concept_specification<const_iter>::_RandomAccessIterator_requirement_violation(const_iter());
_Mutable_RandomAccessIterator_concept_specification<iter>::_Mutable_RandomAccessIterator_requirement_violation(iter());
}
};
#endif /* if __STL_USE_CONCEPT_CHECKS */
#endif /* __STL_CONTAINER_CONCEPTS_H */

View File

@ -0,0 +1,87 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
// Inclusion of this file is DEPRECATED. This is the original HP
// default allocator. It is provided only for backward compatibility.
// This file WILL BE REMOVED in a future release.
//
// DO NOT USE THIS FILE unless you have an old container implementation
// that requires an allocator with the HP-style interface.
//
// Standard-conforming allocators have a very different interface. The
// standard default allocator is declared in the header <memory>.
#ifndef DEFALLOC_H
#define DEFALLOC_H
#include <new.h>
#include <stddef.h>
#include <stdlib.h>
#include <limits.h>
#include <iostream.h>
#include <algobase.h>
template <class T>
inline T* allocate(ptrdiff_t size, T*) {
set_new_handler(0);
T* tmp = (T*)(::operator new((size_t)(size * sizeof(T))));
if (tmp == 0) {
cerr << "out of memory" << endl;
exit(1);
}
return tmp;
}
template <class T>
inline void deallocate(T* buffer) {
::operator delete(buffer);
}
template <class T>
class allocator {
public:
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
pointer allocate(size_type n) {
return ::allocate((difference_type)n, (pointer)0);
}
void deallocate(pointer p) { ::deallocate(p); }
pointer address(reference x) { return (pointer)&x; }
const_pointer const_address(const_reference x) {
return (const_pointer)&x;
}
size_type init_page_size() {
return max(size_type(1), size_type(4096/sizeof(T)));
}
size_type max_size() const {
return max(size_type(1), size_type(UINT_MAX/sizeof(T)));
}
};
class allocator<void> {
public:
typedef void* pointer;
};
#endif

View File

@ -0,0 +1,41 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_DEQUE
#define __SGI_STL_DEQUE
#include <stl_range_errors.h>
#include <stl_algobase.h>
#include <stl_alloc.h>
#include <stl_construct.h>
#include <stl_uninitialized.h>
#include <stl_deque.h>
#endif /* __SGI_STL_DEQUE */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,43 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_DEQUE_H
#define __SGI_STL_DEQUE_H
#include <stl_range_errors.h>
#include <algobase.h>
#include <alloc.h>
#include <stl_deque.h>
#ifdef __STL_USE_NAMESPACES
using __STD::deque;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_DEQUE_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,118 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_FUNCTION_H
#define __SGI_STL_FUNCTION_H
#ifndef __STL_CONFIG_H
#include <stl_config.h>
#endif
#ifndef __SGI_STL_INTERNAL_RELOPS
#include <stl_relops.h>
#endif
#include <stddef.h>
#ifndef __SGI_STL_INTERNAL_FUNCTION_H
#include <stl_function.h>
#endif
#ifdef __STL_USE_NAMESPACE_FOR_RELOPS
// Names from stl_relops.h
using __STD_RELOPS::operator!=;
using __STD_RELOPS::operator>;
using __STD_RELOPS::operator<=;
using __STD_RELOPS::operator>=;
#endif /* __STL_USE_NAMESPACE_FOR_RELOPS */
#ifdef __STL_USE_NAMESPACES
// Names from stl_function.h
using __STD::unary_function;
using __STD::binary_function;
using __STD::plus;
using __STD::minus;
using __STD::multiplies;
using __STD::divides;
using __STD::identity_element;
using __STD::modulus;
using __STD::negate;
using __STD::equal_to;
using __STD::not_equal_to;
using __STD::greater;
using __STD::less;
using __STD::greater_equal;
using __STD::less_equal;
using __STD::logical_and;
using __STD::logical_or;
using __STD::logical_not;
using __STD::unary_negate;
using __STD::binary_negate;
using __STD::not1;
using __STD::not2;
using __STD::binder1st;
using __STD::binder2nd;
using __STD::bind1st;
using __STD::bind2nd;
using __STD::unary_compose;
using __STD::binary_compose;
using __STD::compose1;
using __STD::compose2;
using __STD::pointer_to_unary_function;
using __STD::pointer_to_binary_function;
using __STD::ptr_fun;
using __STD::identity;
using __STD::select1st;
using __STD::select2nd;
using __STD::project1st;
using __STD::project2nd;
using __STD::constant_void_fun;
using __STD::constant_unary_fun;
using __STD::constant_binary_fun;
using __STD::constant0;
using __STD::constant1;
using __STD::constant2;
using __STD::subtractive_rng;
using __STD::mem_fun_t;
using __STD::const_mem_fun_t;
using __STD::mem_fun_ref_t;
using __STD::const_mem_fun_ref_t;
using __STD::mem_fun1_t;
using __STD::const_mem_fun1_t;
using __STD::mem_fun1_ref_t;
using __STD::const_mem_fun1_ref_t;
using __STD::mem_fun;
using __STD::mem_fun_ref;
using __STD::mem_fun1;
using __STD::mem_fun1_ref;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_FUNCTION_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef __SGI_STL_FUNCTIONAL
#define __SGI_STL_FUNCTIONAL
#include <stl_config.h>
#include <stddef.h>
#include <stl_function.h>
#endif /* __SGI_STL_FUNCTIONAL */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef __SGI_STL_HASH_MAP
#define __SGI_STL_HASH_MAP
#ifndef __SGI_STL_INTERNAL_HASHTABLE_H
#include <stl_hashtable.h>
#endif
#include <stl_hash_map.h>
#endif /* __SGI_STL_HASH_MAP */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef __SGI_STL_HASH_MAP_H
#define __SGI_STL_HASH_MAP_H
#ifndef __SGI_STL_INTERNAL_HASHTABLE_H
#include <stl_hashtable.h>
#endif
#include <algobase.h>
#include <stl_hash_map.h>
#ifdef __STL_USE_NAMESPACES
using __STD::hash;
using __STD::hashtable;
using __STD::hash_map;
using __STD::hash_multimap;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_HASH_MAP_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef __SGI_STL_HASH_SET
#define __SGI_STL_HASH_SET
#ifndef __SGI_STL_INTERNAL_HASHTABLE_H
#include <stl_hashtable.h>
#endif
#include <stl_hash_set.h>
#endif /* __SGI_STL_HASH_SET */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef __SGI_STL_HASH_SET_H
#define __SGI_STL_HASH_SET_H
#ifndef __SGI_STL_INTERNAL_HASHTABLE_H
#include <stl_hashtable.h>
#endif
#include <algobase.h>
#include <stl_hash_set.h>
#ifdef __STL_USE_NAMESPACES
using __STD::hash;
using __STD::hashtable;
using __STD::hash_set;
using __STD::hash_multiset;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_HASH_SET_H */

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef __SGI_STL_HASHTABLE_H
#define __SGI_STL_HASHTABLE_H
#include <stl_hashtable.h>
#include <algo.h>
#include <alloc.h>
#include <vector.h>
#ifdef __STL_USE_NAMESPACES
using __STD::hash;
using __STD::hashtable;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_HASHTABLE_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,46 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_HEAP_H
#define __SGI_STL_HEAP_H
#include <stl_config.h>
#include <stl_heap.h>
#ifdef __STL_USE_NAMESPACES
using __STD::push_heap;
using __STD::pop_heap;
using __STD::make_heap;
using __STD::sort_heap;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_HEAP_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,47 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_ITERATOR
#define __SGI_STL_ITERATOR
#include <stl_config.h>
#include <stl_relops.h>
#include <stddef.h>
#ifdef __STL_USE_NEW_IOSTREAMS
#include <iosfwd>
#else /* __STL_USE_NEW_IOSTREAMS */
#include <iostream.h>
#endif /* __STL_USE_NEW_IOSTREAMS */
#include <stl_iterator_base.h>
#include <stl_iterator.h>
#endif /* __SGI_STL_ITERATOR */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,113 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_ITERATOR_H
#define __SGI_STL_ITERATOR_H
#ifndef __SGI_STL_FUNCTION_H
#include <function.h>
#endif
#include <stddef.h>
#ifdef __STL_USE_NEW_IOSTREAMS
#include <iosfwd>
#else /* __STL_USE_NEW_IOSTREAMS */
#include <iostream.h>
#endif /* __STL_USE_NEW_IOSTREAMS */
#ifndef __SGI_STL_INTERNAL_ITERATOR_BASE_H
#include <stl_iterator_base.h>
#endif
#ifndef __SGI_STL_INTERNAL_ITERATOR_H
#include <stl_iterator.h>
#endif
#ifndef __TYPE_TRAITS_H
#include <type_traits.h>
#endif
#ifndef __SGI_STL_INTERNAL_CONSTRUCT_H
#include <stl_construct.h>
#endif
#ifndef __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H
#include <stl_raw_storage_iter.h>
#endif
#ifdef __STL_USE_NAMESPACES
// Names from stl_iterator.h
using __STD::input_iterator_tag;
using __STD::output_iterator_tag;
using __STD::forward_iterator_tag;
using __STD::bidirectional_iterator_tag;
using __STD::random_access_iterator_tag;
#if 0
using __STD::iterator;
#endif
using __STD::input_iterator;
using __STD::output_iterator;
using __STD::forward_iterator;
using __STD::bidirectional_iterator;
using __STD::random_access_iterator;
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
using __STD::iterator_traits;
#endif
using __STD::iterator_category;
using __STD::distance_type;
using __STD::value_type;
using __STD::distance;
using __STD::advance;
using __STD::insert_iterator;
using __STD::front_insert_iterator;
using __STD::back_insert_iterator;
using __STD::inserter;
using __STD::front_inserter;
using __STD::back_inserter;
using __STD::reverse_iterator;
using __STD::reverse_bidirectional_iterator;
using __STD::istream_iterator;
using __STD::ostream_iterator;
// Names from stl_construct.h
using __STD::construct;
using __STD::destroy;
// Names from stl_raw_storage_iter.h
using __STD::raw_storage_iterator;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_ITERATOR_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,537 @@
/*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/* NOTE: This is not portable code. Parts of numeric_limits<> are
* inherently machine-dependent. At present this file is suitable
* for the MIPS and ia32 architectures.
*/
#ifndef __SGI_CPP_LIMITS
#define __SGI_CPP_LIMITS
#include <limits.h>
#include <float.h>
#include <stl_config.h>
__STL_BEGIN_NAMESPACE
enum float_round_style {
round_indeterminate = -1,
round_toward_zero = 0,
round_to_nearest = 1,
round_toward_infinity = 2,
round_toward_neg_infinity = 3
};
enum float_denorm_style {
denorm_indeterminate = -1,
denorm_absent = 0,
denorm_present = 1
};
// The C++ standard (section 18.2.1) requires that some of the members of
// numeric_limits be static const data members that are given constant-
// initializers within the class declaration. On compilers where the
// __STL_STATIC_CONST_INIT_BUG macro is defined, it is impossible to write
// a standard-conforming numeric_limits class.
//
// There are two possible workarounds: either initialize the data
// members outside the class, or change them from data members to
// enums. Neither workaround is satisfactory: the former makes it
// impossible to use the data members in constant-expressions, and the
// latter means they have the wrong type and that it is impossible to
// take their addresses. We choose the former workaround.
#ifdef __STL_STATIC_CONST_INIT_BUG
# define __STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
enum { __mem_name = __mem_value }
#else /* __STL_STATIC_CONST_INIT_BUG */
# define __STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
static const __mem_type __mem_name = __mem_value
#endif /* __STL_STATIC_CONST_INIT_BUG */
// Base class for all specializations of numeric_limits.
template <class __number>
class _Numeric_limits_base {
public:
__STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, false);
static __number min() __STL_NOTHROW { return __number(); }
static __number max() __STL_NOTHROW { return __number(); }
__STL_DECLARE_LIMITS_MEMBER(int, digits, 0);
__STL_DECLARE_LIMITS_MEMBER(int, digits10, 0);
__STL_DECLARE_LIMITS_MEMBER(bool, is_signed, false);
__STL_DECLARE_LIMITS_MEMBER(bool, is_integer, false);
__STL_DECLARE_LIMITS_MEMBER(bool, is_exact, false);
__STL_DECLARE_LIMITS_MEMBER(int, radix, 0);
static __number epsilon() __STL_NOTHROW { return __number(); }
static __number round_error() __STL_NOTHROW { return __number(); }
__STL_DECLARE_LIMITS_MEMBER(int, min_exponent, 0);
__STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, 0);
__STL_DECLARE_LIMITS_MEMBER(int, max_exponent, 0);
__STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, 0);
__STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, false);
__STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, false);
__STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, false);
__STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
has_denorm,
denorm_absent);
__STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false);
static __number infinity() __STL_NOTHROW { return __number(); }
static __number quiet_NaN() __STL_NOTHROW { return __number(); }
static __number signaling_NaN() __STL_NOTHROW { return __number(); }
static __number denorm_min() __STL_NOTHROW { return __number(); }
__STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, false);
__STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, false);
__STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, false);
__STL_DECLARE_LIMITS_MEMBER(bool, traps, false);
__STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
__STL_DECLARE_LIMITS_MEMBER(float_round_style,
round_style,
round_toward_zero);
};
#ifdef __STL_STATIC_CONST_INIT_BUG
# define __STL_DEFINE_NUMERIC_BASE_MEMBER(__type, __mem)
#else /* __STL_STATIC_CONST_INIT_BUG */
# define __STL_DEFINE_NUMERIC_BASE_MEMBER(__type, __mem) \
template <class __number> \
const __type _Numeric_limits_base<__number>:: __mem
#endif /* __STL_STATIC_CONST_INIT_BUG */
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_specialized);
__STL_DEFINE_NUMERIC_BASE_MEMBER(int, digits);
__STL_DEFINE_NUMERIC_BASE_MEMBER(int, digits10);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_signed);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_integer);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_exact);
__STL_DEFINE_NUMERIC_BASE_MEMBER(int, radix);
__STL_DEFINE_NUMERIC_BASE_MEMBER(int, min_exponent);
__STL_DEFINE_NUMERIC_BASE_MEMBER(int, max_exponent);
__STL_DEFINE_NUMERIC_BASE_MEMBER(int, min_exponent10);
__STL_DEFINE_NUMERIC_BASE_MEMBER(int, max_exponent10);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, has_infinity);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, has_quiet_NaN);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, has_signaling_NaN);
__STL_DEFINE_NUMERIC_BASE_MEMBER(float_denorm_style, has_denorm);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, has_denorm_loss);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_iec559);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_bounded);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_modulo);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, traps);
__STL_DEFINE_NUMERIC_BASE_MEMBER(bool, tinyness_before);
__STL_DEFINE_NUMERIC_BASE_MEMBER(float_round_style, round_style);
// Base class for integers.
template <class _Int,
_Int __imin, _Int __imax,
int __idigits = -1, bool __ismod = true>
class _Integer_limits : public _Numeric_limits_base<_Int>
{
public:
__STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
static _Int min() __STL_NOTHROW { return __imin; }
static _Int max() __STL_NOTHROW { return __imax; }
__STL_DECLARE_LIMITS_MEMBER(int,
digits,
(__idigits < 0) ? (int)(sizeof(_Int) * CHAR_BIT)
- (__imin == 0 ? 0 : 1)
: __idigits);
__STL_DECLARE_LIMITS_MEMBER(int, digits10, (digits * 301) / 1000);
// log 2 = 0.301029995664...
__STL_DECLARE_LIMITS_MEMBER(bool, is_signed, __imin != 0);
__STL_DECLARE_LIMITS_MEMBER(bool, is_integer, true);
__STL_DECLARE_LIMITS_MEMBER(bool, is_exact, true);
__STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
__STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
__STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, __ismod);
};
#ifdef __STL_STATIC_CONST_INIT_BUG
# define __STL_DEFINE_INTEGER_LIMITS_MEMBER(__type, __mem)
#else /* __STL_STATIC_CONST_INIT_BUG */
# define __STL_DEFINE_INTEGER_LIMITS_MEMBER(__type, __mem) \
template <class _Int, _Int __imin, _Int __imax, int __idig, bool __ismod> \
const __type _Integer_limits<_Int, __imin, __imax, __idig, __ismod>::__mem
#endif /* __STL_STATIC_CONST_INIT_BUG */
__STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_specialized);
__STL_DEFINE_INTEGER_LIMITS_MEMBER(int, digits);
__STL_DEFINE_INTEGER_LIMITS_MEMBER(int, digits10);
__STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_signed);
__STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_integer);
__STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_exact);
__STL_DEFINE_INTEGER_LIMITS_MEMBER(int, radix);
__STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_bounded);
__STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_modulo);
// Base class for floating-point numbers.
template <class __number,
int __Digits, int __Digits10,
int __MinExp, int __MaxExp,
int __MinExp10, int __MaxExp10,
bool __IsIEC559,
float_round_style __RoundStyle>
class _Floating_limits : public _Numeric_limits_base<__number>
{
public:
__STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
__STL_DECLARE_LIMITS_MEMBER(int, digits, __Digits);
__STL_DECLARE_LIMITS_MEMBER(int, digits10, __Digits10);
__STL_DECLARE_LIMITS_MEMBER(bool, is_signed, true);
__STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
__STL_DECLARE_LIMITS_MEMBER(int, min_exponent, __MinExp);
__STL_DECLARE_LIMITS_MEMBER(int, max_exponent, __MaxExp);
__STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, __MinExp10);
__STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, __MaxExp10);
__STL_DECLARE_LIMITS_MEMBER(bool, has_infinity, true);
__STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN, true);
__STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, true);
__STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
has_denorm,
denorm_indeterminate);
__STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss, false);
__STL_DECLARE_LIMITS_MEMBER(bool, is_iec559, __IsIEC559);
__STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
__STL_DECLARE_LIMITS_MEMBER(bool, traps, true);
__STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
__STL_DECLARE_LIMITS_MEMBER(float_round_style, round_style, __RoundStyle);
};
#ifdef __STL_STATIC_CONST_INIT_BUG
# define __STL_DEFINE_FLOAT_LIMITS_MEMBER(__type, __mem)
#else /* __STL_STATIC_CONST_INIT_BUG */
# define __STL_DEFINE_FLOAT_LIMITS_MEMBER(__type, __mem) \
template <class __Num, int __Dig, int __Dig10, \
int __MnX, int __MxX, int __MnX10, int __MxX10, \
bool __IsIEEE, float_round_style __Sty> \
const __type _Floating_limits<__Num, __Dig, __Dig10, \
__MnX, __MxX, __MnX10, __MxX10, \
__IsIEEE, __Sty>:: __mem
#endif /* __STL_STATIC_CONST_INIT_BUG */
__STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, is_specialized);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(int, digits);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(int, digits10);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, is_signed);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(int, radix);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(int, min_exponent);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(int, max_exponent);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(int, min_exponent10);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(int, max_exponent10);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, has_infinity);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, has_quiet_NaN);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, has_signaling_NaN);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(float_denorm_style, has_denorm);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, has_denorm_loss);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, is_iec559);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, is_bounded);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, traps);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, tinyness_before);
__STL_DEFINE_FLOAT_LIMITS_MEMBER(float_round_style, round_style);
#undef __STL_DECLARE_NUMERIC_LIMITS_MEMBER
#undef __STL_DEFINE_NUMERIC_BASE_MEMBER
#undef __STL_DEFINE_INTEGER_LIMITS_MEMBER
#undef __STL_DEFINE_FLOAT_LIMITS_MEMBER
// Class numeric_limits
// The unspecialized class.
template<class _Tp>
class numeric_limits : public _Numeric_limits_base<_Tp> {};
// Specializations for all built-in integral types.
#ifndef __STL_NO_BOOL
__STL_TEMPLATE_NULL
class numeric_limits<bool>
: public _Integer_limits<bool, false, true, 1, false>
{};
#endif /* __STL_NO_BOOL */
__STL_TEMPLATE_NULL
class numeric_limits<char>
: public _Integer_limits<char, CHAR_MIN, CHAR_MAX>
{};
__STL_TEMPLATE_NULL
class numeric_limits<signed char>
: public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX>
{};
__STL_TEMPLATE_NULL
class numeric_limits<unsigned char>
: public _Integer_limits<unsigned char, 0, UCHAR_MAX>
{};
#ifdef __STL_HAS_WCHAR_T
__STL_TEMPLATE_NULL
class numeric_limits<wchar_t>
: public _Integer_limits<wchar_t, INT_MIN, INT_MAX>
{};
#endif
__STL_TEMPLATE_NULL
class numeric_limits<short>
: public _Integer_limits<short, SHRT_MIN, SHRT_MAX>
{};
__STL_TEMPLATE_NULL
class numeric_limits<unsigned short>
: public _Integer_limits<unsigned short, 0, USHRT_MAX>
{};
__STL_TEMPLATE_NULL
class numeric_limits<int>
: public _Integer_limits<int, INT_MIN, INT_MAX>
{};
__STL_TEMPLATE_NULL
class numeric_limits<unsigned int>
: public _Integer_limits<unsigned int, 0, UINT_MAX>
{};
__STL_TEMPLATE_NULL
class numeric_limits<long>
: public _Integer_limits<long, LONG_MIN, LONG_MAX>
{};
__STL_TEMPLATE_NULL
class numeric_limits<unsigned long>
: public _Integer_limits<unsigned long, 0, ULONG_MAX>
{};
#ifdef __STL_LONG_LONG
// Some compilers have long long, but don't define the
// LONGLONG_MIN and LONGLONG_MAX macros in limits.h. This
// assumes that long long is 64 bits.
#if !defined(LONGLONG_MIN) && !defined(LONGLONG_MAX) \
&& !defined(ULONGLONG_MAX)
#define ULONGLONG_MAX 0xffffffffffffffffLLU
#define LONGLONG_MAX 0x7fffffffffffffffLL
#define LONGLONG_MIN (-LONGLONG_MAX - 1LL)
#endif
__STL_TEMPLATE_NULL
class numeric_limits<long long>
: public _Integer_limits<long long, LONGLONG_MIN, LONGLONG_MAX>
{};
__STL_TEMPLATE_NULL
class numeric_limits<unsigned long long>
: public _Integer_limits<unsigned long long, 0, ULONGLONG_MAX>
{};
#endif /* __STL_LONG_LONG */
// Specializations for all built-in floating-point type.
__STL_TEMPLATE_NULL class numeric_limits<float>
: public _Floating_limits<float,
FLT_MANT_DIG, // Binary digits of precision
FLT_DIG, // Decimal digits of precision
FLT_MIN_EXP, // Minimum exponent
FLT_MAX_EXP, // Maximum exponent
FLT_MIN_10_EXP, // Minimum base 10 exponent
FLT_MAX_10_EXP, // Maximum base 10 exponent
true, // conforms to iec559
round_to_nearest>
{
public:
static float min() __STL_NOTHROW { return FLT_MIN; }
static float denorm_min() __STL_NOTHROW { return FLT_MIN; }
static float max() __STL_NOTHROW { return FLT_MAX; }
static float epsilon() __STL_NOTHROW { return FLT_EPSILON; }
static float round_error() __STL_NOTHROW { return 0.5f; } // Units: ulps.
static float infinity() __STL_NOTHROW;
static float quiet_NaN() __STL_NOTHROW;
static float signaling_NaN() __STL_NOTHROW;
};
__STL_TEMPLATE_NULL class numeric_limits<double>
: public _Floating_limits<double,
DBL_MANT_DIG, // Binary digits of precision
DBL_DIG, // Decimal digits of precision
DBL_MIN_EXP, // Minimum exponent
DBL_MAX_EXP, // Maximum exponent
DBL_MIN_10_EXP, // Minimum base 10 exponent
DBL_MAX_10_EXP, // Maximum base 10 exponent
true, // conforms to iec559
round_to_nearest>
{
public:
static double min() __STL_NOTHROW { return DBL_MIN; }
static double denorm_min() __STL_NOTHROW { return DBL_MIN; }
static double max() __STL_NOTHROW { return DBL_MAX; }
static double epsilon() __STL_NOTHROW { return DBL_EPSILON; }
static double round_error() __STL_NOTHROW { return 0.5; } // Units: ulps.
static double infinity() __STL_NOTHROW;
static double quiet_NaN() __STL_NOTHROW;
static double signaling_NaN() __STL_NOTHROW;
};
__STL_TEMPLATE_NULL class numeric_limits<long double>
: public _Floating_limits<long double,
LDBL_MANT_DIG, // Binary digits of precision
LDBL_DIG, // Decimal digits of precision
LDBL_MIN_EXP, // Minimum exponent
LDBL_MAX_EXP, // Maximum exponent
LDBL_MIN_10_EXP,// Minimum base 10 exponent
LDBL_MAX_10_EXP,// Maximum base 10 exponent
false, // Doesn't conform to iec559
round_to_nearest>
{
public:
static long double min() __STL_NOTHROW { return LDBL_MIN; }
static long double denorm_min() __STL_NOTHROW { return LDBL_MIN; }
static long double max() __STL_NOTHROW { return LDBL_MAX; }
static long double epsilon() __STL_NOTHROW { return LDBL_EPSILON; }
static long double round_error() __STL_NOTHROW { return 4; } // Units: ulps.
static long double infinity() __STL_NOTHROW;
static long double quiet_NaN() __STL_NOTHROW;
static long double signaling_NaN() __STL_NOTHROW;
};
// We write special values (Inf and NaN) as bit patterns and
// cast the the appropriate floating-point types.
#if defined(_MIPSEB)
// Big-endian MIPS. float is 32 bits, double 64, long double 128.
#define _Define_float(__f, __h, __l) \
inline float numeric_limits<float>::__f() __STL_NOTHROW { \
static const unsigned short __x[2] = { __h, __l }; \
return *reinterpret_cast<const float*>(__x); }
#define _Define_double(__f, __h, __l) \
inline double numeric_limits<double>::__f() __STL_NOTHROW { \
static const unsigned short __x[4] = { __h, __l }; \
return *reinterpret_cast<const double*>(__x); }
#define _Define_ldouble(__f, __h, __l) \
inline long double numeric_limits<long double>::__f() __STL_NOTHROW { \
static const unsigned short __x[8] = { __h, __l }; \
return *reinterpret_cast<const long double*>(__x); }
_Define_float(infinity, 0x7f80, 0)
_Define_float(quiet_NaN, 0x7f81, 0)
_Define_float(signaling_NaN, 0x7fc1, 0)
_Define_double(infinity, 0x7ff0, 0)
_Define_double(quiet_NaN, 0x7ff1, 0)
_Define_double(signaling_NaN, 0x7ff9, 0)
_Define_ldouble(infinity, 0x7ff0, 0)
_Define_ldouble(quiet_NaN, 0x7ff1, 0)
_Define_ldouble(signaling_NaN, 0x7ff9, 0)
#elif defined(__i386) || defined(_M_IX86)
// Little-endian ia32. float is 32 bits, double 64, long double 80.
#define _Define_float(__f, __h, __l) \
inline float numeric_limits<float>::__f() __STL_NOTHROW { \
static const unsigned short __x[2] = { __l, __h }; \
return *reinterpret_cast<const float*>(__x); }
#define _Define_double(__f, __h, __l) \
inline double numeric_limits<double>::__f() __STL_NOTHROW { \
static const unsigned short __x[4] = { 0, 0, __l, __h }; \
return *reinterpret_cast<const double*>(__x); }
#define _Define_ldouble(__f, __h, __l) \
inline long double numeric_limits<long double>::__f() __STL_NOTHROW { \
static const unsigned short __x[5] = { 0, 0, 0, __l, __h }; \
return *reinterpret_cast<const long double*>(__x); }
_Define_float(infinity, 0x7f80, 0)
_Define_float(quiet_NaN, 0x7fa0, 0)
_Define_float(signaling_NaN, 0x7fc0, 0)
_Define_double(infinity, 0x7ff0, 0)
_Define_double(quiet_NaN, 0x7ff4, 0)
_Define_double(signaling_NaN, 0x7ff8, 0)
_Define_ldouble(infinity, 0x7fff, 0x8000)
_Define_ldouble(quiet_NaN, 0x7fff, 0xa000)
_Define_ldouble(signaling_NaN, 0x7fff, 0xc000)
#else
/* This is an architecture we don't know how to handle. Return some
obviously wrong values. */
#define _Define_float(__f) \
inline float numeric_limits<float>::__f() __STL_NOTHROW { \
return 0; }
#define _Define_double(__f) \
inline double numeric_limits<double>::__f() __STL_NOTHROW { \
return 0; }
#define _Define_ldouble(__f) \
inline long double numeric_limits<long double>::__f() __STL_NOTHROW { \
return 0; }
_Define_float(infinity)
_Define_float(quiet_NaN)
_Define_float(signaling_NaN)
_Define_double(infinity)
_Define_double(quiet_NaN)
_Define_double(signaling_NaN)
_Define_ldouble(infinity)
_Define_ldouble(quiet_NaN)
_Define_ldouble(signaling_NaN)
#endif
#undef _Define_float
#undef _Define_double
#undef _Define_ldouble
__STL_END_NAMESPACE
#endif /* __SGI_CPP_LIMITS */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,40 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_LIST
#define __SGI_STL_LIST
#include <stl_algobase.h>
#include <stl_alloc.h>
#include <stl_construct.h>
#include <stl_uninitialized.h>
#include <stl_list.h>
#endif /* __SGI_STL_LIST */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,42 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_LIST_H
#define __SGI_STL_LIST_H
#include <algobase.h>
#include <alloc.h>
#include <stl_list.h>
#ifdef __STL_USE_NAMESPACES
using __STD::list;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_LIST_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,40 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_MAP
#define __SGI_STL_MAP
#ifndef __SGI_STL_INTERNAL_TREE_H
#include <stl_tree.h>
#endif
#include <stl_map.h>
#include <stl_multimap.h>
#endif /* __SGI_STL_MAP */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,46 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_MAP_H
#define __SGI_STL_MAP_H
#ifndef __SGI_STL_INTERNAL_TREE_H
#include <stl_tree.h>
#endif
#include <algobase.h>
#include <alloc.h>
#include <stl_map.h>
#ifdef __STL_USE_NAMESPACES
using __STD::rb_tree;
using __STD::map;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_MAP_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,134 @@
/*
* Copyright (c) 1997-1999
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef __SGI_STL_MEMORY
#define __SGI_STL_MEMORY
#include <stl_algobase.h>
#include <stl_alloc.h>
#include <stl_construct.h>
#include <stl_tempbuf.h>
#include <stl_uninitialized.h>
#include <stl_raw_storage_iter.h>
__STL_BEGIN_NAMESPACE
#if defined(__SGI_STL_USE_AUTO_PTR_CONVERSIONS) && \
defined(__STL_MEMBER_TEMPLATES)
template<class _Tp1> struct auto_ptr_ref {
_Tp1* _M_ptr;
auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
};
#endif
template <class _Tp> class auto_ptr {
private:
_Tp* _M_ptr;
public:
typedef _Tp element_type;
explicit auto_ptr(_Tp* __p = 0) __STL_NOTHROW : _M_ptr(__p) {}
auto_ptr(auto_ptr& __a) __STL_NOTHROW : _M_ptr(__a.release()) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class _Tp1> auto_ptr(auto_ptr<_Tp1>& __a) __STL_NOTHROW
: _M_ptr(__a.release()) {}
#endif /* __STL_MEMBER_TEMPLATES */
auto_ptr& operator=(auto_ptr& __a) __STL_NOTHROW {
if (&__a != this) {
delete _M_ptr;
_M_ptr = __a.release();
}
return *this;
}
#ifdef __STL_MEMBER_TEMPLATES
template <class _Tp1>
auto_ptr& operator=(auto_ptr<_Tp1>& __a) __STL_NOTHROW {
if (__a.get() != this->get()) {
delete _M_ptr;
_M_ptr = __a.release();
}
return *this;
}
#endif /* __STL_MEMBER_TEMPLATES */
// Note: The C++ standard says there is supposed to be an empty throw
// specification here, but omitting it is standard conforming. Its
// presence can be detected only if _Tp::~_Tp() throws, but (17.4.3.6/2)
// this is prohibited.
~auto_ptr() { delete _M_ptr; }
_Tp& operator*() const __STL_NOTHROW {
return *_M_ptr;
}
_Tp* operator->() const __STL_NOTHROW {
return _M_ptr;
}
_Tp* get() const __STL_NOTHROW {
return _M_ptr;
}
_Tp* release() __STL_NOTHROW {
_Tp* __tmp = _M_ptr;
_M_ptr = 0;
return __tmp;
}
void reset(_Tp* __p = 0) __STL_NOTHROW {
if (__p != _M_ptr) {
delete _M_ptr;
_M_ptr = __p;
}
}
// According to the C++ standard, these conversions are required. Most
// present-day compilers, however, do not enforce that requirement---and,
// in fact, most present-day compilers do not support the language
// features that these conversions rely on.
#if defined(__SGI_STL_USE_AUTO_PTR_CONVERSIONS) && \
defined(__STL_MEMBER_TEMPLATES)
public:
auto_ptr(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW
: _M_ptr(__ref._M_ptr) {}
auto_ptr& operator=(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW {
if (__ref._M_ptr != this->get()) {
delete _M_ptr;
_M_ptr = __ref._M_ptr;
}
return *this;
}
template <class _Tp1> operator auto_ptr_ref<_Tp1>() __STL_NOTHROW
{ return auto_ptr_ref<_Tp1>(this->release()); }
template <class _Tp1> operator auto_ptr<_Tp1>() __STL_NOTHROW
{ return auto_ptr<_Tp1>(this->release()); }
#endif /* auto ptr conversions && member templates */
};
__STL_END_NAMESPACE
#endif /* __SGI_STL_MEMORY */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,46 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_MULTIMAP_H
#define __SGI_STL_MULTIMAP_H
#ifndef __SGI_STL_INTERNAL_TREE_H
#include <stl_tree.h>
#endif
#include <algobase.h>
#include <alloc.h>
#include <stl_multimap.h>
#ifdef __STL_USE_NAMESPACES
using __STD::rb_tree;
using __STD::multimap;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_MULTIMAP_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,46 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_MULTISET_H
#define __SGI_STL_MULTISET_H
#ifndef __SGI_STL_INTERNAL_TREE_H
#include <stl_tree.h>
#endif
#include <algobase.h>
#include <alloc.h>
#include <stl_multiset.h>
#ifdef __STL_USE_NAMESPACES
using __STD::rb_tree;
using __STD::multiset;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_MULTISET_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,49 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_NUMERIC
#define __SGI_STL_NUMERIC
#include <stl_config.h>
#include <stl_relops.h>
#include <stddef.h>
#ifdef __STL_USE_NEW_IOSTREAMS
#include <iostream>
#else /* __STL_USE_NEW_IOSTREAMS */
#include <iostream.h>
#endif /* __STL_USE_NEW_IOSTREAMS */
#include <stl_iterator_base.h>
#include <stl_iterator.h>
#include <stl_function.h>
#include <stl_numeric.h>
#endif /* __SGI_STL_NUMERIC */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,51 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_PAIR_H
#define __SGI_STL_PAIR_H
#ifndef __STL_CONFIG_H
#include <stl_config.h>
#endif
#ifndef __SGI_STL_INTERNAL_RELOPS
#include <stl_relops.h>
#endif
#ifndef __SGI_STL_INTERNAL_PAIR_H
#include <stl_pair.h>
#endif
#ifdef __STL_USE_NAMESPACES
using __STD::pair;
using __STD::make_pair;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_PAIR_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,495 @@
/*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_PTHREAD_ALLOC
#define __SGI_STL_PTHREAD_ALLOC
// Pthread-specific node allocator.
// This is similar to the default allocator, except that free-list
// information is kept separately for each thread, avoiding locking.
// This should be reasonably fast even in the presence of threads.
// The down side is that storage may not be well-utilized.
// It is not an error to allocate memory in thread A and deallocate
// it in thread B. But this effectively transfers ownership of the memory,
// so that it can only be reallocated by thread B. Thus this can effectively
// result in a storage leak if it's done on a regular basis.
// It can also result in frequent sharing of
// cache lines among processors, with potentially serious performance
// consequences.
#include <errno.h>
#include <stl_config.h>
#include <stl_alloc.h>
#ifndef __RESTRICT
# define __RESTRICT
#endif
#ifndef __STL_NO_BAD_ALLOC
# include <new>
#endif
__STL_BEGIN_NAMESPACE
#define __STL_DATA_ALIGNMENT 8
union _Pthread_alloc_obj {
union _Pthread_alloc_obj * __free_list_link;
char __client_data[__STL_DATA_ALIGNMENT]; /* The client sees this. */
};
// Pthread allocators don't appear to the client to have meaningful
// instances. We do in fact need to associate some state with each
// thread. That state is represented by
// _Pthread_alloc_per_thread_state<_Max_size>.
template<size_t _Max_size>
struct _Pthread_alloc_per_thread_state {
typedef _Pthread_alloc_obj __obj;
enum { _S_NFREELISTS = _Max_size/__STL_DATA_ALIGNMENT };
_Pthread_alloc_obj* volatile __free_list[_S_NFREELISTS];
_Pthread_alloc_per_thread_state<_Max_size> * __next;
// Free list link for list of available per thread structures.
// When one of these becomes available for reuse due to thread
// termination, any objects in its free list remain associated
// with it. The whole structure may then be used by a newly
// created thread.
_Pthread_alloc_per_thread_state() : __next(0)
{
memset((void *)__free_list, 0, (size_t) _S_NFREELISTS * sizeof(__obj *));
}
// Returns an object of size __n, and possibly adds to size n free list.
void *_M_refill(size_t __n);
};
// Pthread-specific allocator.
// The argument specifies the largest object size allocated from per-thread
// free lists. Larger objects are allocated using malloc_alloc.
// Max_size must be a power of 2.
template <size_t _Max_size = 128>
class _Pthread_alloc_template {
public: // but only for internal use:
typedef _Pthread_alloc_obj __obj;
// Allocates a chunk for nobjs of size size. nobjs may be reduced
// if it is inconvenient to allocate the requested number.
static char *_S_chunk_alloc(size_t __size, int &__nobjs);
enum {_S_ALIGN = __STL_DATA_ALIGNMENT};
static size_t _S_round_up(size_t __bytes) {
return (((__bytes) + (int) _S_ALIGN-1) & ~((int) _S_ALIGN - 1));
}
static size_t _S_freelist_index(size_t __bytes) {
return (((__bytes) + (int) _S_ALIGN-1)/(int)_S_ALIGN - 1);
}
private:
// Chunk allocation state. And other shared state.
// Protected by _S_chunk_allocator_lock.
static pthread_mutex_t _S_chunk_allocator_lock;
static char *_S_start_free;
static char *_S_end_free;
static size_t _S_heap_size;
static _Pthread_alloc_per_thread_state<_Max_size>* _S_free_per_thread_states;
static pthread_key_t _S_key;
static bool _S_key_initialized;
// Pthread key under which per thread state is stored.
// Allocator instances that are currently unclaimed by any thread.
static void _S_destructor(void *instance);
// Function to be called on thread exit to reclaim per thread
// state.
static _Pthread_alloc_per_thread_state<_Max_size> *_S_new_per_thread_state();
// Return a recycled or new per thread state.
static _Pthread_alloc_per_thread_state<_Max_size> *_S_get_per_thread_state();
// ensure that the current thread has an associated
// per thread state.
class _M_lock;
friend class _M_lock;
class _M_lock {
public:
_M_lock () { pthread_mutex_lock(&_S_chunk_allocator_lock); }
~_M_lock () { pthread_mutex_unlock(&_S_chunk_allocator_lock); }
};
public:
/* n must be > 0 */
static void * allocate(size_t __n)
{
__obj * volatile * __my_free_list;
__obj * __RESTRICT __result;
_Pthread_alloc_per_thread_state<_Max_size>* __a;
if (__n > _Max_size) {
return(malloc_alloc::allocate(__n));
}
if (!_S_key_initialized ||
!(__a = (_Pthread_alloc_per_thread_state<_Max_size>*)
pthread_getspecific(_S_key))) {
__a = _S_get_per_thread_state();
}
__my_free_list = __a -> __free_list + _S_freelist_index(__n);
__result = *__my_free_list;
if (__result == 0) {
void *__r = __a -> _M_refill(_S_round_up(__n));
return __r;
}
*__my_free_list = __result -> __free_list_link;
return (__result);
};
/* p may not be 0 */
static void deallocate(void *__p, size_t __n)
{
__obj *__q = (__obj *)__p;
__obj * volatile * __my_free_list;
_Pthread_alloc_per_thread_state<_Max_size>* __a;
if (__n > _Max_size) {
malloc_alloc::deallocate(__p, __n);
return;
}
if (!_S_key_initialized ||
!(__a = (_Pthread_alloc_per_thread_state<_Max_size> *)
pthread_getspecific(_S_key))) {
__a = _S_get_per_thread_state();
}
__my_free_list = __a->__free_list + _S_freelist_index(__n);
__q -> __free_list_link = *__my_free_list;
*__my_free_list = __q;
}
static void * reallocate(void *__p, size_t __old_sz, size_t __new_sz);
} ;
typedef _Pthread_alloc_template<> pthread_alloc;
template <size_t _Max_size>
void _Pthread_alloc_template<_Max_size>::_S_destructor(void * __instance)
{
_M_lock __lock_instance; // Need to acquire lock here.
_Pthread_alloc_per_thread_state<_Max_size>* __s =
(_Pthread_alloc_per_thread_state<_Max_size> *)__instance;
__s -> __next = _S_free_per_thread_states;
_S_free_per_thread_states = __s;
}
template <size_t _Max_size>
_Pthread_alloc_per_thread_state<_Max_size> *
_Pthread_alloc_template<_Max_size>::_S_new_per_thread_state()
{
/* lock already held here. */
if (0 != _S_free_per_thread_states) {
_Pthread_alloc_per_thread_state<_Max_size> *__result =
_S_free_per_thread_states;
_S_free_per_thread_states = _S_free_per_thread_states -> __next;
return __result;
} else {
return new _Pthread_alloc_per_thread_state<_Max_size>;
}
}
template <size_t _Max_size>
_Pthread_alloc_per_thread_state<_Max_size> *
_Pthread_alloc_template<_Max_size>::_S_get_per_thread_state()
{
/*REFERENCED*/
_M_lock __lock_instance; // Need to acquire lock here.
int __ret_code;
_Pthread_alloc_per_thread_state<_Max_size> * __result;
if (!_S_key_initialized) {
if (pthread_key_create(&_S_key, _S_destructor)) {
__THROW_BAD_ALLOC; // defined in stl_alloc.h
}
_S_key_initialized = true;
}
__result = _S_new_per_thread_state();
__ret_code = pthread_setspecific(_S_key, __result);
if (__ret_code) {
if (__ret_code == ENOMEM) {
__THROW_BAD_ALLOC;
} else {
// EINVAL
abort();
}
}
return __result;
}
/* We allocate memory in large chunks in order to avoid fragmenting */
/* the malloc heap too much. */
/* We assume that size is properly aligned. */
template <size_t _Max_size>
char *_Pthread_alloc_template<_Max_size>
::_S_chunk_alloc(size_t __size, int &__nobjs)
{
{
char * __result;
size_t __total_bytes;
size_t __bytes_left;
/*REFERENCED*/
_M_lock __lock_instance; // Acquire lock for this routine
__total_bytes = __size * __nobjs;
__bytes_left = _S_end_free - _S_start_free;
if (__bytes_left >= __total_bytes) {
__result = _S_start_free;
_S_start_free += __total_bytes;
return(__result);
} else if (__bytes_left >= __size) {
__nobjs = __bytes_left/__size;
__total_bytes = __size * __nobjs;
__result = _S_start_free;
_S_start_free += __total_bytes;
return(__result);
} else {
size_t __bytes_to_get =
2 * __total_bytes + _S_round_up(_S_heap_size >> 4);
// Try to make use of the left-over piece.
if (__bytes_left > 0) {
_Pthread_alloc_per_thread_state<_Max_size>* __a =
(_Pthread_alloc_per_thread_state<_Max_size>*)
pthread_getspecific(_S_key);
__obj * volatile * __my_free_list =
__a->__free_list + _S_freelist_index(__bytes_left);
((__obj *)_S_start_free) -> __free_list_link = *__my_free_list;
*__my_free_list = (__obj *)_S_start_free;
}
# ifdef _SGI_SOURCE
// Try to get memory that's aligned on something like a
// cache line boundary, so as to avoid parceling out
// parts of the same line to different threads and thus
// possibly different processors.
{
const int __cache_line_size = 128; // probable upper bound
__bytes_to_get &= ~(__cache_line_size-1);
_S_start_free = (char *)memalign(__cache_line_size, __bytes_to_get);
if (0 == _S_start_free) {
_S_start_free = (char *)malloc_alloc::allocate(__bytes_to_get);
}
}
# else /* !SGI_SOURCE */
_S_start_free = (char *)malloc_alloc::allocate(__bytes_to_get);
# endif
_S_heap_size += __bytes_to_get;
_S_end_free = _S_start_free + __bytes_to_get;
}
}
// lock is released here
return(_S_chunk_alloc(__size, __nobjs));
}
/* Returns an object of size n, and optionally adds to size n free list.*/
/* We assume that n is properly aligned. */
/* We hold the allocation lock. */
template <size_t _Max_size>
void *_Pthread_alloc_per_thread_state<_Max_size>
::_M_refill(size_t __n)
{
int __nobjs = 128;
char * __chunk =
_Pthread_alloc_template<_Max_size>::_S_chunk_alloc(__n, __nobjs);
__obj * volatile * __my_free_list;
__obj * __result;
__obj * __current_obj, * __next_obj;
int __i;
if (1 == __nobjs) {
return(__chunk);
}
__my_free_list = __free_list
+ _Pthread_alloc_template<_Max_size>::_S_freelist_index(__n);
/* Build free list in chunk */
__result = (__obj *)__chunk;
*__my_free_list = __next_obj = (__obj *)(__chunk + __n);
for (__i = 1; ; __i++) {
__current_obj = __next_obj;
__next_obj = (__obj *)((char *)__next_obj + __n);
if (__nobjs - 1 == __i) {
__current_obj -> __free_list_link = 0;
break;
} else {
__current_obj -> __free_list_link = __next_obj;
}
}
return(__result);
}
template <size_t _Max_size>
void *_Pthread_alloc_template<_Max_size>
::reallocate(void *__p, size_t __old_sz, size_t __new_sz)
{
void * __result;
size_t __copy_sz;
if (__old_sz > _Max_size
&& __new_sz > _Max_size) {
return(realloc(__p, __new_sz));
}
if (_S_round_up(__old_sz) == _S_round_up(__new_sz)) return(__p);
__result = allocate(__new_sz);
__copy_sz = __new_sz > __old_sz? __old_sz : __new_sz;
memcpy(__result, __p, __copy_sz);
deallocate(__p, __old_sz);
return(__result);
}
template <size_t _Max_size>
_Pthread_alloc_per_thread_state<_Max_size> *
_Pthread_alloc_template<_Max_size>::_S_free_per_thread_states = 0;
template <size_t _Max_size>
pthread_key_t _Pthread_alloc_template<_Max_size>::_S_key;
template <size_t _Max_size>
bool _Pthread_alloc_template<_Max_size>::_S_key_initialized = false;
template <size_t _Max_size>
pthread_mutex_t _Pthread_alloc_template<_Max_size>::_S_chunk_allocator_lock
= PTHREAD_MUTEX_INITIALIZER;
template <size_t _Max_size>
char *_Pthread_alloc_template<_Max_size>
::_S_start_free = 0;
template <size_t _Max_size>
char *_Pthread_alloc_template<_Max_size>
::_S_end_free = 0;
template <size_t _Max_size>
size_t _Pthread_alloc_template<_Max_size>
::_S_heap_size = 0;
#ifdef __STL_USE_STD_ALLOCATORS
template <class _Tp>
class pthread_allocator {
typedef pthread_alloc _S_Alloc; // The underlying allocator.
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
template <class _NewType> struct rebind {
typedef pthread_allocator<_NewType> other;
};
pthread_allocator() __STL_NOTHROW {}
pthread_allocator(const pthread_allocator& a) __STL_NOTHROW {}
template <class _OtherType>
pthread_allocator(const pthread_allocator<_OtherType>&)
__STL_NOTHROW {}
~pthread_allocator() __STL_NOTHROW {}
pointer address(reference __x) const { return &__x; }
const_pointer address(const_reference __x) const { return &__x; }
// __n is permitted to be 0. The C++ standard says nothing about what
// the return value is when __n == 0.
_Tp* allocate(size_type __n, const void* = 0) {
return __n != 0 ? static_cast<_Tp*>(_S_Alloc::allocate(__n * sizeof(_Tp)))
: 0;
}
// p is not permitted to be a null pointer.
void deallocate(pointer __p, size_type __n)
{ _S_Alloc::deallocate(__p, __n * sizeof(_Tp)); }
size_type max_size() const __STL_NOTHROW
{ return size_t(-1) / sizeof(_Tp); }
void construct(pointer __p, const _Tp& __val) { new(__p) _Tp(__val); }
void destroy(pointer _p) { _p->~_Tp(); }
};
template<>
class pthread_allocator<void> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template <class _NewType> struct rebind {
typedef pthread_allocator<_NewType> other;
};
};
template <size_t _Max_size>
inline bool operator==(const _Pthread_alloc_template<_Max_size>&,
const _Pthread_alloc_template<_Max_size>&)
{
return true;
}
template <class _T1, class _T2>
inline bool operator==(const pthread_allocator<_T1>&,
const pthread_allocator<_T2>& a2)
{
return true;
}
template <class _T1, class _T2>
inline bool operator!=(const pthread_allocator<_T1>&,
const pthread_allocator<_T2>&)
{
return false;
}
template <class _Tp, size_t _Max_size>
struct _Alloc_traits<_Tp, _Pthread_alloc_template<_Max_size> >
{
static const bool _S_instanceless = true;
typedef simple_alloc<_Tp, _Pthread_alloc_template<_Max_size> > _Alloc_type;
typedef __allocator<_Tp, _Pthread_alloc_template<_Max_size> >
allocator_type;
};
template <class _Tp, class _Atype, size_t _Max>
struct _Alloc_traits<_Tp, __allocator<_Atype, _Pthread_alloc_template<_Max> > >
{
static const bool _S_instanceless = true;
typedef simple_alloc<_Tp, _Pthread_alloc_template<_Max> > _Alloc_type;
typedef __allocator<_Tp, _Pthread_alloc_template<_Max> > allocator_type;
};
template <class _Tp, class _Atype>
struct _Alloc_traits<_Tp, pthread_allocator<_Atype> >
{
static const bool _S_instanceless = true;
typedef simple_alloc<_Tp, _Pthread_alloc_template<> > _Alloc_type;
typedef pthread_allocator<_Tp> allocator_type;
};
#endif /* __STL_USE_STD_ALLOCATORS */
__STL_END_NAMESPACE
#endif /* __SGI_STL_PTHREAD_ALLOC */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 1996-1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_PTHREAD_ALLOC_H
#define __SGI_STL_PTHREAD_ALLOC_H
#include <pthread_alloc>
#ifdef __STL_USE_NAMESPACES
using __STD::_Pthread_alloc_template;
using __STD::pthread_alloc;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_PTHREAD_ALLOC_H */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,45 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_QUEUE
#define __SGI_STL_QUEUE
#include <stl_algobase.h>
#include <stl_alloc.h>
#include <stl_construct.h>
#include <stl_uninitialized.h>
#include <stl_vector.h>
#include <stl_bvector.h>
#include <stl_heap.h>
#include <stl_deque.h>
#include <stl_function.h>
#include <stl_queue.h>
#endif /* __SGI_STL_QUEUE */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_ROPE
#define __SGI_STL_ROPE
#include <stl_algobase.h>
#include <stl_tempbuf.h>
#include <stl_algo.h>
#include <stl_function.h>
#include <stl_numeric.h>
#include <stl_alloc.h>
#include <stl_construct.h>
#include <stl_uninitialized.h>
#include <stl_hash_fun.h>
#include <stl_rope.h>
#endif /* __SGI_STL_ROPE */
// Local Variables:
// mode:C++
// End:

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_ROPE_H
#define __SGI_STL_ROPE_H
#include <hashtable.h>
#include <stl_rope.h>
#ifdef __STL_USE_NAMESPACES
using __STD::char_producer;
using __STD::sequence_buffer;
using __STD::rope;
using __STD::crope;
using __STD::wrope;
#endif /* __STL_USE_NAMESPACES */
#endif /* __SGI_STL_ROPE_H */
// Local Variables:
// mode:C++
// End:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,204 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef STL_SEQUENCE_CONCEPTS_H
#define STL_SEQUENCE_CONCEPTS_H
#include <container_concepts.h>
#ifdef __STL_USE_CONCEPT_CHECKS
// This file covers the following concepts:
// _Sequence
// _FrontInsertionSequence
// _BackInsertionSequence
struct _ERROR_IN_STL_SEQ {
template <class _XX>
static void
__fill_constructor_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
typename _XX::difference_type __n = typename _XX::difference_type();
_XX __x(__n, __t);
__sink_unused_warning(__x);
}
template <class _XX>
static void
__fill_default_constructor_requirement_violation(_XX& __s) {
_STL_ERROR::__default_constructor_requirement_violation(*__s.begin());
typename _XX::difference_type __n = typename _XX::difference_type();
_XX __x(__n);
__sink_unused_warning(__x);
}
template <class _XX>
static void
__range_constructor_requirement_violation(_XX& __s) {
_XX __x(__s.begin(), __s.end());
__sink_unused_warning(__x);
}
template <class _XX>
static void
__insert_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
typename _XX::iterator __p = typename _XX::iterator();
__p = __s.insert(__p, __t);
}
template <class _XX>
static void
__fill_insert_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
typename _XX::iterator __p = typename _XX::iterator();
typename _XX::difference_type __n = typename _XX::difference_type();
__s.insert(__p, __n, __t);
}
template <class _XX>
static void
__range_insert_function_requirement_violation(_XX& __s) {
typename _XX::iterator __p = typename _XX::iterator();
typename _XX::iterator __i = typename _XX::iterator();
typename _XX::iterator __j = typename _XX::iterator();
__s.insert(__p, __i, __j);
}
template <class _XX>
static void
__insert_element_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
std::pair<typename _XX::iterator, bool> __r;
__r = __s.insert(__t);
__sink_unused_warning(__r);
}
template <class _XX>
static void
__unconditional_insert_element_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
typename _XX::iterator __p;
__p = __s.insert(__t);
__sink_unused_warning(__p);
}
template <class _XX>
static void
__erase_function_requirement_violation(_XX& __s) {
typename _XX::iterator __p = typename _XX::iterator();
__p = __s.erase(__p);
}
template <class _XX>
static void
__range_erase_function_requirement_violation(_XX& __s) {
typename _XX::iterator __p = typename _XX::iterator();
typename _XX::iterator __q = typename _XX::iterator();
__p = __s.erase(__p, __q);
}
template <class _XX>
static void
__const_front_function_requirement_violation(const _XX& __s) {
typename _XX::const_reference __t = __s.front();
__sink_unused_warning(__t);
}
template <class _XX>
static void
__front_function_requirement_violation(_XX& __s) {
typename _XX::reference __t = __s.front();
__const_front_function_requirement_violation(__s);
__sink_unused_warning(__t);
}
template <class _XX>
static void
__const_back_function_requirement_violation(const _XX& __s) {
typename _XX::const_reference __t = __s.back();
__sink_unused_warning(__t);
}
template <class _XX>
static void
__back_function_requirement_violation(_XX& __s) {
typename _XX::reference __t = __s.back();
__const_back_function_requirement_violation(__s);
__sink_unused_warning(__t);
}
template <class _XX>
static void
__push_front_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
__s.push_front(__t);
}
template <class _XX>
static void
__pop_front_function_requirement_violation(_XX& __s) {
__s.pop_front();
}
template <class _XX>
static void
__push_back_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
__s.push_back(__t);
}
template <class _XX>
static void
__pop_back_function_requirement_violation(_XX& __s) {
__s.pop_back();
}
};
/* Sequence Containers */
template <class _Sequence>
struct _Sequence_concept_specification {
static void
_Sequence_requirement_violation(_Sequence __s) {
// Refinement of ForwardContainer
_ForwardContainer_concept_specification<_Sequence>::_ForwardContainer_requirement_violation(__s);
// Refinement of DefaultConstructible
_DefaultConstructible_concept_specification<_Sequence>::_DefaultConstructible_requirement_violation(__s);
// Valid Expressions
_ERROR_IN_STL_SEQ::__fill_constructor_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__fill_default_constructor_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__range_constructor_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__insert_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__fill_insert_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__range_insert_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__erase_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__range_erase_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__front_function_requirement_violation(__s);
}
};
template <class _FrontInsertionSequence>
struct _FrontInsertionSequence_concept_specification {
static void
_FrontInsertionSequence_requirement_violation(_FrontInsertionSequence __s) {
// Refinement of Sequence
_Sequence_concept_specification<_FrontInsertionSequence>::_Sequence_requirement_violation(__s);
// Valid Expressions
_ERROR_IN_STL_SEQ::__push_front_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__pop_front_function_requirement_violation(__s);
}
};
template <class _BackInsertionSequence>
struct _BackInsertionSequence_concept_specification {
static void
_BackInsertionSequence_requirement_violation(_BackInsertionSequence __s) {
// Refinement of Sequence
_Sequence_concept_specification<_BackInsertionSequence>::_Sequence_requirement_violation(__s);
// Valid Expressions
_ERROR_IN_STL_SEQ::__back_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__push_back_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__pop_back_function_requirement_violation(__s);
}
};
#endif /* if __STL_USE_CONCEPT_CHECKS */
#endif /* STL_SEQUENCE_CONCEPTS_H */

View File

@ -0,0 +1,40 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __SGI_STL_SET
#define __SGI_STL_SET
#ifndef __SGI_STL_INTERNAL_TREE_H
#include <stl_tree.h>
#endif
#include <stl_set.h>
#include <stl_multiset.h>
#endif /* __SGI_STL_SET */
// Local Variables:
// mode:C++
// End:

Some files were not shown because too many files have changed in this diff Show More