Add stuff missing from yesterday's library commit.

git-svn-id: svn://localhost/ardour2/trunk@2643 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2007-11-13 10:29:44 +00:00
parent c660fd3129
commit 89f1f09c04
207 changed files with 16612 additions and 27866 deletions

View file

@ -1,13 +0,0 @@
Makefile
Makefile.in
aclocal.m4
autom4te.cache
config.log
config.status
configure
glibmm-2.4.pc
glibmmconfig.h
libtool
stamp-h1
*.os
*.dylib

View file

@ -1,20 +0,0 @@
Please use the mailing list (gtkmm-list@gnome.org) instead of emailing developers directly.
See the ChangeLog for up-to-date information.
Murray Cumming <murrayc@usa.net>
Daniel Elstner <daniel.elstner@gmx.net>
Some former contributors:
Karl Nelson <kenelson@ece.ucdavis.edu>
Tero Pulkkinen <terop@modeemi.cs.tut.fi>
Elliot Lee <sopwith@redhat.com>
Phil Dawes <P.L.Dawes-CSSE94@cs.bham.ac.uk>
Erik Andersen <andersee@debian.org>
Bibek Sahu <scorpio@dodds.net>
Mirko Streckenbach
Havoc Pennington <hp@pobox.com>
Guillaume Laurent <glaurent@telegraph-road.org>
Todd Dukes <tdukes@ibmoto.com>
Peter Lerner <peter.lerner@bnbt.de>
Herbert Valerio Riedel <hvr@gnu.org>

View file

@ -1,33 +0,0 @@
Changes between glibmm 2.2 (previously part of gtkmm) and glibmm 2.4:
* glibmm is now a separate module, for use with non-GUI software.
(Note that glibmm 2.4 and gtkmm 2.4 install in parallel with
gtkmm 2.2 - so you can install and use both simultaneously and
port to 2.4 whenever you are ready.)
* glibmm now uses libsigc++ 2 rather than libsigc++ 1.2.
There is a libsigc++ compatibility header. The new, undeprecated, API
is slightly improved.
- Connecting signal handlers:
signal_something().connect( SigC::slot(*this, &Something::on_something) );
should become
signal_something().connect( sigc::mem_fun(*this, &Something::on_something) );
or, for non-member methods:
signal_something().connect( sigc::ptr_fun(&Something::on_something) );
- Binding extra parameters:
SigC::bind(...)
should become
sigc::bind(...)
- Declaring signals:
SigC::Signal1<void, int>
should become
sigc::signal<void, int>
- Declaring slots:
SigC::Slot1<void, int>
should become
sigc::slot<void,int>
- Inheriting from the libsigc++ base class:
class Something : public SigC::Object
should become
class Something : public sigc::trackable

View file

@ -1,515 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 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.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations
below.
When we speak of free software, we are referring to freedom of use,
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 and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
^L
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it
becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
^L
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, 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 library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete 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 distribute a copy of this License along with the
Library.
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 Library or any portion
of it, thus forming a work based on the Library, 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) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
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 Library, 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 Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
^L
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you 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.
If distribution of 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 satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
^L
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be 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.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
^L
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library 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.
9. 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 Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
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 with
this License.
^L
11. 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 Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library 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 Library.
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.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library 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.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser 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 Library
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 Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
^L
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
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
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "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
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. 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 LIBRARY 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
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
^L
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms
of the ordinary General Public License).
To apply these terms, attach the following notices to the library.
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 library's name and a brief idea of what it
does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; 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.
You should also get your employer (if you work as a programmer) or
your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James
Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

File diff suppressed because it is too large Load diff

View file

@ -1,236 +0,0 @@
Installation Instructions
*************************
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free
Software Foundation, Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
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, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. (Caching is
disabled by default to prevent problems with accidental use of stale
cache files.)
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 you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You only need
`configure.ac' 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. Run `./configure --help' for
details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
*Note Defining Variables::, for more details.
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 support 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' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' 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' cannot figure out automatically,
but needs to determine by the type of machine the package will run on.
Usually, assuming the package is built to be run on the _same_
architectures, `configure' can figure that out, but if it prints a
message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS KERNEL-OS
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 machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
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.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script). Here is a another example:
/bin/bash ./configure CONFIG_SHELL=/bin/bash
Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent
configuration-related scripts to be executed by `/bin/bash'.
`configure' Invocation
======================
`configure' recognizes the following options to control how it operates.
`--help'
`-h'
Print a summary of the options to `configure', and exit.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--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.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.

View file

@ -1,64 +0,0 @@
ACLOCAL_AMFLAGS = -I scripts
SUBDIRS = tools glib examples docs scripts tests MSVC_Net2003
DIST_SUBDIRS = $(SUBDIRS)
EXTRA_DIST = build_shared/Makefile_build.am_fragment \
build_shared/Makefile_build_gensrc.am_fragment \
build_shared/Makefile_gensrc.am_fragment \
build_shared/Makefile_gensrc_platform.am_fragment \
build_shared/Makefile_build_extra.am_fragment \
CHANGES README.win32
all-local:
@echo "*** Everything completed ***"
dist-hook:
@echo; echo; \
echo "**********************************************************"; \
echo "* IMPORTANT NOTICE: *"; \
echo "* *"; \
echo "* Be sure you have done a complete build before running *"; \
echo "* 'make dist' or 'make distcheck', because otherwise *"; \
echo "* the tarball will _not_ contain the dependency rules *"; \
echo "* generated by the compiler. *"; \
echo "**********************************************************"; \
echo; echo
include $(top_srcdir)/docs/Makefile_web.am_fragment
doc_tarball_files = \
docs/images/*.gif \
docs/internal/*.txt docs/internal/*.dia docs/reference/html
# This doesn't work very well in a $(srcdir) != $(builddir) setup,
# but this target is for maintainer use only anyway.
glibmm-docs.tar.gz:
find examples -name '*.cc' -o -name '*.h' -o -name '*.xpm' -o -name '*.xml' | \
tar cf - --files-from - $(doc_tarball_files) | gzip -c --best >$@
# Upload documentation and examples:
post-html-recursive:
list='docs examples'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) post-html); \
done
post-html-local: glibmm-docs.tar.gz
rsync $(rsync_args) glibmm-docs.tar.gz $$USER@$(web_host):$(web_path_gtkmm)
post-html: post-html-recursive post-html-local
doc-clean-recursive:
(cd docs && $(MAKE) $(AM_MAKEFLAGS) doc-clean)
doc-clean: doc-clean-recursive
doc-rebuild:
(cd docs && $(MAKE) $(AM_MAKEFLAGS) doc-rebuild)
.PHONY: post-html post-html-local post-html-recursive doc-clean doc-clean-recursive doc-rebuild

View file

@ -1,399 +0,0 @@
2.13.3:
* gmmproc improvements:
- gmmproc: Allow () in property and signal docuemntation.
- gmmproc: Do not try to remove a common prefix from the
C enam values, if there is no common prefix.
- enum.pl: Allow whitespace in front of an enum typedef.
(Daniel Elstner)
- enum.pl: Fix an infinite loop.
* ObjectBase: Added connect_property_changed(),
as an alternative to use when the property proxies are not
available because GLIBMM_PROPERTIES_ENABLED is not defined.
(Murray Cumming)
* Value: When registering float parameters, use
G_MAXFLOAT as the minimum, instead of G_MINFLOAT.
Likewise for doubles.
(Oliver Nittka)
2.13.2:
*Build:
- Fix for api-default-signal-handlers option.
Bug #357830 (Matt Hoosier)
- win32: Remove unused source file from Visual Studio project.
(Cedric Gustin)
2.13.1:
* KeyFile class added, wrapping GKeyFile,
for parsing of .ini-style files.
(Rob Page)
* Added get_user_data_dir(), get_user_config_dir(), and
get_user_cache_dir().
(Jonathon Jongsma)
* Support optional ifdef parameters in the .hg macros,
to allow, for instance the --enable-atk=no option,
to disable the build and use of the atkmm API,
for use in embedded environments.
(Johannes Schimd, Murray Cuming, Openismus)
* Documentation:
- Small ustring reference documentation improvement.
(Ralf Stephan)
2.12.0:
Changes sinze 2.10:
* Added the --enable-api-default-signal-handlers option, for use in
embedded environments that have reduced resources. See configure --help
for the other subsets.
* Value: Added init(const GValue*), so we can copy GValue instances
of any type at runtime. Needed by the new branch of libgdamm.
2.11.3:
* Build: Added the --enable-api-default-signal-handlers option, for use in
embedded environments that have reduced resources. See configure --help
for the other subsets.
2.11.2:
* Date: Fix implementation of Glib::Date::set_time_current() so
that it doesn't set the date to Dec 31, 1969.
(Jonathon Jongsma)
* Value: Added init(const GValue*), so we can copy GValue instances
of any type at runtime. Needed by the new branch of libgdamm.
(Murray Cumming)
* Added a #warning to warn about including X11/Xlib.h before a glibmm header,
which would break things. Bug #316726 from Mert Tugcu and Javeed Shaikh.
(Murray Cumming)
* Build:
- Quote some m4 macros to avoid warnings. Bugs (with patches) #347076
and #347077
(Kevin McBride).
- Fix exporting of get/set_property() on mingw32-gcc.
(Cedric Gustin)
2.10.1
* Windows Build:
- Define GLIBMM_DLL when building with mingw32 or cygwin,
because it is needed by gtkmm. Bug #309030
(Cedric Gustin)
* OptionGroup: Allow default values, by not initializing them all.
(Armin Burgmeier)
* Slight code size reduction by marking private functions as static.
(Murray Cumming)
2.10.0:
* Windows Build:
- ustring.h: Tag npos with GLIBMM_API, in order to
dllexport it on win32. Bug #332438.
- Updated MSVC++ build files and README, for MS Visual Studio 2005.
(Cedric Gustin)
* gmmproc code generator:
- WRAP_METHOD() Take an extra optional argument: deprecated deprecationtext -
so that we can insert the appropriate doxygen tag in the documentation, where
the C documentation does not do it for us.
2.9.1:
* Date:
- Added set_time(time_t), set_time(GTimeVal), and deprecated
set_time(GTime)
- Added set_time_current().
(Murray Cumming)
* Build: Added --enable-deprecated-api option. When set to disabled,
it does not build deprecated API. This reduces the size of the
library, and might be useful for embedded devices.
(Murray Cumming)
2.8.2:
* Solaris build fix: Correct the detection
of make. (Mark Rouchal)
2.8.1:
* Build: Check for glib 2.8.
2.8.0:
API additions since glibmm 2.6:
* GModule: Add BIND_LOCAL enum value.
(Bug #172748 from Phillip Neiswanger).
* MainContext Added signal_child_watch()
and examples/child_watch.
(Yair Hershkovitz)
* OptionEntry: Added FLAG_NO_ARG, FLAG_FILENAME,
FLAG_OPTIONAL_ARG, and FLAG_NOALIAS enum values.
(Murray Cumming)
2.7.3:
* Updated reference documentation from glib documentation.
2.7.2:
* OptionEntry: Added FLAG_NO_ARG, FLAG_FILENAME,
FLAG_OPTIONAL_ARG, and FLAG_NOALIAS enum values.
* build_filename() and build_path(): Now use the implementation
from glib.
2.7.1:
* GModule: Add BIND_LOCAL enum value.
(Bug #172748 from Phillip Neiswanger).
* MainContext Added signal_child_watch()
and examples/child_watch.
(Yair Hershkovitz)
* Fixes from 2.6.2.
2.6.1:
* Interface::add_interface(): Disabled the check for a second call,
introduced in 2.6.0, for now, because it stops some valid uses.
(Bryan Forbes)
2.6.0:
New stable version. Changes compare to glibmm 2.4.x:
* Added Option, OptionContext, OptionGroup for parsing of command-line arguments.
* Added filename_display_basename() and filename_display_name().
* Added setenv() and unsetenv().
* add_interface() methods will no longer give warnings if you
call them twice.
* gmmproc:
- Now reuses C properties documentation.
2.5.6:
* add_interface() methods will no longer give warnings if you
call them twice.
* gmmproc: Output properties documentation taken from the .defs.
* examples now build on AIX.
(Murray Cumming)
* MSVC++ .Net 2003 build fix. (Cedric Gustin)
2.5.5:
* Now builds with the following compilers, in addition to
the existing GNU g++, and Intel compilers:
- SUN Forte CC 5.5
- IBM AIX xlC v7
- Tru64 C++ V6.5-042
- IRIX MIPSpro 7.4.2m
(Older versions of all these compilers might also work.)
(Murray Cumming, www.thewrittenword.com)
* Now builds with MSVC++ .Net 2003 (gtkmm 2.4 already did).
(Cedric Gustin)
2.5.4:
Options:
* Added Option(GOptionGroup* cast_item) constructor,
needed by Gtk::Main.
* Added reference documentation.
(Murray Cumming)
2.5.3:
* Options:
- Allow parsing of boolean arguments (arguments with no value).
- Really use the short names.
(Daniel Holbach, Murray Cumming)
* Added filename_display_basename() and filename_display_name().
(Murray Cumming)
* Added setenv() and unsetenv(). (Murray Cumming)
* Use static keyword to prevent exporting private API.
(Benoît Dejean)
* input example: Improvements and simplification. (Chris Vine)
2.5.2:
* OptionEntry: Remove useless enum. (Murray Cumming)
* Documentation:
- examples: Added iochannel_stream example. (Chris Vine)
- reference: Generate more reference API from the C documentation, and
try to use the libstdc++ doxygen tags file to link to their
documentation. (Murray Cumming)
2.5.1:
* OptionContext, OptionGroup, OptionEntry: Made the add_entry() methods
type-safe and fixed several problems memory-management problems. This
API is now worth looking at.
2.5.0:
* Added OptionContext, OptionGroup, and OptionEntry classes, for
parsing of command-line options. See examples/options/
2.4.4:
* Signals: Avoid crashes when disconnecting a signal when handling that signal.
(Murray Cumming, Martin Schulze)
*
2.4.3:
* Minor improvements to reference documentation. (Daniel Elstner)
* Minor Glib::Dispatcher improvements (Daniel Elstner)
2.4.2:
* Glib::Dispatcher: win32 implementation rewritten, and hopefully, improved.
(Daniel Elstner)
* Glib::ustring:
- Optimization and code-cleanup. (Daniel Elstner)
- Added reference documentation for constuctors. (Murray Cumming)
* Fixed some compiler warnings.
(Daniel Elstner)
* gmmproc: Some improvements for libgdamm. (Murray Cumming)
2.4.1:
* Build fixes for gcc 3.4.0.
* Doxygen not required when building from tarballs.
(Murray Cumming)
2.4.0:
Changes since 2.2.0:
* Now separate from gtkmm, so you can use things like Glib::ustring without depending on gtkmm. This glibmm 2.4 API installs in parallel with gtkmm 2.0/2.2, so you can install applications which use either.
* When using pkg-config, you should check for "glibmm-2.4".
* Glib::ObjectBase inherits virtually from SigC::Object, allowing multiple inheritance with other classes that inherit from SigC::Object.
* RefPtr:
- is_null() was removed, to encourage you to use "== 0" instead.
- operator=(CppObject*) was removed.
* The gtkmmproc code-generator is now gmmproc, and has several improvements to support gtkmm 2.4.
* Now uses improved libsigc++ 2.0 API.
* Added i18n.h and i18n-lib.h, which include the relevant
glib headers, which declare internationalization
macros such as _().
* New methods:
Glib::spawn_close_id(), Glib::MainLoop::depth(),
Glib::Date::clamp_min(), Glib::Date::clamp_max().
* Improved documentation.
2.3.8:
* Fix crash when using Glib::Main signals.
(Martin Schulze)
* Corrected the configure-time SUN compiler check.
(Murray Cumming, Alexander Nedotsukov)
2.3.7:
* Added configure macros to detect SUN compiler oddities.
* Various SUN Forte C+ and g++ 3.4 (cvs) build fixes.
(Murray Cumming)
* gmmproc: Improved parsing of C docs.
(Hagen Moebius)
2.3.6:
* Added i18n.h and i18n-lib.h, which include the relevant
glib headers, which declare internationalization
macros such as _(). (Murray Cumming)
* Added Glib::spawn_close_id(). (Murray Cumming)
* Added Glib::MainLoop::depth(). (Murray Cumming)
* Documentation: corrections to CHANGES (Martin Schulze).
* gmmproc: Can now handle "const const_iterator& iter"
parameter names without getting confused by 2 consts.
(Murray Cumming)
2.3.5:
* glibmm now uses libsigc++ 2 rather than libsigc++ 1.2.
2.3.4:
* ListHandle/SListHandle (intermediate container types):
- Added a const_cast<> to allow lists of const elements.
* gmmproc: _WRAP_SIGNAL(): Added optional custom_c_callback
parameter.
(Murray Cumming)
* WIN32: Build fixes, mostly merged from the 2.2 branch.
(Cedric Gustin)
2.3.3:
* gmmproc (code generator)
- properties: Make read-only properties have const accessors,
and add a second read-only const accessor for normal
properties. Wrap construct-only properties as read-only,
instead of ignoring them.
- vfuncs: Really generate const vfuncs when requested. Put
the method declaration directly into the .h file, so that
the doxygen documentation can be next to it.
- documentation:
- Remove mergecdocs configure option - always
merge the C docs, to avoid any risk of uploading or
releasing empty documentation. Just delete the *_docs.xml
files to make building from cvs faster.
- Install a GLIBMM_CHECK_PERL() macro, for use by gtkmm
and other *mm projects, to get the perl path needed by
doxygen.
- Install beautify_docs.pl so it can be reused in gtkmm
and other *mm projects, instead of having lots of copies.
* Glib::ObjectBase: The default constructor, never before used,
now generates a custom GType, for use when creating new
implementations of Glib::Interfaces - for instance, see the
new custom tree model example in gtkmm.
* Glib::Date: Added clamp_min() and clamp_max().
(Murray Cumming)
* Documentation:
- Added reference documentation for MainLoop, MainContext,
Source, and Date. (Alberto Paro)
2.3.2:
* gmmproc (code generator):
- signal proxies have extra space to avoid << with templates.
- Added WRAP_METHOD_DOCS_ONLY() for reusing documentation even
when the method is hand-coded.
- _WRAP_SIGNAL(): Added optional no_default_handler parameter,
because some of the new GTK+ signals have no public default
handler vfunc.
* Added Glib::init(), for use by non-GUI apps which need to
use Glib::wrap().
* PropertyProxy: Can now be used with Interfaces.
* Documentation improvements, so that gtkmm docs link to glibmm
docs.
(Murray Cumming)
2.3.1:
* gmmproc changes needed by gtkmm 2.3.0
(Murray Cumming)
* examples updated and buildable and working,
without gtkmm code.
(J. Abelardo Gutierrez)
Changes in glibmm 2.3.0:
* Now separate from gtkmm, so you can use things like Glib::ustring without depending on gtkmm.
This glibmm 2.4 API installs in parallel with gtkmm 2.0/2.2, so you can install this unstable library
without the risk of breaking existing application.
* This does not yet require glib 2.3 because there has been no tarball release of that yet. For now, you
can use glibmm 2.3.0 with glib 2.2.x.
* When using pkg-config, you should check for "glibmm-2.4".
* Glib::ObjectBase inherits virtually from SigC::Object, allowing multiple inheritance with other
classes that inherit from SigC::Object.
* RefPtr:
- is_null() was removed, to encourage you to use "== 0" instead.
- operator=(CppObject*) was removed.
* gtkmmproc is now gmmproc.
* All the glibmm bugfixes in gtkmm 2.2.x.

View file

@ -1,4 +0,0 @@
This is glibmm, a C++ API for parts of glib that are useful for C++.
See http://www.gtkmm.org

View file

@ -1,48 +0,0 @@
# -*- python -*-
import os
import os.path
import glob
glibmm2_files = glob.glob('glib/glibmm/*.cc')
Import('env libraries install_prefix')
glibmm2 = env.Copy()
glibmm2.Merge([libraries['sigc2'], libraries['glib2'], libraries['glibmm2']])
glibmm2.Append(CXXFLAGS=['-DHAVE_CONFIG_H', '-DGLIBMM_EXCEPTIONS_ENABLED', '-DGLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED', '-DGLIBMM_PROPERTIES_ENABLED'])
#glibmm2.Append(CXXFLAGS='-DG_DISABLE_DEPRECATED')
glibmm2.Append(CXXFLAGS='-DG_LOG_DOMAIN=\\\"glibmm\\\"')
libglibmm2 = glibmm2.SharedLibrary('glibmm2', glibmm2_files)
if os.access ('autogen.sh', os.F_OK) :
glibmm2_configure_script = glibmm2.Command ('configure', 'configure.ac', 'cd libs/glibmm2; ./autogen.sh; cd -', ENV=os.environ)
glibmm2_config_h = glibmm2.Command('glibmmconfig.h', [glibmm2_configure_script, 'glibmmconfig.h.in'],
'cd libs/glibmm2; ./configure || exit 1; cd -', ENV=os.environ)
else :
glibmm2_config_h = glibmm2.Command('glibmmconfig.h', ['configure', 'glibmmconfig.h.in'],
'cd libs/glibmm2; ./configure || exit 1; cd -', ENV=os.environ)
Default([glibmm2_config_h, libglibmm2])
env.Alias('install', env.Install(os.path.join(install_prefix, env['LIBDIR'], 'ardour2'), libglibmm2))
env.Alias('tarball', env.Distribute (env['DISTTREE'],
[ 'SConscript',
'glibmm.h',
'configure',
'Makefile.in',
'glibmmconfig.h',
'glibmmconfig.h.in',
'glibmm-2.4.pc.in',
'glibmm/Makefile.in',
'scripts'
] +
glibmm2_files +
glob.glob('glibmm/*.h') +
glob.glob('glibmm/private/*.h')
))

View file

@ -1,40 +0,0 @@
#! /bin/sh
# check all tools first
if /usr/bin/which libtoolize >/dev/null 2>&1 ; then
:
else
echo "You do not have libtool installed, which is very sadly required to build part of Ardour"
exit 1
fi
if /usr/bin/which automake >/dev/null 2>&1 ; then
:
else
echo "You do not have automake installed, which is very sadly required to build part of Ardour"
exit 1
fi
if /usr/bin/which autoconf >/dev/null 2>&1 ; then
:
else
echo "You do not have autoconf installed, which is very sadly required to build part of Ardour"
exit 1
fi
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
echo "Adding libtools."
libtoolize --automake --copy --force
echo "Building macros."
aclocal -I "$srcdir/scripts" $ACLOCAL_FLAGS
echo "Building makefiles."
automake --add-missing --copy
echo "Building configure."
autoconf
rm -f config.cache

View file

@ -1,149 +0,0 @@
# Configure.in
#
# This file tests for various compiler features needed to configure
# the gtkmm package. Original skeleton was provided by Stephan Kulow.
# All tests were written by Tero Pulkkinen, Mirko Streckenbach, and
# Karl Nelson.
#
# NOTE! IF YOU DO CHANGES HERE, CHECK IF YOU NEED TO MODIFY .m4 TOO!!!
#
# Copyright 2001 Free Software Foundation
# Copyright 1999 gtkmm Development Team
# Copyright 1998 Stephan Kulow
#
AC_INIT(glibmmconfig.h.in)
AC_PREREQ(2.50)
#########################################################################
# Version and initialization
#########################################################################
GLIBMM_MAJOR_VERSION=2
GLIBMM_MINOR_VERSION=6
GLIBMM_MICRO_VERSION=1
GLIBMM_VERSION=$GLIBMM_MAJOR_VERSION.$GLIBMM_MINOR_VERSION.$GLIBMM_MICRO_VERSION
GLIBMM_RELEASE=$GLIBMM_MAJOR_VERSION.$GLIBMM_MINOR_VERSION
AC_DEFINE_UNQUOTED(GLIBMM_MAJOR_VERSION, $GLIBMM_MAJOR_VERSION)
AC_DEFINE_UNQUOTED(GLIBMM_MINOR_VERSION, $GLIBMM_MINOR_VERSION)
AC_DEFINE_UNQUOTED(GLIBMM_MICRO_VERSION, $GLIBMM_MICRO_VERSION)
AC_SUBST(GLIBMM_MAJOR_VERSION)
AC_SUBST(GLIBMM_MINOR_VERSION)
AC_SUBST(GLIBMM_MICRO_VERSION)
AC_SUBST(GLIBMM_VERSION)
AC_SUBST(GLIBMM_RELEASE)
#
# +1 : ? : +1 == new interface that does not break old one
# +1 : ? : 0 == new interface that breaks old one
# ? : ? : 0 == no new interfaces, but breaks apps
# ? :+1 : ? == just some internal changes, nothing breaks but might work
# better
# CURRENT : REVISION : AGE
LIBGLIBMM_SO_VERSION=1:13:0
AC_SUBST(LIBGLIBMM_SO_VERSION)
AC_CONFIG_AUX_DIR(scripts)
dnl For automake.
VERSION=$GLIBMM_VERSION
PACKAGE=glibmm
dnl Initialize automake stuff
AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
dnl Specify a configuration file (no autoheader)
AM_CONFIG_HEADER(glibmmconfig.h)
AM_MAINTAINER_MODE
AL_ACLOCAL_INCLUDE(scripts)
#########################################################################
# Configure arguments
#########################################################################
#########################################################################
# Environment Checks
#########################################################################
AC_PROG_CC
AC_PROG_CPP
AC_PROG_MAKE_SET
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_DISABLE_STATIC
AC_PROG_LIBTOOL
AL_PROG_GNU_M4(AC_MSG_ERROR([dnl
SUN m4 does not work for building gtkmm.
Please install GNU m4.]))
AL_PROG_GNU_MAKE(AC_MSG_ERROR([dnl
SUN make does not work for building gtkmm.
Please install GNU make.]))
#########################################################################
# Dependancy checks
#########################################################################
gtkmm_min_glib_version=2.6.0
PKG_CHECK_MODULES(GLIBMM, glib-2.0 >= ${gtkmm_min_glib_version} gobject-2.0 >= ${gtkmm_min_glib_version} gmodule-2.0 >= ${gtkmm_min_glib_version})
AC_SUBST(GLIBMM_CFLAGS)
AC_SUBST(GLIBMM_LIBS)
# gthread isn't a requirement, but we should use its CFLAGS if available.
PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= ${gtkmm_min_glib_version},[],[GTHREAD_CFLAGS=''; GTHREAD_LIBS=''])
AC_SUBST(GTHREAD_CFLAGS)
AC_SUBST(GTHREAD_LIBS)
#########################################################################
# C++ checks
#########################################################################
AC_PROG_CXX
AC_LANG_CPLUSPLUS
AC_CXX_BOOL(,config_error=yes)
AC_CXX_NAMESPACES(,config_error=yes)
AC_CXX_MUTABLE(,config_error=yes)
AC_MSG_CHECKING(if C++ environment provides all required features)
if test "x$config_error" = xyes ; then
AC_MSG_RESULT([no])
AC_MSG_ERROR([Your compiler is not powerful enough to compile gtkmm. If it should be, see config.log for more information of why it failed.])
fi
AC_MSG_RESULT([yes])
GLIBMM_CXX_HAS_NAMESPACE_STD()
GLIBMM_CXX_HAS_STD_ITERATOR_TRAITS()
GLIBMM_CXX_HAS_SUN_REVERSE_ITERATOR()
GLIBMM_CXX_HAS_TEMPLATE_SEQUENCE_CTORS()
GLIBMM_CXX_MEMBER_FUNCTIONS_MEMBER_TEMPLATES()
GLIBMM_CXX_CAN_DISAMBIGUATE_CONST_TEMPLATE_SPECIALIZATIONS()
GLIBMM_CXX_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION()
GLIBMM_CXX_CAN_ASSIGN_NON_EXTERN_C_FUNCTIONS_TO_EXTERN_C_CALLBACKS()
GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC()
GLIBMM_CXX_ALLOWS_STATIC_INLINE_NPOS()
# Check whether --enable-debug-refcounting was given.
GLIBMM_ARG_ENABLE_DEBUG_REFCOUNTING()
# Evaluate the --enable-warnings=level option.
GTKMM_ARG_ENABLE_WARNINGS()
# Dummy conditional just to make automake-1.4 happy.
# We need an always-false condition in docs/Makefile.am.
AM_CONDITIONAL(GTKMM_FALSE,[false])
# HACK: Assign a dummy in order to prevent execution of autoheader by the
# maintainer-mode rules. That would fail since we aren't using autoheader.
AUTOHEADER=':'
AC_CONFIG_FILES([
Makefile
glibmm-2.4.pc
glibmm/Makefile
])
AC_OUTPUT()

View file

@ -1,11 +0,0 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: GLibmm
Description: C++ wrapper for GLib
Requires: gobject-2.0 sigc++-2.0
Version: @VERSION@
Libs: -L${libdir} -lglibmm-2.4
Cflags: -I${includedir}/glibmm-2.4 -I${libdir}/glibmm-2.4/include

View file

@ -1,72 +0,0 @@
/* $Id$ */
/* glibmm - a C++ wrapper for the GLib toolkit
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _GLIBMM_H
#define _GLIBMM_H
#include <glibmmconfig.h>
//#include <glibmm/i18n.h> //This must be included by the application, after system headers such as <iostream>.
#include <glibmm/arrayhandle.h>
#include <glibmm/class.h>
#include <glibmm/containerhandle_shared.h>
#include <glibmm/convert.h>
#include <glibmm/date.h>
#include <glibmm/dispatcher.h>
#include <glibmm/error.h>
#include <glibmm/exception.h>
#include <glibmm/exceptionhandler.h>
#include <glibmm/fileutils.h>
#include <glibmm/helperlist.h>
#include <glibmm/interface.h>
#include <glibmm/iochannel.h>
#include <glibmm/init.h>
#include <glibmm/streamiochannel.h>
#include <glibmm/listhandle.h>
#include <glibmm/main.h>
#include <glibmm/markup.h>
#include <glibmm/miscutils.h>
#include <glibmm/module.h>
#include <glibmm/objectbase.h>
#include <glibmm/object.h>
#include <glibmm/optioncontext.h>
#include <glibmm/pattern.h>
#include <glibmm/property.h>
#include <glibmm/propertyproxy_base.h>
#include <glibmm/propertyproxy.h>
#include <glibmm/quark.h>
#include <glibmm/random.h>
#include <glibmm/refptr.h>
#include <glibmm/shell.h>
#include <glibmm/signalproxy_connectionnode.h>
#include <glibmm/signalproxy.h>
#include <glibmm/slisthandle.h>
#include <glibmm/spawn.h>
#include <glibmm/stringutils.h>
#include <glibmm/thread.h>
#include <glibmm/threadpool.h>
#include <glibmm/timer.h>
#include <glibmm/timeval.h>
#include <glibmm/ustring.h>
#include <glibmm/value.h>
#include <glibmm/wrap.h>
#endif /* _GLIBMM_H */

View file

@ -1,3 +0,0 @@
Makefile
Makefile.in
*.os

View file

@ -1,96 +0,0 @@
## Copyright (c) 2001
## The gtkmm development team.
SUBDIRS =
sublib_name = glibmm
sublib_libname = glibmm-2.4
sublib_namespace = Glib
sublib_cflags = $(GLIBMM_CFLAGS)
sublib_files_extra_posix_cc =
sublib_files_general_cc = \
class.cc \
containers.cc \
debug.cc \
dispatcher.cc \
error.cc \
exception.cc \
exceptionhandler.cc \
init.cc \
interface.cc \
main.cc \
miscutils.cc \
object.cc \
objectbase.cc \
pattern.cc \
property.cc \
propertyproxy.cc \
propertyproxy_base.cc \
quark.cc \
random.cc \
signalproxy.cc \
signalproxy_connectionnode.cc \
streamiochannel.cc \
stringutils.cc \
threadpool.cc \
timer.cc \
timeval.cc \
ustring.cc \
utility.cc \
value.cc \
value_custom.cc \
wrap.cc
sublib_files_posix_h =
sublib_files_general_h = \
arrayhandle.h \
class.h \
containerhandle_shared.h \
containers.h \
debug.h \
dispatcher.h \
error.h \
exception.h \
exceptionhandler.h \
helperlist.h \
init.h \
i18n.h \
interface.h \
iochannel.h \
listhandle.h \
main.h \
miscutils.h \
object.h \
objectbase.h \
pattern.h \
property.h \
propertyproxy.h \
propertyproxy_base.h \
quark.h \
random.h \
refptr.h \
sarray.h \
signalproxy_connectionnode.h \
slisthandle.h \
streamiochannel.h \
stringutils.h \
threadpool.h \
timer.h \
timeval.h \
ustring.h \
utility.h \
value.h \
value_custom.h \
wrap.h
files_built_general_cc = value_basictypes.cc
files_built_general_h = signalproxy.h value_basictypes.h
lib_LTLIBRARIES = libglibmm-2.4.la
libglibmm_2_4_la_SOURCES = $(files_all_general_cc) $(files_all_posix_cc)
libglibmm_2_4_la_LDFLAGS = $(common_ldflags)
libglibmm_2_4_la_LIBADD = $(GLIBMM_LIBS)

View file

@ -1,522 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_ARRAYHANDLE_H
#define _GLIBMM_ARRAYHANDLE_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/containerhandle_shared.h>
namespace Glib
{
namespace Container_Helpers
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* Count the number of elements in a 0-terminated sequence.
*/
template <class T> inline
size_t compute_array_size(const T* array)
{
const T* pend = array;
while(*pend)
++pend;
return (pend - array);
}
/* Allocate and fill a 0-terminated array. The size argument
* specifies the number of elements in the input sequence.
*/
template <class For, class Tr>
typename Tr::CType* create_array(For pbegin, size_t size, Tr)
{
typedef typename Tr::CType CType;
CType *const array = static_cast<CType*>(g_malloc((size + 1) * sizeof(CType)));
CType *const array_end = array + size;
for(CType* pdest = array; pdest != array_end; ++pdest)
{
// Use & to force a warning if the iterator returns a temporary object.
*pdest = Tr::to_c_type(*&*pbegin);
++pbegin;
}
*array_end = CType();
return array;
}
/* Convert from any container that supports forward
* iterators and has a size() method.
*/
template <class Tr, class Cont>
struct ArraySourceTraits
{
typedef typename Tr::CType CType;
static size_t get_size(const Cont& cont)
{ return cont.size(); }
static const CType* get_data(const Cont& cont, size_t size)
{ return Glib::Container_Helpers::create_array(cont.begin(), size, Tr()); }
static const Glib::OwnershipType initial_ownership = Glib::OWNERSHIP_SHALLOW;
};
/* Convert from a 0-terminated array. The Cont argument must be a pointer
* to the first element. Note that only arrays of the C type are supported.
*/
template <class Tr, class Cont>
struct ArraySourceTraits<Tr,Cont*>
{
typedef typename Tr::CType CType;
static size_t get_size(const CType* array)
{ return (array) ? Glib::Container_Helpers::compute_array_size(array) : 0; }
static const CType* get_data(const CType* array, size_t)
{ return array; }
static const Glib::OwnershipType initial_ownership = Glib::OWNERSHIP_NONE;
};
template <class Tr, class Cont>
struct ArraySourceTraits<Tr,const Cont*> : ArraySourceTraits<Tr,Cont*>
{};
/* Convert from a 0-terminated array. The Cont argument must be a pointer
* to the first element. Note that only arrays of the C type are supported.
* For consistency, the array must be 0-terminated, even though the array
* size is known at compile time.
*/
template <class Tr, class Cont, size_t N>
struct ArraySourceTraits<Tr,Cont[N]>
{
typedef typename Tr::CType CType;
static size_t get_size(const CType*)
{ return (N - 1); }
static const CType* get_data(const CType* array, size_t)
{ return array; }
static const Glib::OwnershipType initial_ownership = Glib::OWNERSHIP_NONE;
};
template <class Tr, class Cont, size_t N>
struct ArraySourceTraits<Tr,const Cont[N]> : ArraySourceTraits<Tr,Cont[N]>
{};
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
/**
* @ingroup ContHelpers
*/
template <class Tr>
class ArrayHandleIterator
{
public:
typedef typename Tr::CppType CppType;
typedef typename Tr::CType CType;
typedef std::random_access_iterator_tag iterator_category;
typedef CppType value_type;
typedef ptrdiff_t difference_type;
typedef value_type reference;
typedef void pointer;
explicit inline ArrayHandleIterator(const CType* pos);
inline value_type operator*() const;
inline value_type operator[](difference_type offset) const;
inline ArrayHandleIterator<Tr> & operator++();
inline const ArrayHandleIterator<Tr> operator++(int);
// All this random access stuff is only there because STL algorithms
// usually have optimized specializations for random access iterators,
// and we don't want to give away efficiency for nothing.
//
inline ArrayHandleIterator<Tr> & operator+=(difference_type rhs);
inline ArrayHandleIterator<Tr> & operator-=(difference_type rhs);
inline const ArrayHandleIterator<Tr> operator+ (difference_type rhs) const;
inline const ArrayHandleIterator<Tr> operator- (difference_type rhs) const;
inline difference_type operator-(const ArrayHandleIterator<Tr>& rhs) const;
inline bool operator==(const ArrayHandleIterator<Tr>& rhs) const;
inline bool operator!=(const ArrayHandleIterator<Tr>& rhs) const;
inline bool operator< (const ArrayHandleIterator<Tr>& rhs) const;
inline bool operator> (const ArrayHandleIterator<Tr>& rhs) const;
inline bool operator<=(const ArrayHandleIterator<Tr>& rhs) const;
inline bool operator>=(const ArrayHandleIterator<Tr>& rhs) const;
private:
const CType* pos_;
};
} // namespace Container_Helpers
/** If a method takes this as an argument, or has this as a return type, then you can use a standard
* container such as std::list or std::vector.
* @ingroup ContHandles
*/
template < class T, class Tr = Glib::Container_Helpers::TypeTraits<T> >
class ArrayHandle
{
public:
typedef typename Tr::CppType CppType;
typedef typename Tr::CType CType;
typedef CppType value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef Glib::Container_Helpers::ArrayHandleIterator<Tr> const_iterator;
typedef Glib::Container_Helpers::ArrayHandleIterator<Tr> iterator;
template <class Cont> inline
ArrayHandle(const Cont& container);
// Take over ownership of an array created by GTK+ functions.
inline ArrayHandle(const CType* array, size_t array_size, Glib::OwnershipType ownership);
inline ArrayHandle(const CType* array, Glib::OwnershipType ownership);
// Copying clears the ownership flag of the source handle.
inline ArrayHandle(const ArrayHandle<T,Tr>& other);
~ArrayHandle();
inline const_iterator begin() const;
inline const_iterator end() const;
template <class U> inline operator std::vector<U>() const;
template <class U> inline operator std::deque<U>() const;
template <class U> inline operator std::list<U>() const;
template <class Cont> inline
void assign_to(Cont& container) const;
template <class Out> inline
void copy(Out pdest) const;
inline const CType* data() const;
inline size_t size() const;
inline bool empty() const;
private:
size_t size_;
const CType* parray_;
mutable Glib::OwnershipType ownership_;
// No copy assignment.
ArrayHandle<T, Tr>& operator=(const ArrayHandle<T,Tr>&);
};
/** If a method takes this as an argument, or has this as a return type, then you can use a standard
* container such as std::list<Glib::ustring> or std::vector<Glib::ustring>.
* @ingroup ContHandles
*/
typedef ArrayHandle<Glib::ustring> StringArrayHandle;
/***************************************************************************/
/* Inline implementation */
/***************************************************************************/
#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Container_Helpers
{
/**** Glib::Container_Helpers::ArrayHandleIterator<> ***********************/
template <class Tr> inline
ArrayHandleIterator<Tr>::ArrayHandleIterator(const CType* pos)
:
pos_ (pos)
{}
template <class Tr> inline
typename ArrayHandleIterator<Tr>::value_type ArrayHandleIterator<Tr>::operator*() const
{
return Tr::to_cpp_type(*pos_);
}
template <class Tr> inline
typename ArrayHandleIterator<Tr>::value_type
ArrayHandleIterator<Tr>::operator[](difference_type offset) const
{
return Tr::to_cpp_type(pos_[offset]);
}
template <class Tr> inline
ArrayHandleIterator<Tr>& ArrayHandleIterator<Tr>::operator++()
{
++pos_;
return *this;
}
template <class Tr> inline
const ArrayHandleIterator<Tr> ArrayHandleIterator<Tr>::operator++(int)
{
return ArrayHandleIterator<Tr>(pos_++);
}
template <class Tr> inline
ArrayHandleIterator<Tr>&
ArrayHandleIterator<Tr>::operator+=(typename ArrayHandleIterator<Tr>::difference_type rhs)
{
pos_ += rhs;
return *this;
}
template <class Tr> inline
ArrayHandleIterator<Tr>&
ArrayHandleIterator<Tr>::operator-=(typename ArrayHandleIterator<Tr>::difference_type rhs)
{
pos_ -= rhs;
return *this;
}
template <class Tr> inline
const ArrayHandleIterator<Tr>
ArrayHandleIterator<Tr>::operator+(typename ArrayHandleIterator<Tr>::difference_type rhs) const
{
return ArrayHandleIterator<Tr>(pos_ + rhs);
}
template <class Tr> inline
const ArrayHandleIterator<Tr>
ArrayHandleIterator<Tr>::operator-(typename ArrayHandleIterator<Tr>::difference_type rhs) const
{
return ArrayHandleIterator<Tr>(pos_ - rhs);
}
template <class Tr> inline
typename ArrayHandleIterator<Tr>::difference_type
ArrayHandleIterator<Tr>::operator-(const ArrayHandleIterator<Tr>& rhs) const
{
return (pos_ - rhs.pos_);
}
template <class Tr> inline
bool ArrayHandleIterator<Tr>::operator==(const ArrayHandleIterator<Tr>& rhs) const
{
return (pos_ == rhs.pos_);
}
template <class Tr> inline
bool ArrayHandleIterator<Tr>::operator!=(const ArrayHandleIterator<Tr>& rhs) const
{
return (pos_ != rhs.pos_);
}
template <class Tr> inline
bool ArrayHandleIterator<Tr>::operator<(const ArrayHandleIterator<Tr>& rhs) const
{
return (pos_ < rhs.pos_);
}
template <class Tr> inline
bool ArrayHandleIterator<Tr>::operator>(const ArrayHandleIterator<Tr>& rhs) const
{
return (pos_ > rhs.pos_);
}
template <class Tr> inline
bool ArrayHandleIterator<Tr>::operator<=(const ArrayHandleIterator<Tr>& rhs) const
{
return (pos_ <= rhs.pos_);
}
template <class Tr> inline
bool ArrayHandleIterator<Tr>::operator>=(const ArrayHandleIterator<Tr>& rhs) const
{
return (pos_ >= rhs.pos_);
}
} // namespace Container_Helpers
/**** Glib::ArrayHandle<> **************************************************/
template <class T, class Tr>
template <class Cont>
inline
ArrayHandle<T,Tr>::ArrayHandle(const Cont& container)
:
size_ (Glib::Container_Helpers::ArraySourceTraits<Tr,Cont>::get_size(container)),
parray_ (Glib::Container_Helpers::ArraySourceTraits<Tr,Cont>::get_data(container, size_)),
ownership_ (Glib::Container_Helpers::ArraySourceTraits<Tr,Cont>::initial_ownership)
{}
template <class T, class Tr> inline
ArrayHandle<T,Tr>::ArrayHandle(const typename ArrayHandle<T,Tr>::CType* array, size_t array_size,
Glib::OwnershipType ownership)
:
size_ (array_size),
parray_ (array),
ownership_ (ownership)
{}
template <class T, class Tr> inline
ArrayHandle<T,Tr>::ArrayHandle(const typename ArrayHandle<T,Tr>::CType* array,
Glib::OwnershipType ownership)
:
size_ ((array) ? Glib::Container_Helpers::compute_array_size(array) : 0),
parray_ (array),
ownership_ (ownership)
{}
template <class T, class Tr> inline
ArrayHandle<T,Tr>::ArrayHandle(const ArrayHandle<T,Tr>& other)
:
size_ (other.size_),
parray_ (other.parray_),
ownership_ (other.ownership_)
{
other.ownership_ = Glib::OWNERSHIP_NONE;
}
template <class T, class Tr>
ArrayHandle<T,Tr>::~ArrayHandle()
{
if(ownership_ != Glib::OWNERSHIP_NONE)
{
if(ownership_ != Glib::OWNERSHIP_SHALLOW)
{
// Deep ownership: release each container element.
const CType *const pend = parray_ + size_;
for(const CType* p = parray_; p != pend; ++p)
Tr::release_c_type(*p);
}
g_free(const_cast<CType*>(parray_));
}
}
template <class T, class Tr> inline
typename ArrayHandle<T,Tr>::const_iterator ArrayHandle<T,Tr>::begin() const
{
return Glib::Container_Helpers::ArrayHandleIterator<Tr>(parray_);
}
template <class T, class Tr> inline
typename ArrayHandle<T,Tr>::const_iterator ArrayHandle<T,Tr>::end() const
{
return Glib::Container_Helpers::ArrayHandleIterator<Tr>(parray_ + size_);
}
template <class T, class Tr>
template <class U>
inline
ArrayHandle<T,Tr>::operator std::vector<U>() const
{
#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
return std::vector<U>(this->begin(), this->end());
#else
std::vector<U> temp;
temp.reserve(this->size());
Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
return temp;
#endif
}
template <class T, class Tr>
template <class U>
inline
ArrayHandle<T,Tr>::operator std::deque<U>() const
{
#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
return std::deque<U>(this->begin(), this->end());
#else
std::deque<U> temp;
Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
return temp;
#endif
}
template <class T, class Tr>
template <class U>
inline
ArrayHandle<T,Tr>::operator std::list<U>() const
{
#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
return std::list<U>(this->begin(), this->end());
#else
std::list<U> temp;
Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
return temp;
#endif
}
template <class T, class Tr>
template <class Cont>
inline
void ArrayHandle<T,Tr>::assign_to(Cont& container) const
{
#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
container.assign(this->begin(), this->end());
#else
Cont temp;
Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
container.swap(temp);
#endif
}
template <class T, class Tr>
template <class Out>
inline
void ArrayHandle<T,Tr>::copy(Out pdest) const
{
std::copy(this->begin(), this->end(), pdest);
}
template <class T, class Tr> inline
const typename ArrayHandle<T,Tr>::CType* ArrayHandle<T,Tr>::data() const
{
return parray_;
}
template <class T, class Tr> inline
size_t ArrayHandle<T,Tr>::size() const
{
return size_;
}
template <class T, class Tr> inline
bool ArrayHandle<T,Tr>::empty() const
{
return (size_ == 0);
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
} // namespace Glib
#endif /* _GLIBMM_ARRAYHANDLE_H */

View file

@ -1,116 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 1998-2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/class.h>
#include <glibmm/property.h>
#include <glibmm/ustring.h>
#include <glibmm/utility.h>
namespace Glib
{
void Class::register_derived_type(GType base_type)
{
if(gtype_)
return; // already initialized
GTypeQuery base_query = { 0, 0, 0, 0, };
g_type_query(base_type, &base_query);
const GTypeInfo derived_info =
{
base_query.class_size,
0, // base_init
0, // base_finalize
class_init_func_,
0, // class_finalize
0, // class_data
base_query.instance_size,
0, // n_preallocs
0, // instance_init
0, // value_table
};
Glib::ustring derived_name = "gtkmm__";
derived_name += base_query.type_name;
gtype_ = g_type_register_static(base_type, derived_name.c_str(), &derived_info, GTypeFlags(0));
}
GType Class::clone_custom_type(const char* custom_type_name) const
{
std::string full_name ("gtkmm__CustomObject_");
Glib::append_canonical_typename(full_name, custom_type_name);
GType custom_type = g_type_from_name(full_name.c_str());
if(!custom_type)
{
g_return_val_if_fail(gtype_ != 0, 0);
// Cloned custom types derive from the wrapper's parent type,
// so that g_type_class_peek_parent() works correctly.
const GType base_type = g_type_parent(gtype_);
GTypeQuery base_query = { 0, 0, 0, 0, };
g_type_query(base_type, &base_query);
const GTypeInfo derived_info =
{
base_query.class_size,
0, // base_init
0, // base_finalize
&Class::custom_class_init_function,
0, // class_finalize
this, // class_data
base_query.instance_size,
0, // n_preallocs
0, // instance_init
0, // value_table
};
custom_type = g_type_register_static(
base_type, full_name.c_str(), &derived_info, GTypeFlags(0));
}
return custom_type;
}
// static
void Class::custom_class_init_function(void* g_class, void* class_data)
{
// The class_data pointer is set to 'this' by clone_custom_type().
const Class *const self = static_cast<Class*>(class_data);
g_return_if_fail(self->class_init_func_ != 0);
// Call the wrapper's class_init_function() to redirect
// the vfunc and default signal handler callbacks.
(*self->class_init_func_)(g_class, 0);
GObjectClass *const gobject_class = static_cast<GObjectClass*>(g_class);
gobject_class->get_property = &Glib::custom_get_property_callback;
gobject_class->set_property = &Glib::custom_set_property_callback;
}
} // namespace Glib

View file

@ -1,76 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_CLASS_H
#define _GLIBMM_CLASS_H
/* $Id$ */
/* Copyright 2001 Free Software Foundation
* Copyright (C) 1998-2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib-object.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Glib
{
class Class
{
public:
/* No constructor/destructor:
* Glib::Class objects are used only as static data, which would cause
* lots of ugly global constructor invocations. These are avoidable,
* because the C/C++ standard explicitly specifies that all _static_ data
* is zero-initialized at program start.
*/
//Class();
//~Class();
//static void class_init_function(BaseClassType *p);
//static void object_init_function(BaseObjectType *o);
//GType get_type() = 0; //Creates the GType when this is first called.
// Hook for translating API
//static Glib::Object* wrap_new(GObject*);
inline GType get_type() const;
GType clone_custom_type(const char* custom_type_name) const;
protected:
GType gtype_;
GClassInitFunc class_init_func_;
void register_derived_type(GType base_type);
private:
static void custom_class_init_function(void* g_class, void* class_data);
};
inline
GType Class::get_type() const
{
return gtype_;
}
} // namespace Glib
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
#endif /* _GLIBMM_CLASS_H */

View file

@ -1,343 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_CONTAINERHANDLE_SHARED_H
#define _GLIBMM_CONTAINERHANDLE_SHARED_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <cstddef>
#include <algorithm>
#include <iterator>
#include <vector>
#include <deque>
#include <list>
#include <glib-object.h>
#include <glib/gmem.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <glibmm/wrap.h>
#include <glibmm/debug.h>
#include <glibmmconfig.h>
GLIBMM_USING_STD(forward_iterator_tag)
GLIBMM_USING_STD(random_access_iterator_tag)
GLIBMM_USING_STD(distance)
GLIBMM_USING_STD(copy)
GLIBMM_USING_STD(vector)
GLIBMM_USING_STD(deque)
GLIBMM_USING_STD(list)
namespace Glib
{
/** @defgroup ContHandles Generic container converters
*/
/**
* @ingroup ContHandles
*/
enum OwnershipType
{
OWNERSHIP_NONE = 0,
OWNERSHIP_SHALLOW, //Release the list, but not its elements, when the container is deleted
OWNERSHIP_DEEP //Release the list, and its elements, when the container is deleted.
};
/** Utility class holding an iterator sequence.
* @ingroup ContHandles
* This can be used to initialize a Glib container handle (such as
* Glib::ArrayHandle) with an iterator sequence. Use the helper
* function Glib::sequence() to create a Sequence<> object.
*/
template <class Iterator>
class Sequence
{
private:
Iterator pbegin_;
Iterator pend_;
public:
Sequence(Iterator pbegin, Iterator pend)
: pbegin_(pbegin), pend_(pend) {}
Iterator begin() const { return pbegin_; }
Iterator end() const { return pend_; }
size_t size() const { return std::distance(pbegin_, pend_); }
};
/** Helper function to create a Glib::Sequence<> object, which
* in turn can be used to initialize a container handle.
* @ingroup ContHandles
*
* @par Usage example:
* @code
* combo.set_popdown_strings(Glib::sequence(foo_begin, foo_end));
* @endcode
*/
template <class Iterator> inline
Sequence<Iterator> sequence(Iterator pbegin, Iterator pend)
{
return Sequence<Iterator>(pbegin, pend);
}
namespace Container_Helpers
{
/** @defgroup ContHelpers Helper classes
* @ingroup ContHandles
*/
/** Generic TypeTraits implementation.
* @ingroup ContHelpers
* This can be used if the C++ type is the same as the C type, or if implicit
* conversions between the types are available. Also, the types are required
* to implement copy-by-value semantics. (Ownership is just ignored.)
*/
template <class T>
struct TypeTraits
{
typedef T CppType;
typedef T CType;
typedef T CTypeNonConst;
static CType to_c_type (const CppType& item) { return item; }
static CppType to_cpp_type (const CType& item) { return item; }
static void release_c_type (const CType&) {}
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS /* hide the specializations */
//For some (proably, more spec-compliant) compilers, these specializations must
//be next to the objects that they use.
#ifdef GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION
/** Partial specialization for pointers to GtkObject instances.
* @ingroup ContHelpers
*/
template <class T>
struct TypeTraits<T*>
{
typedef T * CppType;
typedef typename T::BaseObjectType * CType;
typedef typename T::BaseObjectType * CTypeNonConst;
static CType to_c_type (CppType ptr) { return Glib::unwrap(ptr); }
static CType to_c_type (CType ptr) { return ptr; }
static CppType to_cpp_type (CType ptr)
{
//We copy/paste the widget wrap() implementation here,
//because we can not use a specific Glib::wrap(T_Impl) overload here,
//because that would be "dependent", and g++ 3.4 does not allow that.
//The specific Glib::wrap() overloads don't do anything special anyway.
GObject* cobj = (GObject*)ptr;
return dynamic_cast<CppType>(Glib::wrap_auto(cobj, false /* take_copy */));
}
static void release_c_type (CType ptr)
{
GLIBMM_DEBUG_UNREFERENCE(0, ptr);
g_object_unref(ptr);
}
};
//This confuse the SUN Forte compiler, so we ifdef it out:
#ifdef GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS
/** Partial specialization for pointers to const GtkObject instances.
* @ingroup ContHelpers
*/
template <class T>
struct TypeTraits<const T*>
{
typedef const T * CppType;
typedef const typename T::BaseObjectType * CType;
typedef typename T::BaseObjectType * CTypeNonConst;
static CType to_c_type (CppType ptr) { return Glib::unwrap(ptr); }
static CType to_c_type (CType ptr) { return ptr; }
static CppType to_cpp_type (CType ptr)
{
//We copy/paste the widget wrap() implementation here,
//because we can not use a specific Glib::wrap(T_Impl) overload here,
//because that would be "dependent", and g++ 3.4 does not allow that.
//The specific Glib::wrap() overloads don't do anything special anyway.
GObject* cobj = (GObject*)const_cast<CTypeNonConst>(ptr);
return dynamic_cast<CppType>(Glib::wrap_auto(cobj, false /* take_copy */));
}
static void release_c_type (CType ptr)
{
GLIBMM_DEBUG_UNREFERENCE(0, ptr);
g_object_unref(const_cast<CTypeNonConst>(ptr));
}
};
#endif //GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS
/** Partial specialization for pointers to GObject instances.
* @ingroup ContHelpers
* The C++ type is always a Glib::RefPtr<>.
*/
template <class T>
struct TypeTraits< Glib::RefPtr<T> >
{
typedef Glib::RefPtr<T> CppType;
typedef typename T::BaseObjectType * CType;
typedef typename T::BaseObjectType * CTypeNonConst;
static CType to_c_type (const CppType& ptr) { return Glib::unwrap(ptr); }
static CType to_c_type (CType ptr) { return ptr; }
static CppType to_cpp_type (CType ptr)
{
//return Glib::wrap(ptr, true);
//We copy/paste the wrap() implementation here,
//because we can not use a specific Glib::wrap(CType) overload here,
//because that would be "dependent", and g++ 3.4 does not allow that.
//The specific Glib::wrap() overloads don't do anything special anyway.
GObject* cobj = (GObject*)const_cast<CTypeNonConst>(ptr);
return Glib::RefPtr<T>( dynamic_cast<T*>(Glib::wrap_auto(cobj, true /* take_copy */)) );
//We use dynamic_cast<> in case of multiple inheritance.
}
static void release_c_type (CType ptr)
{
GLIBMM_DEBUG_UNREFERENCE(0, ptr);
g_object_unref(ptr);
}
};
//This confuse the SUN Forte compiler, so we ifdef it out:
#ifdef GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS
/** Partial specialization for pointers to const GObject instances.
* @ingroup ContHelpers
* The C++ type is always a Glib::RefPtr<>.
*/
template <class T>
struct TypeTraits< Glib::RefPtr<const T> >
{
typedef Glib::RefPtr<const T> CppType;
typedef const typename T::BaseObjectType * CType;
typedef typename T::BaseObjectType * CTypeNonConst;
static CType to_c_type (const CppType& ptr) { return Glib::unwrap(ptr); }
static CType to_c_type (CType ptr) { return ptr; }
static CppType to_cpp_type (CType ptr)
{
//return Glib::wrap(ptr, true);
//We copy/paste the wrap() implementation here,
//because we can not use a specific Glib::wrap(CType) overload here,
//because that would be "dependent", and g++ 3.4 does not allow that.
//The specific Glib::wrap() overloads don't do anything special anyway.
GObject* cobj = (GObject*)(ptr);
return Glib::RefPtr<const T>( dynamic_cast<const T*>(Glib::wrap_auto(cobj, true /* take_copy */)) );
//We use dynamic_cast<> in case of multiple inheritance.
}
static void release_c_type (CType ptr)
{
GLIBMM_DEBUG_UNREFERENCE(0, ptr);
g_object_unref(const_cast<CTypeNonConst>(ptr));
}
};
#endif //GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS
#endif //GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION
/** Specialization for UTF-8 strings.
* @ingroup ContHelpers
* When converting from C++ to C, Glib::ustring will be accepted as well as
* std::string and 'const char*'. However, when converting to the C++ side,
* the output type cannot be 'const char*'.
*/
template <>
struct TypeTraits<Glib::ustring>
{
typedef Glib::ustring CppType;
typedef const char * CType;
typedef char * CTypeNonConst;
static CType to_c_type (const Glib::ustring& str) { return str.c_str(); }
static CType to_c_type (const std::string& str) { return str.c_str(); }
static CType to_c_type (CType str) { return str; }
static CppType to_cpp_type(CType str)
{ return (str) ? Glib::ustring(str) : Glib::ustring(); }
static void release_c_type(CType str)
{ g_free(const_cast<CTypeNonConst>(str)); }
};
/** Specialization for std::string.
* @ingroup ContHelpers
* When converting from C++ to C, std::string will be accepted as well as
* 'const char*'. However, when converting to the C++ side, the output type
* cannot be 'const char*'.
*/
template <>
struct TypeTraits<std::string>
{
typedef std::string CppType;
typedef const char * CType;
typedef char * CTypeNonConst;
static CType to_c_type (const std::string& str) { return str.c_str(); }
static CType to_c_type (const Glib::ustring& str) { return str.c_str(); }
static CType to_c_type (CType str) { return str; }
static CppType to_cpp_type(CType str)
{ return (str) ? std::string(str) : std::string(); }
static void release_c_type(CType str)
{ g_free(const_cast<CTypeNonConst>(str)); }
};
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifndef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
/* The STL containers in Sun's libCstd don't support templated sequence
* constructors, for "backward compatibility" reasons. This helper function
* is used in the ContainerHandle -> STL-container conversion workarounds.
*/
template <class Cont, class In>
void fill_container(Cont& container, In pbegin, In pend)
{
for(; pbegin != pend; ++pbegin)
container.push_back(*pbegin);
}
#endif /* GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS */
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
} // namespace Container_Helpers
} // namespace Glib
#endif /* _GLIBMM_CONTAINERHANDLE_SHARED_H */

View file

@ -1,33 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* containers.h
*
* Copyright (C) 1998-2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/containers.h>
namespace Glib
{
gpointer glibmm_null_pointer=0;
} //namespace Glib

View file

@ -1,372 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_CONTAINERS_H
#define _GLIBMM_CONTAINERS_H
/* $Id$ */
/* containers.h
*
* Copyright (C) 1998-2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/glist.h>
#include <glib/gslist.h>
#include <glibmm/sarray.h> /* for backward compatibility */
#include <iterator>
#include <glibmmconfig.h>
GLIBMM_USING_STD(bidirectional_iterator_tag)
GLIBMM_USING_STD(forward_iterator_tag)
#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Glib
{
template <class T> class List_Iterator;
template <class T> class List_ConstIterator;
template <class T> class List_ReverseIterator;
// Most of these methods in the non-template classes needs to be moved
// to implementation.
//Daniel Elstner has ideas about generating these per-widget with m4. murrayc.
extern GLIBMM_API gpointer glibmm_null_pointer;
template <class T>
class List_Iterator_Base
{
public:
typedef T value_type;
typedef T* pointer;
typedef T& reference;
} ;
///For instance, List_Iterator< Gtk::Widget >
template <class T>
class List_Iterator : public List_Iterator_Base<T>
{
public:
typedef std::bidirectional_iterator_tag iterator_category;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef typename List_Iterator_Base<T>::pointer pointer;
typedef typename List_Iterator_Base<T>::reference reference;
GList* const* head_;
GList* node_;
typedef List_Iterator<T> Self;
List_Iterator(GList* const& head, GList* node)
: head_(&head), node_(node)
{}
List_Iterator()
: head_(0), node_(0)
{}
List_Iterator(const Self& src)
: head_(src.head_), node_(src.node_)
{}
bool operator==(const Self& src) const { return node_ == src.node_; }
bool operator!=(const Self& src) const { return node_ != src.node_; }
Self& operator++()
{
if (!node_)
node_ = g_list_first(*head_);
else
node_ = (GList*)g_list_next(node_);
return *this;
}
Self operator++(int)
{
Self tmp = *this;
++*this;
return tmp;
}
Self& operator--()
{
if (!node_)
node_ = g_list_last(*head_);
else
node_ = (GList*)g_list_previous(node_);
return *this;
}
Self operator--(int)
{
Self tmp = *this;
--*this;
return tmp;
}
reference operator*() const
{
return *(pointer)( node_ ? node_->data : glibmm_null_pointer );
}
pointer operator -> () const { return &operator*(); }
};
///For instance, SList_Iterator< Gtk::Widget >
template <class T>
class SList_Iterator : public List_Iterator_Base<T>
{
public:
typedef std::forward_iterator_tag iterator_category;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef typename List_Iterator_Base<T>::pointer pointer;
typedef typename List_Iterator_Base<T>::reference reference;
GSList* node_;
typedef SList_Iterator<T> Self;
SList_Iterator(GSList* node)
: node_(node)
{}
SList_Iterator()
: node_(0)
{}
SList_Iterator(const Self& src)
: node_(src.node_)
{}
bool operator==(const Self& src) const { return node_ == src.node_; }
bool operator!=(const Self& src) const { return node_ != src.node_; }
Self& operator++()
{
node_ = g_slist_next(node_);
return *this;
}
Self operator++(int)
{
Self tmp = *this;
++*this;
return tmp;
}
reference operator*() const
{
g_assert(node_);
return reinterpret_cast<T&>( node_ ? node_->data : glibmm_null_pointer );
}
pointer operator -> () const { return &operator*(); }
};
// This iterator variation returns T_IFace (wrapped from T_Impl)
// For instance, List_Cpp_Iterator<GtkWidget, Gtk::Widget> is a little like std::list<Gtk::Widget>::iterator
template<class T_Impl, class T_IFace>
class List_Cpp_Iterator : public List_Iterator_Base<T_IFace>
{
public:
typedef std::bidirectional_iterator_tag iterator_category;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef typename List_Iterator_Base<T_IFace>::pointer pointer;
typedef typename List_Iterator_Base<T_IFace>::reference reference;
typedef List_Cpp_Iterator<T_Impl, T_IFace> Self;
GList** head_;
GList* node_;
bool operator==(const Self& src) const { return node_ == src.node_; }
bool operator!=(const Self& src) const { return node_ != src.node_; }
List_Cpp_Iterator(GList*& head, GList* node )
: head_(&head), node_(node )
{}
List_Cpp_Iterator()
: head_(0), node_(0)
{}
List_Cpp_Iterator(const Self& src)
: head_(src.head_), node_(src.node_)
{}
reference operator*() const
{
if (node_ && node_->data)
{
//We copy/paste the widget wrap() implementation here,
//because we can not use a specific Glib::wrap(T_Impl) overload here,
//because that would be "dependent", and g++ 3.4 does not allow that.
//The specific Glib::wrap() overloads don't do anything special anyway.
GObject* cobj = static_cast<GObject*>( (*node_).data );
#ifdef GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION
return *(dynamic_cast<pointer>(Glib::wrap_auto(cobj, false /* take_copy */)));
#else
//We really do need to use dynamic_cast<>, so I expect problems if this code is used. murrayc.
return *(static_cast<pointer>(Glib::wrap_auto(cobj, false /* take_copy */)));
#endif
}
return *(pointer)glibmm_null_pointer;
}
pointer operator->() const { return &operator*(); }
Self& operator++()
{
if (!node_)
node_ = g_list_first(*head_);
else
node_ = (GList *)g_list_next(node_);
return *this;
}
Self operator++(int)
{
Self tmp = *this;
++*this;
return tmp;
}
Self& operator--()
{
if (!node_)
node_ = g_list_last(*head_);
else
node_ = (GList *)g_list_previous(node_);
return *this;
}
Self operator--(int)
{
Self tmp = *this;
--*this;
return tmp;
}
};
template <class T_Base>
class List_ReverseIterator: private T_Base
{
public:
typedef typename T_Base::iterator_category iterator_category;
typedef typename T_Base::size_type size_type;
typedef typename T_Base::difference_type difference_type;
typedef typename T_Base::value_type value_type;
typedef typename T_Base::pointer pointer;
typedef typename T_Base::reference reference;
typedef List_ReverseIterator<T_Base> Self;
bool operator==(const Self& src) const { return T_Base::operator==(src); }
bool operator!=(const Self& src) const { return T_Base::operator!=(src); }
List_ReverseIterator(GList* const& head, GList* node)
: T_Base(head, node)
{}
List_ReverseIterator()
: T_Base()
{}
List_ReverseIterator(const Self& src)
: T_Base(src)
{}
List_ReverseIterator(const T_Base& src)
: T_Base(src)
{ ++(*this); }
Self& operator++() {T_Base::operator--(); return *this;}
Self& operator--() {T_Base::operator++(); return *this;}
Self operator++(int) {Self src = *this; T_Base::operator--(); return src;}
Self operator--(int) {Self src = *this; T_Base::operator++(); return src;}
reference operator*() const { return T_Base::operator*(); }
pointer operator->() const { return T_Base::operator->(); }
};
template <class T_Base>
class List_ConstIterator: public T_Base
{
public:
typedef typename T_Base::iterator_category iterator_category;
typedef typename T_Base::size_type size_type;
typedef typename T_Base::difference_type difference_type;
typedef const typename T_Base::value_type value_type;
typedef const typename T_Base::pointer pointer;
typedef const typename T_Base::reference reference;
typedef List_ConstIterator<T_Base> Self;
bool operator==(const Self& src) const { return T_Base::operator==(src); }
bool operator!=(const Self& src) const { return T_Base::operator!=(src); }
List_ConstIterator(GList* const& head, GList* node)
: T_Base(head, node)
{}
List_ConstIterator()
: T_Base()
{}
List_ConstIterator(const Self& src)
: T_Base(src)
{}
List_ConstIterator(const T_Base& src)
: T_Base(src)
{}
Self& operator++() {T_Base::operator++(); return *this;}
Self& operator--() {T_Base::operator--(); return *this;}
Self operator++(int) {Self src = *this; T_Base::operator++(); return src;}
Self operator--(int) {Self src = *this; T_Base::operator--(); return src;}
reference operator*() const { return T_Base::operator*(); }
pointer operator->() const { return T_Base::operator->(); }
};
} // namespace Glib
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
#endif /* _GLIBMM_CONTAINERS_H */

View file

@ -1,323 +0,0 @@
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <glibmm/convert.h>
#include <glibmm/private/convert_p.h>
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gconvert.h>
#include <glib/gmessages.h>
#include <glib/gunicode.h>
#include <glibmm/utility.h>
namespace Glib
{
/**** Glib::IConv **********************************************************/
IConv::IConv(const std::string& to_codeset, const std::string& from_codeset)
:
gobject_ (g_iconv_open(to_codeset.c_str(), from_codeset.c_str()))
{
if(gobject_ == reinterpret_cast<GIConv>(-1))
{
GError* error = 0;
// Abuse g_convert() to create a GError object. This may seem a weird
// thing to do, but it gives us consistently translated error messages
// at no further cost.
g_convert("", 0, to_codeset.c_str(), from_codeset.c_str(), 0, 0, &error);
// If this should ever fail we're fucked.
g_assert(error != 0);
Error::throw_exception(error);
}
}
IConv::IConv(GIConv gobject)
:
gobject_ (gobject)
{}
IConv::~IConv()
{
g_iconv_close(gobject_);
}
size_t IConv::iconv(char** inbuf, gsize* inbytes_left, char** outbuf, gsize* outbytes_left)
{
return g_iconv(gobject_, inbuf, inbytes_left, outbuf, outbytes_left);
}
void IConv::reset()
{
// Apparently iconv() on Solaris <= 7 segfaults if you pass in
// NULL for anything but inbuf; work around that. (NULL outbuf
// or NULL *outbuf is allowed by Unix98.)
char* outbuf = 0;
gsize inbytes_left = 0;
gsize outbytes_left = 0;
g_iconv(gobject_, 0, &inbytes_left, &outbuf, &outbytes_left);
}
std::string IConv::convert(const std::string& str)
{
gsize bytes_written = 0;
GError* error = 0;
char *const buf = g_convert_with_iconv(
str.data(), str.size(), gobject_, 0, &bytes_written, &error);
if(error)
Error::throw_exception(error);
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
/**** charset conversion functions *****************************************/
bool get_charset()
{
return g_get_charset(0);
}
bool get_charset(std::string& charset)
{
const char* charset_cstr = 0;
const bool is_utf8 = g_get_charset(&charset_cstr);
charset = charset_cstr;
return is_utf8;
}
std::string convert(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset)
{
gsize bytes_written = 0;
GError* error = 0;
char *const buf = g_convert(
str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(),
0, &bytes_written, &error);
if(error)
Error::throw_exception(error);
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset)
{
gsize bytes_written = 0;
GError* error = 0;
char *const buf = g_convert_with_fallback(
str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(), 0,
0, &bytes_written, &error);
if(error)
Error::throw_exception(error);
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset,
const Glib::ustring& fallback)
{
gsize bytes_written = 0;
GError* error = 0;
char *const buf = g_convert_with_fallback(
str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(),
const_cast<char*>(fallback.c_str()), 0, &bytes_written, &error);
if(error)
Error::throw_exception(error);
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
Glib::ustring locale_to_utf8(const std::string& opsys_string)
{
gsize bytes_written = 0;
GError* error = 0;
char *const buf = g_locale_to_utf8(
opsys_string.data(), opsys_string.size(), 0, &bytes_written, &error);
if(error)
Error::throw_exception(error);
const ScopedPtr<char> scoped_buf (buf);
return Glib::ustring(scoped_buf.get(), scoped_buf.get() + bytes_written);
}
std::string locale_from_utf8(const Glib::ustring& utf8_string)
{
gsize bytes_written = 0;
GError* error = 0;
char *const buf = g_locale_from_utf8(
utf8_string.data(), utf8_string.bytes(), 0, &bytes_written, &error);
if(error)
Error::throw_exception(error);
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
Glib::ustring filename_to_utf8(const std::string& opsys_string)
{
gsize bytes_written = 0;
GError* error = 0;
char *const buf = g_filename_to_utf8(
opsys_string.data(), opsys_string.size(), 0, &bytes_written, &error);
if(error)
Error::throw_exception(error);
const ScopedPtr<char> scoped_buf (buf);
return Glib::ustring(scoped_buf.get(), scoped_buf.get() + bytes_written);
}
std::string filename_from_utf8(const Glib::ustring& utf8_string)
{
gsize bytes_written = 0;
GError* error = 0;
char *const buf = g_filename_from_utf8(
utf8_string.data(), utf8_string.bytes(), 0, &bytes_written, &error);
if(error)
Error::throw_exception(error);
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname)
{
char* hostname_buf = 0;
GError* error = 0;
char *const buf = g_filename_from_uri(uri.c_str(), &hostname_buf, &error);
if(error)
Error::throw_exception(error);
// Let's take ownership at this point.
const ScopedPtr<char> scoped_buf (buf);
if(hostname_buf)
hostname = ScopedPtr<char>(hostname_buf).get();
else
hostname.erase();
return std::string(scoped_buf.get());
}
std::string filename_from_uri(const Glib::ustring& uri)
{
GError* error = 0;
char *const buf = g_filename_from_uri(uri.c_str(), 0, &error);
if(error)
Error::throw_exception(error);
return std::string(ScopedPtr<char>(buf).get());
}
Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname)
{
GError* error = 0;
char *const buf = g_filename_to_uri(filename.c_str(), hostname.c_str(), &error);
if(error)
Error::throw_exception(error);
return Glib::ustring(ScopedPtr<char>(buf).get());
}
Glib::ustring filename_to_uri(const std::string& filename)
{
GError* error = 0;
char *const buf = g_filename_to_uri(filename.c_str(), 0, &error);
if(error)
Error::throw_exception(error);
return Glib::ustring(ScopedPtr<char>(buf).get());
}
Glib::ustring filename_display_basename(const std::string& filename)
{
char *const buf = g_filename_display_basename(filename.c_str());
return Glib::ustring(ScopedPtr<char>(buf).get());
}
Glib::ustring filename_display_name(const std::string& filename)
{
char *const buf = g_filename_display_name(filename.c_str());
return Glib::ustring(ScopedPtr<char>(buf).get());
}
} // namespace Glib
namespace
{
} // anonymous namespace
Glib::ConvertError::ConvertError(Glib::ConvertError::Code error_code, const Glib::ustring& error_message)
:
Glib::Error (G_CONVERT_ERROR, error_code, error_message)
{}
Glib::ConvertError::ConvertError(GError* gobject)
:
Glib::Error (gobject)
{}
Glib::ConvertError::Code Glib::ConvertError::code() const
{
return static_cast<Code>(Glib::Error::code());
}
void Glib::ConvertError::throw_func(GError* gobject)
{
throw Glib::ConvertError(gobject);
}

View file

@ -1,299 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_CONVERT_H
#define _GLIBMM_CONVERT_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gtypes.h> /* for gsize */
#include <glibmm/error.h>
#include <glibmm/ustring.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GIConv* GIConv; }
#endif
namespace Glib
{
/** @defgroup CharsetConv Character Set Conversion
* Utility functions for converting strings between different character sets.
* @{
*/
/** Exception class for charset conversion errors.
* Glib::convert() and friends throw a ConvertError exception if the charset
* conversion failed for some reason. When writing non-trivial applications
* you should always catch those errors, and then try to recover, or tell the
* user the input was invalid.
*/
class ConvertError : public Glib::Error
{
public:
enum Code
{
NO_CONVERSION,
ILLEGAL_SEQUENCE,
FAILED,
PARTIAL_INPUT,
BAD_URI,
NOT_ABSOLUTE_PATH
};
ConvertError(Code error_code, const Glib::ustring& error_message);
explicit ConvertError(GError* gobject);
Code code() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
private:
static void throw_func(GError* gobject);
friend void wrap_init(); // uses throw_func()
#endif
};
/** Thin %iconv() wrapper.
* glibmm provides Glib::convert() and Glib::locale_to_utf8() which
* are likely more convenient than the raw iconv wrappers. However,
* creating an IConv object once and using the convert() method could
* be useful when converting multiple times between the same charsets.
*/
class IConv
{
public:
/** Open new conversion descriptor.
* @param to_codeset Destination codeset.
* @param from_codeset %Source codeset.
* @throw Glib::ConvertError
*/
IConv(const std::string& to_codeset, const std::string& from_codeset);
explicit IConv(GIConv gobject);
/** Close conversion descriptor.
*/
~IConv();
/** Same as the standard UNIX routine %iconv(), but may be implemented
* via libiconv on UNIX flavors that lack a native implementation. glibmm
* provides Glib::convert() and Glib::locale_to_utf8() which are likely
* more convenient than the raw iconv wrappers.
* @param inbuf Bytes to convert.
* @param inbytes_left In/out parameter, bytes remaining to convert in @a inbuf.
* @param outbuf Converted output bytes.
* @param outbytes_left In/out parameter, bytes available to fill in @a outbuf.
* @return Count of non-reversible conversions, or <tt>static_cast<size_t>(-1)</tt> on error.
*/
size_t iconv(char** inbuf, gsize* inbytes_left, char** outbuf, gsize* outbytes_left);
/** Reset conversion descriptor to initial state.
* Same as <tt>iconv(0, 0, 0, 0)</tt>, but implemented slightly differently
* in order to work on Sun Solaris <= 7. It's also more obvious so you're
* encouraged to use it.
*/
void reset();
/** Convert from one encoding to another.
* @param str The string to convert.
* @return The converted string.
* @throw Glib::ConvertError
*/
std::string convert(const std::string& str);
GIConv gobj() { return gobject_; }
private:
GIConv gobject_;
// noncopyable
IConv(const IConv&);
IConv& operator=(const IConv&);
};
/** Get the charset used by the current locale.
* @return Whether the current locale uses the UTF-8 charset.
*/
bool get_charset();
/** Get the charset used by the current locale.
* @param charset Will be filled with the charset's name.
* @return Whether the current locale uses the UTF-8 charset.
*/
bool get_charset(std::string& charset);
/** Convert from one encoding to another.
* @param str The string to convert.
* @param to_codeset Name of the target charset.
* @param from_codeset Name of the source charset.
* @return The converted string.
* @throw Glib::ConvertError
*/
std::string convert(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset);
/** Converts a string from one character set to another, possibly including
* fallback sequences for characters not representable in the output.
* Characters not in the target encoding will be represented as Unicode
* escapes <tt>\\x{XXXX}</tt> or <tt>\\x{XXXXXX}</tt>.
* @param str The string to convert.
* @param to_codeset Name of the target charset.
* @param from_codeset Name of the source charset.
* @return The converted string.
* @throw Glib::ConvertError
*/
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset);
/** Converts a string from one character set to another, possibly including
* fallback sequences for characters not representable in the output.
* @note It is not guaranteed that the specification for the fallback sequences
* in @a fallback will be honored. Some systems may do a approximate conversion
* from @a from_codeset to @a to_codeset in their iconv() functions, in which
* case Glib will simply return that approximate conversion.
*
* @param str The string to convert.
* @param to_codeset Name of the target charset.
* @param from_codeset Name of the source charset.
* @param fallback UTF-8 string to be used in place of characters which aren't
* available in the target encoding. All characters in the fallback string
* @em must be available in the target encoding.
* @return The converted string.
* @throw Glib::ConvertError
*/
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset,
const Glib::ustring& fallback);
/** Convert from the current locale's encoding to UTF-8.
* Convenience wrapper around Glib::convert().
* @param opsys_string The string to convert. Must be encoded in the charset
* used by the operating system's current locale.
* @return The input string converted to UTF-8 encoding.
* @throw Glib::ConvertError
*/
Glib::ustring locale_to_utf8(const std::string& opsys_string);
/** Convert from UTF-8 to the current locale's encoding.
* Convenience wrapper around Glib::convert().
* @param utf8_string The UTF-8 string to convert.
* @return The input string converted to the charset used by the operating
* system's current locale.
* @throw Glib::ConvertError
*/
std::string locale_from_utf8(const Glib::ustring& utf8_string);
/** Converts a string which is in the encoding used for filenames into
* a UTF-8 string.
* @param opsys_string A string in the encoding for filenames.
* @return The converted string.
* @throw Glib::ConvertError
*/
Glib::ustring filename_to_utf8(const std::string& opsys_string);
/** Converts a string from UTF-8 to the encoding used for filenames.
* @param utf8_string A UTF-8 encoded string.
* @return The converted string.
* @throw Glib::ConvertError
*/
std::string filename_from_utf8(const Glib::ustring& utf8_string);
/** Converts an escaped UTF-8 encoded URI to a local filename
* in the encoding used for filenames.
* @param uri A string in the encoding for filenames.
* @param hostname Location to store hostname for the URI. If there is no
* hostname in the URI, <tt>""</tt> will be stored in this location.
* @return The resulting filename.
* @throw Glib::ConvertError
*/
std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname);
/** Converts an escaped UTF-8 encoded URI to a local filename in the encoding
* used for filenames.
* @param uri A string in the encoding for filenames.
* @return The resulting filename.
* @throw Glib::ConvertError
*/
std::string filename_from_uri(const Glib::ustring& uri);
/** Converts an absolute filename to an escaped UTF-8 encoded URI.
* @param filename An absolute filename specified in the encoding used
* for filenames by the operating system.
* @param hostname A UTF-8 encoded hostname.
* @return The resulting URI.
* @throw Glib::ConvertError
*/
Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname);
/** Converts an absolute filename to an escaped UTF-8 encoded URI.
* @param filename An absolute filename specified in the encoding used
* for filenames by the operating system.
* @return The resulting URI.
* @throw Glib::ConvertError
*/
Glib::ustring filename_to_uri(const std::string& filename);
/** Returns the display basename for the particular filename, guaranteed
* to be valid UTF-8. The display name might not be identical to the filename,
* for instance there might be problems converting it to UTF-8, and some files
* can be translated in the display
*
* You must pass the whole absolute pathname to this function so that
* translation of well known locations can be done.
*
* This function is preferred over filename_display_name() if you know the
* whole path, as it allows translation.
*
* @param filename An absolute pathname in the GLib file name encoding.
* @result A string containing a rendition of the basename of the filename in valid UTF-8
*/
Glib::ustring filename_display_basename(const std::string& filename);
/** Converts a filename into a valid UTF-8 string. The
* conversion is not necessarily reversible, so you
* should keep the original around and use the return
* value of this function only for display purposes.
* Unlike g_filename_to_utf8(), the result is guaranteed
* to be non-empty even if the filename actually isn't in the GLib
* file name encoding.
*
* If you know the whole pathname of the file you should use
* g_filename_display_basename(), since that allows location-based
* translation of filenames.
*
* @param filename: a pathname hopefully in the GLib file name encoding
* @result A string containing a rendition of the filename in valid UTF-8.
*/
Glib::ustring filename_display_name(const Glib::ustring& filename);
/** @} group CharsetConv */
} // namespace Glib
#endif /* _GLIBMM_CONVERT_H */

View file

@ -1,348 +0,0 @@
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <glibmm/date.h>
#include <glibmm/private/date_p.h>
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gmem.h>
#include <glib/gmessages.h>
#include <ctime>
#include <algorithm>
#include <glibmm/convert.h>
#include <glibmm/utility.h>
#include <glibmmconfig.h>
GLIBMM_USING_STD(max)
namespace Glib
{
Date::Date()
{
g_date_clear(&gobject_, 1);
}
Date::Date(Date::Day day, Date::Month month, Date::Year year)
{
g_date_clear(&gobject_, 1);
g_date_set_dmy(&gobject_, day, (GDateMonth) month, year);
}
Date::Date(guint32 julian_day)
{
g_date_clear(&gobject_, 1);
g_date_set_julian(&gobject_, julian_day);
}
Date::Date(const GDate& castitem)
:
gobject_ (castitem)
{}
void Date::clear()
{
g_date_clear(&gobject_, 1);
}
void Date::set_parse(const Glib::ustring& str)
{
g_date_set_parse(&gobject_, str.c_str());
}
void Date::set_time(GTime time)
{
g_date_set_time(&gobject_, time);
}
void Date::set_month(Date::Month month)
{
g_date_set_month(&gobject_, (GDateMonth) month);
}
void Date::set_day(Date::Day day)
{
g_date_set_day(&gobject_, day);
}
void Date::set_year(Date::Year year)
{
g_date_set_year(&gobject_, year);
}
void Date::set_dmy(Date::Day day, Date::Month month, Date::Year year)
{
g_date_set_dmy(&gobject_, day, (GDateMonth) month, year);
}
void Date::set_julian(guint32 julian_day)
{
g_date_set_julian(&gobject_, julian_day);
}
Date& Date::add_days(int n_days)
{
if(n_days >= 0)
g_date_add_days(&gobject_, n_days);
else
g_date_subtract_days(&gobject_, -n_days);
return *this;
}
Date& Date::subtract_days(int n_days)
{
if(n_days >= 0)
g_date_subtract_days(&gobject_, n_days);
else
g_date_add_days(&gobject_, -n_days);
return *this;
}
Date& Date::add_months(int n_months)
{
if(n_months >= 0)
g_date_add_months(&gobject_, n_months);
else
g_date_subtract_months(&gobject_, -n_months);
return *this;
}
Date& Date::subtract_months(int n_months)
{
if(n_months >= 0)
g_date_subtract_months(&gobject_, n_months);
else
g_date_add_months(&gobject_, -n_months);
return *this;
}
Date& Date::add_years(int n_years)
{
if(n_years >= 0)
g_date_add_years(&gobject_, n_years);
else
g_date_subtract_years(&gobject_, -n_years);
return *this;
}
Date& Date::subtract_years(int n_years)
{
if(n_years >= 0)
g_date_subtract_years(&gobject_, n_years);
else
g_date_add_years(&gobject_, -n_years);
return *this;
}
int Date::days_between(const Date& rhs) const
{
return g_date_days_between(&gobject_, &rhs.gobject_);
}
int Date::compare(const Date& rhs) const
{
return g_date_compare(&gobject_, &rhs.gobject_);
}
Date& Date::clamp(const Date& min_date, const Date& max_date)
{
g_date_clamp(&gobject_, &min_date.gobject_, &max_date.gobject_);
return *this;
}
Date& Date::clamp_min(const Date& min_date)
{
g_date_clamp(&gobject_, &min_date.gobject_, 0 /* see the C docs */);
return *this;
}
Date& Date::clamp_max(const Date& max_date)
{
g_date_clamp(&gobject_, 0 /* see the C docs */, &max_date.gobject_);
return *this;
}
void Date::order(Date& other)
{
g_date_order(&gobject_, &other.gobject_);
}
Date::Weekday Date::get_weekday() const
{
return (Date::Weekday) g_date_get_weekday(&gobject_);
}
Date::Month Date::get_month() const
{
return (Date::Month) g_date_get_month(&gobject_);
}
Date::Year Date::get_year() const
{
return g_date_get_year(&gobject_);
}
Date::Day Date::get_day() const
{
return g_date_get_day(&gobject_);
}
guint32 Date::get_julian() const
{
return g_date_get_julian(&gobject_);
}
unsigned int Date::get_day_of_year() const
{
return g_date_get_day_of_year(&gobject_);
}
unsigned int Date::get_monday_week_of_year() const
{
return g_date_get_monday_week_of_year(&gobject_);
}
unsigned int Date::get_sunday_week_of_year() const
{
return g_date_get_sunday_week_of_year(&gobject_);
}
bool Date::is_first_of_month() const
{
return g_date_is_first_of_month(&gobject_);
}
bool Date::is_last_of_month() const
{
return g_date_is_last_of_month(&gobject_);
}
//static
guint8 Date::get_days_in_month(Date::Month month, Date::Year year)
{
return g_date_get_days_in_month((GDateMonth) month, year);
}
//static
guint8 Date::get_monday_weeks_in_year(Date::Year year)
{
return g_date_get_monday_weeks_in_year(year);
}
//static
guint8 Date::get_sunday_weeks_in_year(Date::Year year)
{
return g_date_get_sunday_weeks_in_year(year);
}
//static
bool Date::is_leap_year(Date::Year year)
{
return g_date_is_leap_year(year);
}
Glib::ustring Date::format_string(const Glib::ustring& format) const
{
struct tm tm_data;
g_date_to_struct_tm(&gobject_, &tm_data);
const std::string locale_format = locale_from_utf8(format);
gsize bufsize = std::max<gsize>(2 * locale_format.size(), 128);
do
{
const ScopedPtr<char> buf (static_cast<char*>(g_malloc(bufsize)));
// Set the first byte to something other than '\0', to be able to
// recognize whether strftime actually failed or just returned "".
buf.get()[0] = '\1';
const gsize len = strftime(buf.get(), bufsize, locale_format.c_str(), &tm_data);
if(len != 0 || buf.get()[0] == '\0')
{
g_assert(len < bufsize);
return locale_to_utf8(std::string(buf.get(), len));
}
}
while((bufsize *= 2) <= 65536);
// This error is quite unlikely (unless strftime is buggy).
g_warning("Glib::Date::format_string(): maximum size of strftime buffer exceeded, giving up");
return Glib::ustring();
}
void Date::to_struct_tm(struct tm& dest) const
{
g_date_to_struct_tm(&gobject_, &dest);
}
bool Date::valid() const
{
return g_date_valid(&gobject_);
}
//static
bool Date::valid_day(Date::Day day)
{
return g_date_valid_day(day);
}
//static
bool Date::valid_month(Date::Month month)
{
return g_date_valid_month((GDateMonth) month);
}
//static
bool Date::valid_year(Date::Year year)
{
return g_date_valid_year(year);
}
//static
bool Date::valid_weekday(Date::Weekday weekday)
{
return g_date_valid_weekday((GDateWeekday) weekday);
}
//static
bool Date::valid_julian(guint32 julian_day)
{
return g_date_valid_julian(julian_day);
}
//static
bool Date::valid_dmy(Date::Day day, Date::Month month, Date::Year year)
{
return g_date_valid_dmy(day, (GDateMonth) month, year);
}
} // namespace Glib
namespace
{
} // anonymous namespace

View file

@ -1,427 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_DATE_H
#define _GLIBMM_DATE_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/ustring.h>
#include <glib/gdate.h>
#include <glib/gtypes.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { struct tm; }
#endif
namespace Glib
{
/** Julian calendar date.
*/
class Date
{
public:
typedef guint8 Day;
typedef guint16 Year;
/** @addtogroup glibmmEnums Enums and Flags */
/**
* @ingroup glibmmEnums
*/
enum Month
{
BAD_MONTH,
JANUARY,
FEBRUARY,
MARCH,
APRIL,
MAY,
JUNE,
JULY,
AUGUST,
SEPTEMBER,
OCTOBER,
NOVEMBER,
DECEMBER
};
/**
* @ingroup glibmmEnums
*/
enum Weekday
{
BAD_WEEKDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
SUNDAY
};
/**
* @ingroup glibmmEnums
*/
enum DMY
{
DAY,
MONTH,
YEAR
};
static const Day BAD_DAY = 0;
static const Year BAD_YEAR = 0;
static const guint32 BAD_JULIAN = 0;
Date();
Date(Day day, Month month, Year year);
explicit Date(guint32 julian_day);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
explicit Date(const GDate& castitem);
#endif
void clear();
/** Clear the date. The cleared dates will not represent an existing date, but will not contain garbage.
* @param month Month to set.
*/
/** Parses a user-inputted string str, and try to figure out what date it represents, taking the current locale into account. If the string is successfully parsed, the date will be valid after the call. Otherwise, it will be invalid.
* This function is not appropriate for file formats and the like; it isn't very precise, and its exact behavior varies with the locale. It's intended to be a heuristic routine that guesses what the user means by a given string (and it does work pretty well in that capacity).
* @param str String to parse.
*/
void set_parse (const Glib::ustring& str);
//TODO: Add set_time_current() - see the docs comment below.?
/** Sets the value of a date from a GTime (time_t) value.
* To set the value of a date to the current day, you could write:
*
*set_time(time(NULL));
*
* @param time GTime value to set.
*/
void set_time(GTime time);
/** Sets the month of the year. If the resulting day-month-year triplet is invalid, the date will be invalid.
* @param month Month to set.
*/
void set_month(Month month);
/** Sets the day of the month. If the resulting day-month-year triplet is invalid, the date will be invalid.
* @param day Day to set.
*/
void set_day(Day day);
/** Sets the year. If the resulting day-month-year triplet is invalid, the date will be invalid.
* @param year Year to set.
*/
void set_year(Year year);
/** Sets the value of a day, month, and year.. If the resulting day-month-year triplet is invalid, the date will be invalid.
* @param day Day to set.
* @param month Month to set.
* @param year Year to set.
*/
void set_dmy(Day day, Month month, Year year);
/** Sets the value of a GDate from a Julian day number.
* @param julian_day Julian day to set.
*/
void set_julian(guint32 julian_day);
//TODO: Why return Date& (which is always *this) from these methods?
//Isn't it enough to also change the current instance?
//Maybe we need a copy constructor too.
//murrayc
/** Add a number of days to a Date.
* @param n_days Days to add.
* @return Resulting Date
*/
Date& add_days(int n_days);
/** Subtract n_days to a Date.
* @param n_days Days to subtract.
* @return Resulting Date
*/
Date& subtract_days(int n_days);
/** Add n_months to a Date.
* @param n_months Months to add.
* @return Resulting Date
*/
Date& add_months(int n_months);
/** Subtract n_months to a Date.
* @param n_months Months to subtract.
* @return Resulting Date
*/
Date& subtract_months(int n_months);
/** Add n_days to a Date.
* @param n_years Years to add.
* @return Resulting Date
*/
Date& add_years(int n_years);
/** Subtract n_years to a Date.
* @param n_years Years to subtract.
* @return Resulting Date
*/
Date& subtract_years(int n_years);
/** Calculate days between two dates.
* @param rhs Date.
* @return Numbers of days.
*/
int days_between(const Date& rhs) const;
/** Compare two dates.
* @param rhs Date to compare.
* @return Result of comparition.
*/
int compare(const Date& rhs) const;
/** If date is prior to min_date, sets date equal to min_date.
* If date falls after max_date, sets date equal to max_date. All dates must be valid.
* See also clamp_min() and clamp_max().
* @param min_date Date minimum value.
* @param max_date Date maximum value.
* @return Date in interval.
*/
Date& clamp(const Date& min_date, const Date& max_date);
/** If date is prior to min_date, sets date equal to min_date.
* See also clamp(), and clamp_max().
* @param min_date Date minimum value.
* @return Date in interval.
*/
Date& clamp_min(const Date& min_date);
/** If date falls after max_date, sets date equal to max_date.
* See also clamp(), and clamp_min().
* @param max_date Date maximum value.
* @return Date in interval.
*/
Date& clamp_max(const Date& max_date);
/** Checks if date is less than or equal to other date, and swap the values if this is not the case.
* @param other Date ro compare.
* @return Date.
*/
void order(Date& other);
/** Returns the day of the week for a Date. The date must be valid.
* @return Day of the week as a Date::Weekday.
*/
Weekday get_weekday() const;
/** Returns the month of the year. The date must be valid.
* @return Month of the year as a Date::Month.
*/
Month get_month() const;
/** Returns the year of a Date. The date must be valid.
* @return Year in which the date falls.
*/
Year get_year() const;
/** Returns the day of the month. The date must be valid.
* @return Day of the month..
*/
Day get_day() const;
/** Returns the Julian day or "serial number" of the Date.
* The Julian day is simply the number of days since January 1, Year 1;
* i.e., January 1, Year 1 is Julian day 1; January 2, Year 1 is Julian day 2, etc.
* The date must be valid.
* @return Julian day.
*/
guint32 get_julian() const;
/** Returns the day of the year, where Jan 1 is the first day of the year.
* The date must be valid.
* @return Julian day.
*/
unsigned int get_day_of_year() const;
/** Returns the week of the year, where weeks are understood to start on Monday.
* If the date is before the first Monday of the year, return 0.
* The date must be valid.
* @return Week of the year.
*/
unsigned int get_monday_week_of_year() const;
/** Returns the week of the year during which this date falls, if weeks are understood to being on Sunday.
* Can return 0 if the day is before the first Sunday of the year.
* The date must be valid.
* @return Week of the year.
*/
unsigned int get_sunday_week_of_year() const;
/** Returns true if the date is on the first of a month.
* The date must be valid.
* @return true if the date is the first of the month.
*/
bool is_first_of_month() const;
/** Returns true if the date is the last day of the month.
* The date must be valid.
* @return true if the date is the last day of the month.
*/
bool is_last_of_month() const;
/** Returns the number of days in a month, taking leap years into account.
* @param month Month.
* @param year Year.
* @return Number of days in month during the year.
*/
static guint8 get_days_in_month(Month month, Year year);
/** Returns the number of weeks in the year, where weeks are taken to start on Monday. Will be 52 or 53.
* (Years always have 52 7-day periods, plus 1 or 2 extra days depending on whether it's a leap year. This function is basically telling you how many Mondays are in the year, i.e. there are 53 Mondays if one of the extra days happens to be a Monday.)
* @param year Year to count weeks in.
* @return Number of weeks.
*/
static guint8 get_monday_weeks_in_year(Year year);
/** Returns the number of weeks in the year, where weeks are taken to start on Sunday. Will be 52 or 53.
* (Years always have 52 7-day periods, plus 1 or 2 extra days depending on whether it's a leap year. This function is basically telling you how many Sundays are in the year, i.e. there are 53 Sundays if one of the extra days happens to be a Sunday.)
* @param year Year to count weeks in.
* @return Number of weeks.
*/
static guint8 get_sunday_weeks_in_year(Year year);
/** Returns true if the year is a leap year.
* @param year Year to check.
* @return true if the year is a leap year.
*/
static bool is_leap_year(Year year);
/** Convert date to string.
* @param format A format string as used by @c strftime(), in UTF-8
* encoding. Only date formats are allowed, the result of time formats
* is undefined.
* @return The formatted date string.
* @throw Glib::ConvertError
*/
Glib::ustring format_string(const Glib::ustring& format) const;
/** Fills in the date-related bits of a struct tm using the date value. Initializes the non-date parts with something sane but meaningless.
* @param dest Struct tm to fill.
*/
void to_struct_tm(struct tm& dest) const;
/** Returns true if the Date represents an existing day.
* @return true if the date is valid.
*/
bool valid() const;
/** Returns true if the day of the month is valid (a day is valid if it's between 1 and 31 inclusive).
* @param day Day to check.
* @return true if the day is valid.
*/
static bool valid_day(Day day);
/** Returns true if the month value is valid. The 12 Date::Month enumeration values are the only valid months.
* @param month Month to check.
* @return true if the month is valid.
*/
static bool valid_month(Month month);
/** Returns true if the year is valid.
* Any year greater than 0 is valid, though there is a 16-bit limit to what Date will understand.
* @param year Year to check.
* @return true if the year is valid.
*/
static bool valid_year(Year year);
/** Returns true if the weekday is valid.
* The 7 Date::Weekday enumeration values are the only valid.
* @param weekday Weekday to check.
* @return true if the weekday is valid.
*/
static bool valid_weekday(Weekday weekday);
/** Returns true if the Julian day is valid.
* Anything greater than zero is basically a valid Julian, though there is a 32-bit limit.
* @param julian_day Julian day to check.
* @return true if the Julian day is valid.
*/
static bool valid_julian(guint32 julian_day);
/** Returns true if the day-month-year triplet forms a valid, existing day in the range of days Date understands (Year 1 or later, no more than a few thousand years in the future).
* @param day Day to check.
* @param month Month to check.
* @param year Year to check.
* @return true if the date is a valid one.
*/
static bool valid_dmy(Day day, Month month, Year year);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
GDate* gobj() { return &gobject_; }
const GDate* gobj() const { return &gobject_; }
#endif
private:
GDate gobject_;
};
/** @relates Glib::Date */
inline bool operator==(const Date& lhs, const Date& rhs)
{ return (lhs.compare(rhs) == 0); }
/** @relates Glib::Date */
inline bool operator!=(const Date& lhs, const Date& rhs)
{ return (lhs.compare(rhs) != 0); }
/** @relates Glib::Date */
inline bool operator<(const Date& lhs, const Date& rhs)
{ return (lhs.compare(rhs) < 0); }
/** @relates Glib::Date */
inline bool operator>(const Date& lhs, const Date& rhs)
{ return (lhs.compare(rhs) > 0); }
/** @relates Glib::Date */
inline bool operator<=(const Date& lhs, const Date& rhs)
{ return (lhs.compare(rhs) <= 0); }
/** @relates Glib::Date */
inline bool operator>=(const Date& lhs, const Date& rhs)
{ return (lhs.compare(rhs) >= 0); }
} // namespace Glib
#endif /* _GLIBMM_DATE_H */

View file

@ -1,21 +0,0 @@
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/debug.h>

View file

@ -1,85 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_DEBUG_H
#define _GLIBMM_DEBUG_H
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gmacros.h>
#include <glibmmconfig.h>
// Some stuff that's useful when debugging gtkmm internals:
#ifdef GLIBMM_DEBUG_REFCOUNTING
#include <glib/gmessages.h>
/* We can't use G_GNUC_PRETTY_FUNCTION because it's always disabled in C++,
* even though __PRETTY_FUNCTION__ works fine in C++ as well if you use it
* right (i.e. concatenation with string literals isn't allowed).
*/
#ifdef __GNUC__
#define GLIBMM_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
#else
#define GLIBMM_GNUC_PRETTY_FUNCTION ""
#endif
#define GLIBMM_DEBUG_REFERENCE(cppInstance, cInstance) \
G_STMT_START{ \
void *const cppInstance__ = (void*) (cppInstance); \
void *const cInstance__ = (void*) (cInstance); \
g_log(G_LOG_DOMAIN, \
G_LOG_LEVEL_DEBUG, \
"file %s: line %d (%s):\n" \
"ref: C++ instance: %p; C instance: %p, ref_count = %u, type = %s\n", \
__FILE__, \
__LINE__, \
GLIBMM_GNUC_PRETTY_FUNCTION, \
cppInstance__, \
cInstance__, \
G_OBJECT(cInstance__)->ref_count, \
G_OBJECT_TYPE_NAME(cInstance__)); \
}G_STMT_END
#define GLIBMM_DEBUG_UNREFERENCE(cppInstance, cInstance) \
G_STMT_START{ \
void *const cppInstance__ = (void*) (cppInstance); \
void *const cInstance__ = (void*) (cInstance); \
g_log(G_LOG_DOMAIN, \
G_LOG_LEVEL_DEBUG, \
"file %s: line %d (%s):\n" \
"unref: C++ instance: %p; C instance: %p, ref_count = %u, type = %s\n", \
__FILE__, \
__LINE__, \
GLIBMM_GNUC_PRETTY_FUNCTION, \
cppInstance__, \
cInstance__, \
G_OBJECT(cInstance__)->ref_count, \
G_OBJECT_TYPE_NAME(cInstance__)); \
}G_STMT_END
#else
#define GLIBMM_DEBUG_REFERENCE(cppInstance,cInstance) G_STMT_START{ (void)0; }G_STMT_END
#define GLIBMM_DEBUG_UNREFERENCE(cppInstance,cInstance) G_STMT_START{ (void)0; }G_STMT_END
#endif /* GLIBMM_DEBUG_REFCOUNTING */
#endif /* _GLIBMM_DEBUG_H */

View file

@ -1,442 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/dispatcher.h>
#include <glibmm/exceptionhandler.h>
#include <glibmm/fileutils.h>
#include <glibmm/main.h>
#include <glibmm/thread.h>
#include <cerrno>
#include <fcntl.h>
#include <glib.h>
#ifndef G_OS_WIN32
#include <unistd.h>
#if defined(_tru64) //TODO: Use the real define
//EINTR is not defined on Tru64
//I have tried including these
//#include <sys/types.h>
//#include <sys/statvfs.h>
//#include <signal.h>
#ifndef EINTR
#define EINTR 0
#endif
#endif
#else
#include <windows.h>
#include <io.h>
#include <direct.h>
#include <list>
#endif /* G_OS_WIN32 */
namespace
{
struct DispatchNotifyData
{
unsigned long tag;
Glib::Dispatcher* dispatcher;
Glib::DispatchNotifier* notifier;
DispatchNotifyData()
: tag (0), dispatcher (0), notifier (0) {}
DispatchNotifyData(unsigned long tag_, Glib::Dispatcher* dispatcher_, Glib::DispatchNotifier* notifier_)
: tag (tag_), dispatcher (dispatcher_), notifier (notifier_) {}
};
static void warn_failed_pipe_io(const char* what, int err_no)
{
#ifdef G_OS_WIN32
const char *const message = g_win32_error_message(err_no);
#else
const char *const message = g_strerror(err_no);
#endif
g_critical("Error in inter-thread communication: %s() failed: %s", what, message);
}
#ifndef G_OS_WIN32
/*
* Try to set the close-on-exec flag of the file descriptor,
* so that it won't be leaked if a new process is spawned.
*/
static void fd_set_close_on_exec(int fd)
{
const int flags = fcntl(fd, F_GETFD, 0);
g_return_if_fail(flags >= 0);
fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
}
#endif /* !G_OS_WIN32 */
/*
* One word: paranoia.
*/
#ifdef G_OS_WIN32
static void fd_close_and_invalidate(HANDLE& fd)
{
if(fd != 0)
{
if(!CloseHandle(fd))
warn_failed_pipe_io("CloseHandle", GetLastError());
fd = 0;
}
}
#else /* !G_OS_WIN32 */
static void fd_close_and_invalidate(int& fd)
{
if(fd >= 0)
{
int result;
do
result = close(fd);
while(result < 0 && errno == EINTR);
if(result < 0)
warn_failed_pipe_io("close", errno);
fd = -1;
}
}
#endif /* !G_OS_WIN32 */
} // anonymous namespace
namespace Glib
{
class DispatchNotifier
{
public:
~DispatchNotifier();
static DispatchNotifier* reference_instance(const Glib::RefPtr<MainContext>& context);
static void unreference_instance(DispatchNotifier* notifier);
void send_notification(Dispatcher* dispatcher);
protected:
// Only used by reference_instance(). Should be private, but that triggers
// a silly gcc warning even though DispatchNotifier has static methods.
explicit DispatchNotifier(const Glib::RefPtr<MainContext>& context);
private:
static Glib::StaticPrivate<DispatchNotifier> thread_specific_instance_;
Glib::RefPtr<MainContext> context_;
int ref_count_;
#ifdef G_OS_WIN32
HANDLE fd_receiver_;
Glib::Mutex mutex_;
std::list<DispatchNotifyData> notify_queue_;
#else
int fd_receiver_;
int fd_sender_;
#endif /* !G_OS_WIN32 */
sigc::connection conn_io_handler_;
void create_pipe();
bool pipe_io_handler(Glib::IOCondition condition);
// noncopyable
DispatchNotifier(const DispatchNotifier&);
DispatchNotifier& operator=(const DispatchNotifier&);
};
/**** Glib::DispatchNotifier ***********************************************/
Glib::StaticPrivate<DispatchNotifier>
DispatchNotifier::thread_specific_instance_ = GLIBMM_STATIC_PRIVATE_INIT;
DispatchNotifier::DispatchNotifier(const Glib::RefPtr<MainContext>& context)
:
context_ (context),
ref_count_ (0),
#ifdef G_OS_WIN32
fd_receiver_ (0),
mutex_ (),
notify_queue_ ()
#else
fd_receiver_ (-1),
fd_sender_ (-1)
#endif
{
create_pipe();
try
{
#ifdef G_OS_WIN32
conn_io_handler_ = context_->signal_io().connect(
sigc::mem_fun(*this, &DispatchNotifier::pipe_io_handler),
GPOINTER_TO_INT(fd_receiver_), Glib::IO_IN);
#else /* !G_OS_WIN32 */
conn_io_handler_ = context_->signal_io().connect(
sigc::mem_fun(*this, &DispatchNotifier::pipe_io_handler),
fd_receiver_, Glib::IO_IN);
#endif /* !G_OS_WIN32 */
}
catch(...)
{
#ifndef G_OS_WIN32
fd_close_and_invalidate(fd_sender_);
#endif /* !G_OS_WIN32 */
fd_close_and_invalidate(fd_receiver_);
throw;
}
}
DispatchNotifier::~DispatchNotifier()
{
// Disconnect manually because we don't inherit from sigc::trackable
conn_io_handler_.disconnect();
#ifndef G_OS_WIN32
fd_close_and_invalidate(fd_sender_);
#endif /* !G_OS_WIN32 */
fd_close_and_invalidate(fd_receiver_);
}
void DispatchNotifier::create_pipe()
{
#ifdef G_OS_WIN32
// On Win32 we are using synchronization object instead of pipe
// thus storing its handle as fd_receiver_.
fd_receiver_ = CreateEvent(0, FALSE, FALSE, 0);
if(!fd_receiver_)
{
GError* const error = g_error_new(G_FILE_ERROR, G_FILE_ERROR_FAILED,
"Failed to create event for inter-thread communication: %s",
g_win32_error_message(GetLastError()));
throw Glib::FileError(error);
}
#else /* !G_OS_WIN32 */
int filedes[2] = { -1, -1 };
if(pipe(filedes) < 0)
{
GError* const error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno),
"Failed to create pipe for inter-thread communication: %s",
g_strerror(errno));
throw Glib::FileError(error);
}
fd_set_close_on_exec(filedes[0]);
fd_set_close_on_exec(filedes[1]);
fd_receiver_ = filedes[0];
fd_sender_ = filedes[1];
#endif /* !G_OS_WIN32 */
}
// static
DispatchNotifier* DispatchNotifier::reference_instance(const Glib::RefPtr<MainContext>& context)
{
DispatchNotifier* instance = thread_specific_instance_.get();
if(!instance)
{
instance = new DispatchNotifier(context);
thread_specific_instance_.set(instance);
}
else
{
// Prevent massive mess-up.
g_return_val_if_fail(instance->context_ == context, 0);
}
++instance->ref_count_; // initially 0
return instance;
}
// static
void DispatchNotifier::unreference_instance(DispatchNotifier* notifier)
{
DispatchNotifier *const instance = thread_specific_instance_.get();
// Yes, the notifier argument is only used to check for sanity.
g_return_if_fail(instance == notifier);
if(--instance->ref_count_ <= 0)
{
g_return_if_fail(instance->ref_count_ == 0); // could be < 0 if messed up
// This will cause deletion of the notifier object.
thread_specific_instance_.set(0);
}
}
void DispatchNotifier::send_notification(Dispatcher* dispatcher)
{
#ifdef G_OS_WIN32
{
Glib::Mutex::Lock lock (mutex_);
notify_queue_.push_back(DispatchNotifyData(0xdeadbeef, dispatcher, this));
}
// Send notification event to GUI-thread.
if(!SetEvent(fd_receiver_))
{
warn_failed_pipe_io("SetEvent", GetLastError());
return;
}
#else /* !G_OS_WIN32 */
DispatchNotifyData data (0xdeadbeef, dispatcher, this);
gssize n_written;
do
n_written = write(fd_sender_, &data, sizeof(data));
while(n_written < 0 && errno == EINTR);
if(n_written < 0)
{
warn_failed_pipe_io("write", errno);
return;
}
// All data must be written in a single call to write(), otherwise we can't
// guarantee reentrancy since another thread might be scheduled between two
// write() calls. The manpage is a bit unclear about this -- but I hope
// it's safe to assume immediate success for the tiny amount of data we're
// writing.
g_return_if_fail(n_written == sizeof(data));
#endif /* !G_OS_WIN32 */
}
bool DispatchNotifier::pipe_io_handler(Glib::IOCondition)
{
#ifdef G_OS_WIN32
DispatchNotifyData data;
for(;;)
{
{
Glib::Mutex::Lock lock (mutex_);
if(notify_queue_.empty())
break;
data = notify_queue_.front();
notify_queue_.pop_front();
}
g_return_val_if_fail(data.tag == 0xdeadbeef, true);
g_return_val_if_fail(data.notifier == this, true);
// Actually, we wouldn't need the try/catch block because the Glib::Source
// C callback already does it for us. However, we do it anyway because the
// default return value is 'false', which is not what we want.
try
{
data.dispatcher->signal_();
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
#else /* !G_OS_WIN32 */
DispatchNotifyData data;
gsize n_read = 0;
do
{
void * const buffer = reinterpret_cast<guint8*>(&data) + n_read;
const gssize result = read(fd_receiver_, buffer, sizeof(data) - n_read);
if(result < 0)
{
if(errno == EINTR)
continue;
warn_failed_pipe_io("read", errno);
return true;
}
n_read += result;
}
while(n_read < sizeof(data));
g_return_val_if_fail(data.tag == 0xdeadbeef, true);
g_return_val_if_fail(data.notifier == this, true);
// Actually, we wouldn't need the try/catch block because the Glib::Source
// C callback already does it for us. However, we do it anyway because the
// default return value is 'false', which is not what we want.
try
{
data.dispatcher->signal_(); // emit
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif /* !G_OS_WIN32 */
return true;
}
/**** Glib::Dispatcher *****************************************************/
Dispatcher::Dispatcher()
:
signal_ (),
notifier_ (DispatchNotifier::reference_instance(MainContext::get_default()))
{}
Dispatcher::Dispatcher(const Glib::RefPtr<MainContext>& context)
:
signal_ (),
notifier_ (DispatchNotifier::reference_instance(context))
{}
Dispatcher::~Dispatcher()
{
DispatchNotifier::unreference_instance(notifier_);
}
void Dispatcher::emit()
{
notifier_->send_notification(this);
}
void Dispatcher::operator()()
{
emit();
}
sigc::connection Dispatcher::connect(const sigc::slot<void>& slot)
{
return signal_.connect(slot);
}
} // namespace Glib

View file

@ -1,102 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_DISPATCHER_H
#define _GLIBMM_DISPATCHER_H
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <sigc++/sigc++.h>
#include <glibmm/main.h>
namespace Glib
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
class DispatchNotifier;
#endif
/** Signal class for inter-thread communication.
* @ingroup Threads
* Glib::Dispatcher works similar to sigc::signal<void>. But unlike normal
* signals, the notification happens asynchronously through a pipe. This is
* a simple and efficient way of communicating between threads, and especially
* useful in a thread model with a single GUI thread.
*
* No mutex locking is involved, apart from the operating system's internal
* I/O locking. That implies some usage rules:
*
* @li Only one thread may connect to the signal and receive notification, but
* multiple senders are allowed even without locking.
* @li The GLib main loop must run in the receiving thread (this will be the
* GUI thread usually).
* @li The Dispatcher object must be instantiated by the receiver thread.
* @li The Dispatcher object should be instantiated before creating any of the
* sender threads, if you want to avoid extra locking.
*
* Notes about performance:
*
* @li After instantiation, Glib::Dispatcher will never lock any mutexes on its
* own. The interaction with the GLib main loop might involve locking on the
* @em receiver side. The @em sender side, however, is guaranteed not to lock,
* except for internal locking in the <tt>%write()</tt> system call.
* @li All Dispatcher instances of a receiver thread share the same pipe. That
* is, if you use Glib::Dispatcher only to notify the GUI thread, only one pipe
* is created no matter how many Dispatcher objects you have.
*/
class Dispatcher
{
public:
/** Create new Dispatcher instance using the default main context.
* @throw Glib::FileError
*/
Dispatcher();
/** Create new Dispatcher instance using an arbitrary main context.
* @throw Glib::FileError
*/
explicit Dispatcher(const Glib::RefPtr<MainContext>& context);
~Dispatcher();
void emit();
void operator()();
sigc::connection connect(const sigc::slot<void>& slot);
private:
sigc::signal<void> signal_;
DispatchNotifier* notifier_;
// noncopyable
Dispatcher(const Dispatcher&);
Dispatcher& operator=(const Dispatcher&);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
friend class Glib::DispatchNotifier;
#endif
};
/*! A Glib::Dispatcher example.
* @example thread/dispatcher.cc
*/
} // namespace Glib
#endif /* _GLIBMM_DISPATCHER_H */

View file

@ -1,187 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* error.cc
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gerror.h>
#include <glib/gmessages.h>
#include <map>
#include <glibmmconfig.h>
#include <glibmm/error.h>
#include <glibmm/wrap_init.h>
GLIBMM_USING_STD(map)
namespace
{
typedef std::map<GQuark,Glib::Error::ThrowFunc> ThrowFuncTable;
static ThrowFuncTable* throw_func_table = 0;
} // anonymous namespace
namespace Glib
{
Error::Error()
:
gobject_ (0)
{}
Error::Error(GQuark domain, int code, const Glib::ustring& message)
:
gobject_ (g_error_new_literal(domain, code, message.c_str()))
{}
Error::Error(GError* gobject, bool take_copy)
:
gobject_ ((take_copy && gobject) ? g_error_copy(gobject) : gobject)
{}
Error::Error(const Error& other)
:
Exception(other),
gobject_ ((other.gobject_) ? g_error_copy(other.gobject_) : 0)
{}
Error& Error::operator=(const Error& other)
{
if(gobject_ != other.gobject_)
{
if(gobject_)
{
g_error_free(gobject_);
gobject_ = 0;
}
if(other.gobject_)
{
gobject_ = g_error_copy(other.gobject_);
}
}
return *this;
}
Error::~Error() throw()
{
if(gobject_)
g_error_free(gobject_);
}
GQuark Error::domain() const
{
g_return_val_if_fail(gobject_ != 0, 0);
return gobject_->domain;
}
int Error::code() const
{
g_return_val_if_fail(gobject_ != 0, -1);
return gobject_->code;
}
Glib::ustring Error::what() const
{
g_return_val_if_fail(gobject_ != 0, "");
g_return_val_if_fail(gobject_->message != 0, "");
return gobject_->message;
}
bool Error::matches(GQuark domain, int code) const
{
return g_error_matches(gobject_, domain, code);
}
GError* Error::gobj()
{
return gobject_;
}
const GError* Error::gobj() const
{
return gobject_;
}
void Error::propagate(GError** dest)
{
g_propagate_error(dest, gobject_);
gobject_ = 0;
}
// static
void Error::register_init()
{
if(!throw_func_table)
{
throw_func_table = new ThrowFuncTable();
Glib::wrap_init(); // make sure that at least the Glib exceptions are registered
}
}
// static
void Error::register_cleanup()
{
if(throw_func_table)
{
delete throw_func_table;
throw_func_table = 0;
}
}
// static
void Error::register_domain(GQuark domain, Error::ThrowFunc throw_func)
{
g_assert(throw_func_table != 0);
(*throw_func_table)[domain] = throw_func;
}
// static, noreturn
void Error::throw_exception(GError* gobject)
{
g_assert(gobject != 0);
// Just in case Gtk::Main hasn't been instantiated yet.
if(!throw_func_table)
register_init();
if(const ThrowFunc throw_func = (*throw_func_table)[gobject->domain])
{
(*throw_func)(gobject);
g_assert_not_reached();
}
g_warning("Glib::Error::throw_exception():\n "
"unknown error domain '%s': throwing generic Glib::Error exception\n",
(gobject->domain) ? g_quark_to_string(gobject->domain) : "(null)");
// Doesn't copy, because error-returning functions return a newly allocated GError for us.
throw Glib::Error(gobject);
}
} // namespace Glib

View file

@ -1,77 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_ERROR_H
#define _GLIBMM_ERROR_H
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GError GError; }
#endif
#include <glib/gquark.h>
#include <glibmm/exception.h>
namespace Glib
{
class Error : public Glib::Exception
{
public:
Error();
Error(GQuark domain, int code, const Glib::ustring& message);
explicit Error(GError* gobject, bool take_copy = false);
Error(const Error& other);
Error& operator=(const Error& other);
virtual ~Error() throw();
GQuark domain() const;
int code() const;
virtual Glib::ustring what() const;
bool matches(GQuark domain, int code) const;
GError* gobj();
const GError* gobj() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
void propagate(GError** dest);
typedef void (* ThrowFunc) (GError*);
static void register_init();
static void register_cleanup();
static void register_domain(GQuark domain, ThrowFunc throw_func);
static void throw_exception(GError* gobject) G_GNUC_NORETURN;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
protected:
GError* gobject_;
};
} // namespace Glib
#endif /* _GLIBMM_ERROR_H */

View file

@ -1,40 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* exception.cc
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gmessages.h>
#include <glibmm/exception.h>
namespace Glib
{
Exception::~Exception() throw()
{}
Glib::ustring Exception::what() const
{
g_assert_not_reached();
return Glib::ustring();
}
} // namespace Glib

View file

@ -1,42 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_EXCEPTION_H
#define _GLIBMM_EXCEPTION_H
/* $Id$ */
/* exception.h
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/ustring.h>
namespace Glib
{
class Exception
{
public:
virtual ~Exception() throw() = 0;
virtual Glib::ustring what() const = 0;
};
} // namespace Glib
#endif /* _GLIBMM_EXCEPTION_H */

View file

@ -1,159 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* exceptionhandler.cc
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib.h>
#include <exception>
#include <list>
#include <glibmmconfig.h>
#include <glibmm/error.h>
#include <glibmm/exceptionhandler.h>
#include <glibmm/thread.h>
GLIBMM_USING_STD(exception)
GLIBMM_USING_STD(list)
namespace
{
typedef sigc::signal<void> HandlerList;
// Each thread has its own list of exception handlers
// to avoid thread synchronization problems.
static Glib::StaticPrivate<HandlerList> thread_specific_handler_list = GLIBMM_STATIC_PRIVATE_INIT;
static void glibmm_exception_warning(const GError* error)
{
g_assert(error != 0);
g_critical("\n"
"unhandled exception (type Glib::Error) in signal handler:\n"
"domain: %s\n"
"code : %d\n"
"what : %s\n",
g_quark_to_string(error->domain), error->code,
(error->message) ? error->message : "(null)");
}
static void glibmm_unexpected_exception()
{
try
{
throw; // re-throw current exception
}
catch(const Glib::Error& error)
{
// Access the GError directly, to avoid possible exceptions from C++ code.
glibmm_exception_warning(error.gobj());
// For most failures that cause a Glib::Error exception, aborting the
// program seems too harsh. Instead, give control back to the main loop.
return;
}
catch(const std::exception& except)
{
g_error("\n"
"unhandled exception (type std::exception) in signal handler:\n"
"what: %s\n", except.what());
}
catch(...)
{
g_error("\nunhandled exception (type unknown) in signal handler\n");
}
}
} // anonymous namespace
namespace Glib
{
sigc::connection add_exception_handler(const sigc::slot<void>& slot)
{
HandlerList* handler_list = thread_specific_handler_list.get();
if(!handler_list)
{
handler_list = new HandlerList();
thread_specific_handler_list.set(handler_list);
}
handler_list->slots().push_front(slot);
return handler_list->slots().begin();
}
// internal
void exception_handlers_invoke() throw()
{
// This function will be called from our GLib signal handler proxies
// if an exception has been caught. It's not possible to throw C++
// exceptions through C signal handlers. To handle this situation, the
// programmer can install slots to global Reusable Exception Handlers.
//
// A handler has to re-throw the current exception in a try block, and then
// catch the exceptions it knows about. Any unknown exceptions should just
// fall through, i.e. the handler must not do catch(...).
//
// We now invoke each of the installed slots until the exception has been
// handled. If there are no more handlers in the list and the exception
// is still unhandled, call glibmm_unexpected_exception().
if(HandlerList *const handler_list = thread_specific_handler_list.get())
{
HandlerList::iterator pslot = handler_list->slots().begin();
while(pslot != handler_list->slots().end())
{
// Calling an empty slot would mean ignoring the exception,
// thus we have to check for dead slots explicitly.
if(pslot->empty())
{
pslot = handler_list->slots().erase(pslot);
continue;
}
// Call the Reusable Exception Handler, which should re-throw
// the exception that's currently on the stack.
try
{
(*pslot)();
}
catch(...) // unhandled, try next slot
{
++pslot;
continue;
}
// The exception has either been handled or ignored.
// Give control back to the GLib main loop.
return;
}
}
// Critical: The exception is still unhandled.
glibmm_unexpected_exception();
}
} // namespace Glib

View file

@ -1,45 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_EXCEPTIONHANDLER_H
#define _GLIBMM_EXCEPTIONHANDLER_H
/* $Id$ */
/* exceptionhandler.h
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <sigc++/sigc++.h>
namespace Glib
{
/** Specify a slot to be called when an exception is thrown by a signal handler.
*/
sigc::connection add_exception_handler(const sigc::slot<void>& slot);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// internal
void exception_handlers_invoke() throw();
#endif
} // namespace Glib
#endif /* _GLIBMM_EXCEPTIONHANDLER_H */

View file

@ -1,217 +0,0 @@
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <glibmm/fileutils.h>
#include <glibmm/private/fileutils_p.h>
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gdir.h>
#include <glib/gfileutils.h>
#include <glib/gstrfuncs.h>
#include <glibmm/utility.h>
namespace Glib
{
/**** Glib::Dir ************************************************************/
Dir::Dir(const std::string& path)
{
GError* error = 0;
gobject_ = g_dir_open(path.c_str(), 0, &error);
if(error)
Glib::Error::throw_exception(error);
}
Dir::Dir(GDir* gobject)
:
gobject_ (gobject)
{}
Dir::~Dir()
{
if(gobject_)
g_dir_close(gobject_);
}
std::string Dir::read_name()
{
const char *const name = g_dir_read_name(gobject_);
return (name) ? std::string(name) : std::string();
}
void Dir::rewind()
{
g_dir_rewind(gobject_);
}
void Dir::close()
{
if(gobject_)
{
g_dir_close(gobject_);
gobject_ = 0;
}
}
DirIterator Dir::begin()
{
g_dir_rewind(gobject_);
return DirIterator(gobject_, g_dir_read_name(gobject_));
}
DirIterator Dir::end()
{
return DirIterator(gobject_, 0);
}
/**** Glib::DirIterator ****************************************************/
DirIterator::DirIterator()
:
gobject_ (0),
current_ (0)
{}
DirIterator::DirIterator(GDir* gobject, const char* current)
:
gobject_ (gobject),
current_ (current)
{}
std::string DirIterator::operator*() const
{
return (current_) ? std::string(current_) : std::string();
}
DirIterator& DirIterator::operator++()
{
current_ = g_dir_read_name(gobject_);
return *this;
}
void DirIterator::operator++(int)
{
current_ = g_dir_read_name(gobject_);
}
bool DirIterator::operator==(const DirIterator& rhs) const
{
return (current_ == rhs.current_);
}
bool DirIterator::operator!=(const DirIterator& rhs) const
{
return (current_ != rhs.current_);
}
bool file_test(const std::string& filename, FileTest test)
{
return g_file_test(filename.c_str(), static_cast<GFileTest>(unsigned(test)));
}
int mkstemp(std::string& filename_template)
{
const ScopedPtr<char> buf (g_strndup(filename_template.data(), filename_template.size()));
const int fileno = g_mkstemp(buf.get());
filename_template = buf.get();
return fileno;
}
int file_open_tmp(std::string& name_used, const std::string& prefix)
{
std::string basename_template (prefix);
basename_template += "XXXXXX"; // this sillyness shouldn't be in the interface
GError* error = 0;
ScopedPtr<char> buf_name_used;
const int fileno = g_file_open_tmp(basename_template.c_str(), buf_name_used.addr(), &error);
if(error)
Glib::Error::throw_exception(error);
name_used = buf_name_used.get();
return fileno;
}
int file_open_tmp(std::string& name_used)
{
GError* error = 0;
ScopedPtr<char> buf_name_used;
const int fileno = g_file_open_tmp(0, buf_name_used.addr(), &error);
if(error)
Glib::Error::throw_exception(error);
name_used = buf_name_used.get();
return fileno;
}
std::string file_get_contents(const std::string& filename)
{
ScopedPtr<char> contents;
gsize length = 0;
GError* error = 0;
g_file_get_contents(filename.c_str(), contents.addr(), &length, &error);
if(error)
Glib::Error::throw_exception(error);
return std::string(contents.get(), length);
}
} // namespace Glib
namespace
{
} // anonymous namespace
Glib::FileError::FileError(Glib::FileError::Code error_code, const Glib::ustring& error_message)
:
Glib::Error (G_FILE_ERROR, error_code, error_message)
{}
Glib::FileError::FileError(GError* gobject)
:
Glib::Error (gobject)
{}
Glib::FileError::Code Glib::FileError::code() const
{
return static_cast<Code>(Glib::Error::code());
}
void Glib::FileError::throw_func(GError* gobject)
{
throw Glib::FileError(gobject);
}

View file

@ -1,475 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_FILEUTILS_H
#define _GLIBMM_FILEUTILS_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GDir GDir; }
#endif
#include <iterator>
#include <string>
#include <glibmmconfig.h>
#include <glibmm/error.h>
GLIBMM_USING_STD(input_iterator_tag)
GLIBMM_USING_STD(string)
namespace Glib
{
/** @addtogroup glibmmEnums Enums and Flags */
/**
* @ingroup glibmmEnums
* @par Bitwise operators:
* <tt>%FileTest operator|(FileTest, FileTest)</tt><br>
* <tt>%FileTest operator&(FileTest, FileTest)</tt><br>
* <tt>%FileTest operator^(FileTest, FileTest)</tt><br>
* <tt>%FileTest operator~(FileTest)</tt><br>
* <tt>%FileTest& operator|=(FileTest&, FileTest)</tt><br>
* <tt>%FileTest& operator&=(FileTest&, FileTest)</tt><br>
* <tt>%FileTest& operator^=(FileTest&, FileTest)</tt><br>
*/
enum FileTest
{
FILE_TEST_IS_REGULAR = 1 << 0,
FILE_TEST_IS_SYMLINK = 1 << 1,
FILE_TEST_IS_DIR = 1 << 2,
FILE_TEST_IS_EXECUTABLE = 1 << 3,
FILE_TEST_EXISTS = 1 << 4
};
/** @ingroup glibmmEnums */
inline FileTest operator|(FileTest lhs, FileTest rhs)
{ return static_cast<FileTest>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline FileTest operator&(FileTest lhs, FileTest rhs)
{ return static_cast<FileTest>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline FileTest operator^(FileTest lhs, FileTest rhs)
{ return static_cast<FileTest>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline FileTest operator~(FileTest flags)
{ return static_cast<FileTest>(~static_cast<unsigned>(flags)); }
/** @ingroup glibmmEnums */
inline FileTest& operator|=(FileTest& lhs, FileTest rhs)
{ return (lhs = static_cast<FileTest>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline FileTest& operator&=(FileTest& lhs, FileTest rhs)
{ return (lhs = static_cast<FileTest>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline FileTest& operator^=(FileTest& lhs, FileTest rhs)
{ return (lhs = static_cast<FileTest>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
/** @defgroup FileUtils File Utilities
* Various file-related classes and functions.
*/
/** Exception class for file-related errors.
* @ingroup FileUtils
*/
class FileError : public Glib::Error
{
public:
enum Code
{
EXISTS,
IS_DIRECTORY,
ACCESS_DENIED,
NAME_TOO_LONG,
NO_SUCH_ENTITY,
NOT_DIRECTORY,
NO_SUCH_DEVICE,
NOT_DEVICE,
READONLY_FILESYSTEM,
TEXT_FILE_BUSY,
FAULTY_ADDRESS,
SYMLINK_LOOP,
NO_SPACE_LEFT,
NOT_ENOUGH_MEMORY,
TOO_MANY_OPEN_FILES,
FILE_TABLE_OVERFLOW,
BAD_FILE_DESCRIPTOR,
INVALID_ARGUMENT,
BROKEN_PIPE,
TRYAGAIN,
INTERRUPTED,
IO_ERROR,
NOT_OWNER,
NOSYS,
FAILED
};
FileError(Code error_code, const Glib::ustring& error_message);
explicit FileError(GError* gobject);
Code code() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
private:
static void throw_func(GError* gobject);
friend void wrap_init(); // uses throw_func()
#endif
};
/** @enum FileError::Code
* Values corresponding to <tt>errno</tt> codes returned from file operations
* on UNIX.
* Unlike <tt>errno</tt> codes, FileError::Code values are available on all
* systems, even Windows. The exact meaning of each code depends on what sort
* of file operation you were performing; the UNIX documentation gives more
* details. The following error code descriptions come from the GNU C Library
* manual, and are under the copyright of that manual.
*
* It's not very portable to make detailed assumptions about exactly which
* errors will be returned from a given operation. Some errors don't occur on
* some systems, etc., sometimes there are subtle differences in when a system
* will report a given error, etc.
*/
/** @var FileError::Code FileError::EXISTS
* <tt>(EEXIST)</tt> Operation not permitted; only the owner of the file (or
* other resource) or processes with special privileges can perform the operation.
* <br><br>
*/
/** @var FileError::Code FileError::IS_DIRECTORY
* <tt>(EISDIR)</tt> File is a directory; you cannot open a directory for writing,
* or create or remove hard links to it.
* <br><br>
*/
/** @var FileError::Code FileError::ACCESS_DENIED
* <tt>(EACCES)</tt> Permission denied; the file permissions do not allow the
* attempted operation.
* <br><br>
*/
/** @var FileError::Code FileError::NAME_TOO_LONG
* <tt>(ENAMETOOLONG)</tt> Filename too long.
* <br><br>
*/
/** @var FileError::Code FileError::NO_SUCH_ENTITY
* <tt>(ENOENT)</tt> No such file or directory. This is a "file doesn't exist"
* error for ordinary files that are referenced in contexts where they are expected
* to already exist.
* <br><br>
*/
/** @var FileError::Code FileError::NOT_DIRECTORY
* <tt>(ENOTDIR)</tt> A file that isn't a directory was specified when a directory
* is required.
* <br><br>
*/
/** @var FileError::Code FileError::NO_SUCH_DEVICE
* <tt>(ENXIO)</tt> No such device or address. The system tried to use the device
* represented by a file you specified, and it couldn't find the device. This can
* mean that the device file was installed incorrectly, or that the physical device
* is missing or not correctly attached to the computer.
* <br><br>
*/
/** @var FileError::Code FileError::NOT_DEVICE
* <tt>(ENODEV)</tt> This file is of a type that doesn't support mapping.
* <br><br>
*/
/** @var FileError::Code FileError::READONLY_FILESYSTEM
* <tt>(EROFS)</tt> The directory containing the new link can't be modified
* because it's on a read-only file system.
* <br><br>
*/
/** @var FileError::Code FileError::TEXT_FILE_BUSY
* <tt>(ETXTBSY)</tt> Text file busy.
* <br><br>
*/
/** @var FileError::Code FileError::FAULTY_ADDRESS
* <tt>(EFAULT)</tt> You passed in a pointer to bad memory. (Glib won't
* reliably return this, don't pass in pointers to bad memory.)
* <br><br>
*/
/** @var FileError::Code FileError::SYMLINK_LOOP
* <tt>(ELOOP)</tt> Too many levels of symbolic links were encountered in
* looking up a file name. This often indicates a cycle of symbolic links.
* <br><br>
*/
/** @var FileError::Code FileError::NO_SPACE_LEFT
* <tt>(ENOSPC)</tt> No space left on device; write operation on a file failed
* because the disk is full.
* <br><br>
*/
/** @var FileError::Code FileError::NOT_ENOUGH_MEMORY
* <tt>(ENOMEM)</tt> No memory available. The system cannot allocate more
* virtual memory because its capacity is full.
* <br><br>
*/
/** @var FileError::Code FileError::TOO_MANY_OPEN_FILES
* <tt>(EMFILE)</tt> The current process has too many files open and can't
* open any more. Duplicate descriptors do count toward this limit.
* <br><br>
*/
/** @var FileError::Code FileError::FILE_TABLE_OVERFLOW
* <tt>(ENFILE)</tt> There are too many distinct file openings in the
* entire system.
* <br><br>
*/
/** @var FileError::Code FileError::BAD_FILE_DESCRIPTOR
* <tt>(EBADF)</tt> Bad file descriptor; for example, I/O on a descriptor
* that has been closed or reading from a descriptor open only for writing
* (or vice versa).
* <br><br>
*/
/** @var FileError::Code FileError::INVALID_ARGUMENT
* <tt>(EINVAL)</tt> Invalid argument. This is used to indicate various kinds
* of problems with passing the wrong argument to a library function.
* <br><br>
*/
/** @var FileError::Code FileError::BROKEN_PIPE
* <tt>(EPIPE)</tt> Broken pipe; there is no process reading from the other
* end of a pipe. Every library function that returns this error code also
* generates a <tt>SIGPIPE</tt> signal; this signal terminates the program
* if not handled or blocked. Thus, your program will never actually see
* this code unless it has handled or blocked <tt>SIGPIPE</tt>.
* <br><br>
*/
/** @var FileError::Code FileError::TRYAGAIN
* <tt>(EAGAIN)</tt> Resource temporarily unavailable; the call might work
* if you try again later.
* We used TRYAGAIN instead of TRY_AGAIN, because that is a defined as a macro by a Unix header.
* <br><br>
*/
/** @var FileError::Code FileError::INTERRUPTED
* <tt>(EINTR)</tt> Interrupted function call; an asynchronous signal occurred
* and prevented completion of the call. When this happens, you should try
* the call again.
* <br><br>
*/
/** @var FileError::Code FileError::IO_ERROR
* <tt>(EIO)</tt> Input/output error; usually used for physical read or write
* errors. I.e. the disk or other physical device hardware is returning errors.
* <br><br>
*/
/** @var FileError::Code FileError::NOT_OWNER
* <tt>(EPERM)</tt> Operation not permitted; only the owner of the file (or other
* resource) or processes with special privileges can perform the operation.
* <br><br>
*/
/** @var FileError::Code FileError::FAILED
* Does not correspond to a UNIX error code; this is the standard "failed for
* unspecified reason" error code present in all Glib::Error error code
* enumerations. Returned if no specific code applies.
*/
class Dir;
/** The iterator type of Glib::Dir.
* @ingroup FileUtils
*/
class DirIterator
{
public:
typedef std::input_iterator_tag iterator_category;
typedef std::string value_type;
typedef int difference_type;
typedef value_type reference;
typedef void pointer;
DirIterator();
#ifndef DOXYGEN_SHOULD_SKIP_THIS
DirIterator(GDir* gobject, const char* current);
#endif
std::string operator*() const;
DirIterator& operator++();
/** @note DirIterator has input iterator semantics, which means real
* postfix increment is impossible. The return type is @c void to
* prevent surprising behaviour.
*/
void operator++(int);
bool operator==(const DirIterator& rhs) const;
bool operator!=(const DirIterator& rhs) const;
private:
GDir* gobject_;
const char* current_;
};
/** Utility class representing an open directory.
* @ingroup FileUtils
* It's highly recommended to use the iterator interface. With iterators,
* reading an entire directory into a STL container is really easy:
* @code
* Glib::Dir dir (directory_path);
* std::list<std::string> entries (dir.begin(), dir.end());
* @endcode
* @note The encoding of the directory entries isn't necessarily UTF-8.
* Use Glib::filename_to_utf8() if you need to display them.
*/
class Dir
{
public:
typedef DirIterator iterator;
typedef DirIterator const_iterator;
/** Opens a directory for reading. The names of the files in the
* directory can then be retrieved using read_name().
* @param path The path to the directory you are interested in.
* @throw Glib::FileError
*/
explicit Dir(const std::string& path);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
explicit Dir(GDir* gobject);
#endif
/** Closes the directory and deallocates all related resources.
*/
~Dir();
/** Retrieves the name of the next entry in the directory.
* The <tt>'.'</tt> and <tt>'..'</tt> entries are omitted.
* @return The entry's name or <tt>""</tt> if there are no more entries.
* @see begin(), end()
*/
std::string read_name();
/** Resets the directory. The next call to
* read_name() will return the first entry again.
*/
void rewind();
/** Closes the directory and deallocates all related resources.
* Note that close() is implicitely called by ~Dir(). Thus you don't
* need to call close() yourself unless you want to close the directory
* before the destructor runs.
*/
void close();
/** Get the begin of an input iterator sequence.
* @return An input iterator pointing to the first directory entry.
*/
DirIterator begin();
/** Get the end of an input iterator sequence.
* @return An input iterator pointing behind the last directory entry.
*/
DirIterator end();
private:
GDir* gobject_;
// noncopyable
Dir(const Dir&);
Dir& operator=(const Dir&);
};
/** Returns @c true if any of the tests in the bitfield @a test are true.
* @ingroup FileUtils
* For example, <tt>(Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_DIR)</tt> will
* return @c true if the file exists; the check whether it's a directory
* doesn't matter since the existence test is true. With the current set of
* available tests, there's no point passing in more than one test at a time.
*
* Apart from <tt>Glib::FILE_TEST_IS_SYMLINK</tt> all tests follow symbolic
* links, so for a symbolic link to a regular file file_test() will return
* @c true for both <tt>Glib::FILE_TEST_IS_SYMLINK</tt> and
* <tt>Glib::FILE_TEST_IS_REGULAR</tt>.
*
* @note For a dangling symbolic link file_test() will return @c true for
* <tt>Glib::FILE_TEST_IS_SYMLINK</tt> and @c false for all other flags.
*
* @param filename A filename to test.
* @param test Bitfield of Glib::FileTest flags.
* @return Whether a test was true.
*/
bool file_test(const std::string& filename, FileTest test);
/** Opens a temporary file.
* @ingroup FileUtils
* See the %mkstemp() documentation on most UNIX-like systems. This is a
* portability wrapper, which simply calls %mkstemp() on systems that have
* it, and implements it in GLib otherwise.
* @param filename_template A string that should match the rules for
* %mkstemp(), i.e. end in <tt>"XXXXXX"</tt>. The <tt>X</tt> string
* will be modified to form the name of a file that didn't exist.
* @return A file handle (as from open()) to the file opened for reading
* and writing. The file is opened in binary mode on platforms where there
* is a difference. The file handle should be closed with close(). In
* case of errors, <tt>-1</tt> is returned.
*/
int mkstemp(std::string& filename_template);
/** Opens a file for writing in the preferred directory for temporary files
* (as returned by Glib::get_tmp_dir()).
* @ingroup FileUtils
* @a prefix should a basename template; it'll be suffixed by 6 characters
* in order to form a unique filename. No directory components are allowed.
*
* The actual name used is returned in @a name_used.
*
* @param prefix Template for file name, basename only.
* @retval name_used The actual name used.
* @return A file handle (as from <tt>open()</tt>) to the file opened for reading
* and writing. The file is opened in binary mode on platforms where there is a
* difference. The file handle should be closed with <tt>close()</tt>.
* @throw Glib::FileError
*/
int file_open_tmp(std::string& name_used, const std::string& prefix);
/** Opens a file for writing in the preferred directory for temporary files
* (as returned by Glib::get_tmp_dir()).
* @ingroup FileUtils
* This function works like file_open_tmp(std::string&, const std::string&)
* but uses a default basename prefix.
*
* @retval name_used The actual name used.
* @return A file handle (as from <tt>open()</tt>) to the file opened for reading
* and writing. The file is opened in binary mode on platforms where there is a
* difference. The file handle should be closed with <tt>close()</tt>.
* @throw Glib::FileError
*/
int file_open_tmp(std::string& name_used);
/** Reads an entire file into a string, with good error checking.
* @ingroup FileUtils
* @param filename A file to read contents from.
* @return The file contents.
* @throw Glib::FileError
*/
std::string file_get_contents(const std::string& filename);
} // namespace Glib
#endif /* _GLIBMM_FILEUTILS_H */

View file

@ -1,165 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_HELPERLIST_H
#define _GLIBMM_HELPERLIST_H
/* $Id$ */
/* helperlist.h
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/containers.h>
namespace Glib
{
// This class has some pure virtual methods which need to be implemented by derived classes.
template< typename T_Child, typename T_CppElement, typename T_Iterator >
class HelperList
{
public:
HelperList()
: gparent_(0)
{}
HelperList(GObject* gparent)
: gparent_(gparent)
{}
virtual ~HelperList()
{}
typedef T_Child value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef T_Iterator iterator;
typedef List_ConstIterator<iterator> const_iterator;
typedef List_ReverseIterator<iterator> reverse_iterator;
typedef List_ConstIterator<reverse_iterator> const_reverse_iterator;
typedef T_CppElement element_type;
typedef size_t difference_type;
typedef size_t size_type;
//These are implemented differently for each Helper List.
virtual iterator erase(iterator) = 0;
virtual void erase(iterator start, iterator stop)
{
while(start != stop)
start = erase(start); //Implemented in derived class.
}
virtual void remove(const_reference) = 0;
size_type size() const
{
return g_list_length(glist());
}
inline size_type max_size() { return size_type(-1); }
inline bool empty() { return glist() == 0; }
inline iterator begin()
{return begin_();}
inline iterator end()
{return end_();}
inline const_iterator begin() const
{ return const_iterator(begin_()); }
inline const_iterator end() const
{ return const_iterator(end_()); }
inline reverse_iterator rbegin()
{ return reverse_iterator(end_()); }
inline reverse_iterator rend()
{ return reverse_iterator(begin_()); }
inline const_reverse_iterator rbegin() const
{ return const_reverse_iterator(reverse_iterator(end_())); }
inline const_reverse_iterator rend() const
{ return const_reverse_iterator(reverse_iterator(begin_())); }
reference front() const
{
return *begin();
}
reference back() const
{
return *(--end());
}
reference operator[](size_type l) const
{
size_type j = 0;
iterator i;
for(i = begin(), j = 0; i != end(), j < l; ++i, ++j);
return (*i);
}
// iterator find(const_reference w)
// {
// iterator i = begin();
// for(i = begin(); i != end() && (*i != w); i++);
// return i;
// }
//
// iterator find(Widget& w)
// {
// iterator i;
// for (i = begin(); i != end() && ((*i)->$1() != &w); i++);
// return i;
// }
//Derived classes might choose to reimplement these as public:
inline void pop_front()
{ erase(begin()); }
inline void pop_back()
{ erase(--end()); }
void clear()
{ erase(begin(), end()); }
GObject* gparent()
{ return gparent_; };
const GObject* gparent() const
{ return gparent_; };
protected:
virtual GList*& glist() const = 0; // front of list
iterator begin_() const
{
return iterator(glist(), glist());
}
iterator end_() const
{
return iterator(glist(), (GList*)0);
}
GObject* gparent_;
};
} /* namespace Glib */
#endif /* _GLIBMM_HELPERLIST_H */

View file

@ -1,30 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_I18N_H
#define _GLIBMM_I18N_H
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
// Include this file to define internationalization macros such as _().
// This file must be included by the application, after system headers such as <iostream>.
#include <glib/gi18n.h>
#endif /* _GLIBMM_I18N_H */

View file

@ -1,34 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2003 The glibmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/wrap.h>
#include <glibmm/error.h>
namespace Glib
{
void init()
{
Glib::wrap_register_init();
Glib::Error::register_init(); //also calls Glib::wrap_init();
}
} // namespace Glib

View file

@ -1,39 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_INIT_H
#define _GLIBMM_INIT_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
namespace Glib
{
/** Initialize glibmm.
* You may call this more than once.
* You do nott need to call this if you are using Glib::MainLoop or Gtk::Main,
* because they call it for you.
*/
void init();
} // namespace Glib
#endif /* _GLIBMM_INIT_H */

View file

@ -1,95 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/interface.h>
#include <glibmm/private/interface_p.h>
namespace Glib
{
/**** Glib::Interface_Class ************************************************/
void Interface_Class::add_interface(GType instance_type) const
{
//This check is distabled, because it checks whether any of the types's bases implement the interface, not just the specific type.
//if( !g_type_is_a(instance_type, gtype_) ) //For convenience, don't complain about calling this twice.
//{
const GInterfaceInfo interface_info =
{
class_init_func_,
0, // interface_finalize
0, // interface_data
};
g_type_add_interface_static(instance_type, gtype_, &interface_info);
//}
}
/**** Interface Glib::Interface ********************************************/
Interface::Interface(const Interface_Class& interface_class)
{
//gobject_ will be set in the Object constructor.
//Any instantiable class that derives from Interface should also inherit from Object.
// If I understand it correctly, gobject_ shouldn't be 0 now. daniel.
// TODO: Make this a g_assert() if the assumption above is correct.
g_return_if_fail(gobject_ != 0);
if(custom_type_name_ && !is_anonymous_custom_())
{
void *const instance_class = G_OBJECT_GET_CLASS(gobject_);
if(!g_type_interface_peek(instance_class, interface_class.get_type()))
{
interface_class.add_interface(G_OBJECT_CLASS_TYPE(instance_class));
}
}
}
Interface::Interface(GObject* castitem)
{
// Connect GObject and wrapper instances.
ObjectBase::initialize(castitem);
}
Interface::~Interface()
{}
GType Interface::get_type()
{
return G_TYPE_INTERFACE;
}
GType Interface::get_base_type()
{
return G_TYPE_INTERFACE;
}
RefPtr<ObjectBase> wrap_interface(GObject* object, bool take_copy)
{
return Glib::RefPtr<ObjectBase>( wrap_auto(object, take_copy) );
}
} // namespace Glib

View file

@ -1,72 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_INTERFACE_H
#define _GLIBMM_INTERFACE_H
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/object.h>
namespace Glib
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
class Interface_Class;
#endif
// There is no base GInterface struct in Glib, though there is G_TYPE_INTERFACE enum value.
class Interface : virtual public Glib::ObjectBase
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef Interface CppObjectType;
typedef Interface_Class CppClassType;
typedef GTypeInterface BaseClassType;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
explicit Interface(const Glib::Interface_Class& interface_class);
explicit Interface(GObject* castitem);
virtual ~Interface();
//void add_interface(GType gtype_implementer);
// Hook for translating API
//static Glib::Interface* wrap_new(GTypeInterface*);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
static GType get_type() G_GNUC_CONST;
static GType get_base_type() G_GNUC_CONST;
#endif
inline GObject* gobj() { return gobject_; }
inline const GObject* gobj() const { return gobject_; }
private:
// noncopyable
Interface(const Interface&);
Interface& operator=(const Interface&);
};
RefPtr<ObjectBase> wrap_interface(GObject* object, bool take_copy = false);
} // namespace Glib
#endif /* _GLIBMM_INTERFACE_H */

View file

@ -1,687 +0,0 @@
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <glibmm/iochannel.h>
#include <glibmm/private/iochannel_p.h>
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/exceptionhandler.h>
#include <glibmm/iochannel.h>
#include <glibmm/utility.h>
#include <glibmm/main.h>
#include <glib.h>
namespace
{
// Glib::IOChannel reference counting issues:
//
// Normally, you'd expect that the C++ object stays around as long as the
// C instance does. Also Glib::wrap() usually returns always the same C++
// wrapper object for a single C instance.
//
// Unfortunately it isn't possible to implement these features if we didn't
// create the underlying GIOChannel. That is, when wrapping existing
// GIOChannel instances such as returned by e.g. g_io_channel_unix_new() or
// g_io_channel_new_file(). Neither is there a way to hook up a wrapper
// object in an existing GIOChannel, nor exists any destroy notification.
//
// So that means: If the IOChannel is implemented in C++ -- that is, our
// GlibmmIOChannel backend is used -- we use the GIOChannel reference
// counting mechanism. If the IOChannel backend is unknown, then the
// wrapper instance holds always exactly one reference to the GIOChannel.
// The wrapper object itself is then managed via our own refcounting
// mechanism. To do that a utility class ForeignIOChannel is introduced to
// override reference() and unreference().
class ForeignIOChannel : public Glib::IOChannel
{
public:
ForeignIOChannel(GIOChannel* gobject, bool take_copy)
: Glib::IOChannel(gobject, take_copy), ref_count_(0) {}
virtual void reference() const;
virtual void unreference() const;
private:
mutable int ref_count_;
};
void ForeignIOChannel::reference() const
{
++ref_count_;
}
void ForeignIOChannel::unreference() const
{
if (!(--ref_count_)) delete this;
}
} // anonymous namespace
namespace Glib
{
class GlibmmIOChannel
{
public:
GIOChannel base;
Glib::IOChannel* wrapper;
static const GIOFuncs vfunc_table;
static GIOStatus io_read(GIOChannel* channel, char* buf, gsize count,
gsize* bytes_read, GError** err);
static GIOStatus io_write(GIOChannel* channel, const char* buf, gsize count,
gsize* bytes_written, GError** err);
static GIOStatus io_seek (GIOChannel* channel, gint64 offset, GSeekType type, GError** err);
static GIOStatus io_close(GIOChannel* channel, GError** err);
static GSource* io_create_watch(GIOChannel* channel, GIOCondition condition);
static void io_free(GIOChannel* channel);
static GIOStatus io_set_flags(GIOChannel* channel, GIOFlags flags, GError** err);
static GIOFlags io_get_flags(GIOChannel* channel);
};
// static
const GIOFuncs GlibmmIOChannel::vfunc_table =
{
&GlibmmIOChannel::io_read,
&GlibmmIOChannel::io_write,
&GlibmmIOChannel::io_seek,
&GlibmmIOChannel::io_close,
&GlibmmIOChannel::io_create_watch,
&GlibmmIOChannel::io_free,
&GlibmmIOChannel::io_set_flags,
&GlibmmIOChannel::io_get_flags,
};
/**** GLib::IOChannel ******************************************************/
/* Construct a custom C++-implemented IOChannel. GlibmmIOChannel is an
* extended GIOChannel struct which allows us to hook up a pointer to this
* persistent wrapper instance.
*/
IOChannel::IOChannel()
:
gobject_ (static_cast<GIOChannel*>(g_malloc(sizeof(GlibmmIOChannel))))
{
g_io_channel_init(gobject_);
gobject_->funcs = const_cast<GIOFuncs*>(&GlibmmIOChannel::vfunc_table);
reinterpret_cast<GlibmmIOChannel*>(gobject_)->wrapper = this;
}
/* Construct an IOChannel wrapper for an already created GIOChannel.
* See the comment at the top of this file for an explanation of the
* problems with this approach.
*/
IOChannel::IOChannel(GIOChannel* gobject, bool take_copy)
:
gobject_ (gobject)
{
// This ctor should never be called for GlibmmIOChannel instances.
g_assert(gobject != 0);
g_assert(gobject->funcs != &GlibmmIOChannel::vfunc_table);
if(take_copy)
g_io_channel_ref(gobject_);
}
IOChannel::~IOChannel()
{
if(gobject_)
{
// Check whether this IOChannel is implemented in C++, i.e. whether it
// uses our GlibmmIOChannel forwarding backend. Normally, this will never
// be true because the wrapper should only be deleted in the io_free()
// callback, which clears gobject_ before deleting. But in case the ctor
// of a derived class threw an exception the GIOChannel must be destroyed
// prematurely.
//
if(gobject_->funcs == &GlibmmIOChannel::vfunc_table)
{
// Disconnect the wrapper object so that it won't be deleted twice.
reinterpret_cast<GlibmmIOChannel*>(gobject_)->wrapper = 0;
}
GIOChannel *const tmp_gobject = gobject_;
gobject_ = 0;
g_io_channel_unref(tmp_gobject);
}
}
Glib::RefPtr<IOChannel> IOChannel::create_from_file(const std::string& filename, const std::string& mode)
{
GError* error = 0;
GIOChannel *const channel = g_io_channel_new_file(filename.c_str(), mode.c_str(), &error);
if(error)
Glib::Error::throw_exception(error);
return Glib::wrap(channel, false);
}
Glib::RefPtr<IOChannel> IOChannel::create_from_fd(int fd)
{
return Glib::wrap(g_io_channel_unix_new(fd), false);
}
#ifdef G_OS_WIN32
Glib::RefPtr<IOChannel> IOChannel::create_from_win32_fd(int fd)
{
return Glib::wrap(g_io_channel_win32_new_fd(fd), false);
}
Glib::RefPtr<IOChannel> IOChannel::create_from_win32_socket(int socket)
{
return Glib::wrap(g_io_channel_win32_new_socket(socket), false);
}
#endif /* G_OS_WIN32 */
IOStatus IOChannel::write(const Glib::ustring& str)
{
gsize bytes_written = 0;
return write(str.data(), str.bytes(), bytes_written);
}
IOStatus IOChannel::read_line(Glib::ustring& line)
{
Glib::ScopedPtr<char> buf;
GError* error = 0;
gsize bytes = 0;
const GIOStatus status = g_io_channel_read_line(gobj(), buf.addr(), &bytes, 0, &error);
if(error)
Glib::Error::throw_exception(error);
if(buf.get())
line.assign(buf.get(), buf.get() + bytes);
else
line.erase();
return (IOStatus) status;
}
IOStatus IOChannel::read_to_end(Glib::ustring& str)
{
Glib::ScopedPtr<char> buf;
GError* error = 0;
gsize bytes = 0;
const GIOStatus status = g_io_channel_read_to_end(gobj(), buf.addr(), &bytes, &error);
if(error)
Glib::Error::throw_exception(error);
if(buf.get())
str.assign(buf.get(), buf.get() + bytes);
else
str.erase();
return (IOStatus) status;
}
IOStatus IOChannel::read(Glib::ustring& str, gsize count)
{
Glib::ScopedPtr<char> buf (g_new(char, count));
GError* error = 0;
gsize bytes = 0;
const GIOStatus status = g_io_channel_read_chars(gobj(), buf.get(), count, &bytes, &error);
if(error)
Glib::Error::throw_exception(error);
if(buf.get())
str.assign(buf.get(), buf.get() + bytes);
else
str.erase();
return (IOStatus) status;
}
IOStatus IOChannel::set_encoding(const std::string& encoding)
{
GError* error = 0;
const GIOStatus status = g_io_channel_set_encoding(
gobj(), (encoding.empty()) ? 0 : encoding.c_str(), &error);
if(error)
Glib::Error::throw_exception(error);
return (IOStatus) status;
}
std::string IOChannel::get_encoding() const
{
const char *const encoding = g_io_channel_get_encoding(gobject_);
return (encoding) ? std::string(encoding) : std::string();
}
void IOChannel::set_line_term(const std::string& term)
{
if(term.empty())
g_io_channel_set_line_term(gobj(), 0, 0);
else
g_io_channel_set_line_term(gobj(), term.data(), term.size());
}
std::string IOChannel::get_line_term() const
{
int len = 0;
const char *const term = g_io_channel_get_line_term(gobject_, &len);
return (term) ? std::string(term, len) : std::string();
}
Glib::RefPtr<IOSource> IOChannel::create_watch(IOCondition condition)
{
// The corresponding unreference() takes place in the dtor
// of the Glib::RefPtr<IOChannel> object below.
reference();
return IOSource::create(Glib::RefPtr<IOChannel>(this), condition);
}
IOStatus IOChannel::read_vfunc(char*, gsize, gsize&)
{
g_assert_not_reached();
return IO_STATUS_ERROR;
}
IOStatus IOChannel::write_vfunc(const char*, gsize, gsize&)
{
g_assert_not_reached();
return IO_STATUS_ERROR;
}
IOStatus IOChannel::seek_vfunc(gint64, SeekType)
{
g_assert_not_reached();
return IO_STATUS_ERROR;
}
IOStatus IOChannel::close_vfunc()
{
g_assert_not_reached();
return IO_STATUS_ERROR;
}
Glib::RefPtr<Glib::Source> IOChannel::create_watch_vfunc(IOCondition)
{
g_assert_not_reached();
return Glib::RefPtr<Glib::Source>();
}
IOStatus IOChannel::set_flags_vfunc(IOFlags)
{
g_assert_not_reached();
return IO_STATUS_ERROR;
}
IOFlags IOChannel::get_flags_vfunc()
{
g_assert_not_reached();
return IOFlags(0);
}
void IOChannel::reference() const
{
g_io_channel_ref(gobject_);
}
void IOChannel::unreference() const
{
g_io_channel_unref(gobject_);
}
Glib::RefPtr<IOChannel> wrap(GIOChannel* gobject, bool take_copy)
{
IOChannel* cpp_object = 0;
if(gobject)
{
if(gobject->funcs == &GlibmmIOChannel::vfunc_table)
{
cpp_object = reinterpret_cast<GlibmmIOChannel*>(gobject)->wrapper;
if(take_copy && cpp_object)
cpp_object->reference();
}
else
{
cpp_object = new ForeignIOChannel(gobject, take_copy);
cpp_object->reference(); // the refcount is initially 0
}
}
return Glib::RefPtr<IOChannel>(cpp_object);
}
/**** Glib::GlibmmIOChannel ************************************************/
// static
GIOStatus GlibmmIOChannel::io_read(GIOChannel* channel, char* buf, gsize count,
gsize* bytes_read, GError** err)
{
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
try
{
return (GIOStatus) wrapper->read_vfunc(buf, count, *bytes_read);
}
catch(Glib::Error& error)
{
error.propagate(err);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return G_IO_STATUS_ERROR;
}
// static
GIOStatus GlibmmIOChannel::io_write(GIOChannel* channel, const char* buf, gsize count,
gsize* bytes_written, GError** err)
{
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
try
{
return (GIOStatus) wrapper->write_vfunc(buf, count, *bytes_written);
}
catch(Glib::Error& error)
{
error.propagate(err);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return G_IO_STATUS_ERROR;
}
// static
GIOStatus GlibmmIOChannel::io_seek(GIOChannel* channel, gint64 offset, GSeekType type, GError** err)
{
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
try
{
return (GIOStatus) wrapper->seek_vfunc(offset, (SeekType) type);
}
catch(Glib::Error& error)
{
error.propagate(err);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return G_IO_STATUS_ERROR;
}
// static
GIOStatus GlibmmIOChannel::io_close(GIOChannel* channel, GError** err)
{
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
try
{
return (GIOStatus) wrapper->close_vfunc();
}
catch(Glib::Error& error)
{
error.propagate(err);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return G_IO_STATUS_ERROR;
}
// static
GSource* GlibmmIOChannel::io_create_watch(GIOChannel* channel, GIOCondition condition)
{
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
try
{
const Glib::RefPtr<Source> source = wrapper->create_watch_vfunc((IOCondition) condition);
return (source) ? source->gobj_copy() : 0;
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return 0;
}
// static
void GlibmmIOChannel::io_free(GIOChannel* channel)
{
if(IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper)
{
wrapper->gobject_ = 0;
delete wrapper;
}
g_free(channel);
}
// static
GIOStatus GlibmmIOChannel::io_set_flags(GIOChannel* channel, GIOFlags flags, GError** err)
{
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
try
{
return (GIOStatus) wrapper->set_flags_vfunc((IOFlags) flags);
}
catch(Glib::Error& error)
{
error.propagate(err);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return G_IO_STATUS_ERROR;
}
// static
GIOFlags GlibmmIOChannel::io_get_flags(GIOChannel* channel)
{
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
try
{
return (GIOFlags) wrapper->get_flags_vfunc();
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return GIOFlags(0);
}
} // namespace Glib
namespace
{
} // anonymous namespace
Glib::IOChannelError::IOChannelError(Glib::IOChannelError::Code error_code, const Glib::ustring& error_message)
:
Glib::Error (G_IO_CHANNEL_ERROR, error_code, error_message)
{}
Glib::IOChannelError::IOChannelError(GError* gobject)
:
Glib::Error (gobject)
{}
Glib::IOChannelError::Code Glib::IOChannelError::code() const
{
return static_cast<Code>(Glib::Error::code());
}
void Glib::IOChannelError::throw_func(GError* gobject)
{
throw Glib::IOChannelError(gobject);
}
namespace Glib
{
IOStatus IOChannel::read(gunichar& unichar)
{
GError *error = 0;
IOStatus retvalue = ((IOStatus)(g_io_channel_read_unichar(gobj(), &(unichar), &(error))));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
IOStatus IOChannel::read(char* buf, gsize count, gsize& bytes_read)
{
GError *error = 0;
IOStatus retvalue = ((IOStatus)(g_io_channel_read_chars(gobj(), buf, count, &(bytes_read), &(error))));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
IOStatus IOChannel::write(const char* buf, gssize count, gsize& bytes_written)
{
GError *error = 0;
IOStatus retvalue = ((IOStatus)(g_io_channel_write_chars(gobj(), buf, count, &(bytes_written), &(error))));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
IOStatus IOChannel::write(gunichar unichar)
{
GError *error = 0;
IOStatus retvalue = ((IOStatus)(g_io_channel_write_unichar(gobj(), unichar, &(error))));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
IOStatus IOChannel::seek(gint64 offset, SeekType type)
{
GError *error = 0;
IOStatus retvalue = ((IOStatus)(g_io_channel_seek_position(gobj(), offset, ((GSeekType)(type)), &(error))));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
IOStatus IOChannel::flush()
{
GError *error = 0;
IOStatus retvalue = ((IOStatus)(g_io_channel_flush(gobj(), &(error))));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
IOStatus IOChannel::close(bool flush)
{
GError *error = 0;
IOStatus retvalue = ((IOStatus)(g_io_channel_shutdown(gobj(), static_cast<int>(flush), &(error))));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
gsize IOChannel::get_buffer_size() const
{
return g_io_channel_get_buffer_size(const_cast<GIOChannel*>(gobj()));
}
void IOChannel::set_buffer_size(gsize size)
{
g_io_channel_set_buffer_size(gobj(), size);
}
IOFlags IOChannel::get_flags() const
{
return ((IOFlags)(g_io_channel_get_flags(const_cast<GIOChannel*>(gobj()))));
}
IOStatus IOChannel::set_flags(IOFlags flags)
{
GError *error = 0;
IOStatus retvalue = ((IOStatus)(g_io_channel_set_flags(gobj(), ((GIOFlags)(flags)), &(error))));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
void IOChannel::set_buffered(bool buffered)
{
g_io_channel_set_buffered(gobj(), static_cast<int>(buffered));
}
bool IOChannel::get_buffered() const
{
return g_io_channel_get_buffered(const_cast<GIOChannel*>(gobj()));
}
IOCondition IOChannel::get_buffer_condition() const
{
return ((IOCondition)(g_io_channel_get_buffer_condition(const_cast<GIOChannel*>(gobj()))));
}
bool IOChannel::get_close_on_unref() const
{
return g_io_channel_get_close_on_unref(const_cast<GIOChannel*>(gobj()));
}
void IOChannel::set_close_on_unref(bool do_close)
{
g_io_channel_set_close_on_unref(gobj(), static_cast<int>(do_close));
}
} // namespace Glib

View file

@ -1,695 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_IOCHANNEL_H
#define _GLIBMM_IOCHANNEL_H
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/error.h>
#include <glibmm/main.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <glib/gtypes.h>
#include <string>
#include <glibmmconfig.h>
GLIBMM_USING_STD(string)
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GIOChannel GIOChannel; }
#endif
namespace Glib
{
class Source;
class IOSource;
/** @addtogroup glibmmEnums Enums and Flags */
/**
* @ingroup glibmmEnums
*/
enum SeekType
{
SEEK_TYPE_CUR,
SEEK_TYPE_SET,
SEEK_TYPE_END
};
/**
* @ingroup glibmmEnums
*/
enum IOStatus
{
IO_STATUS_ERROR,
IO_STATUS_NORMAL,
IO_STATUS_EOF,
IO_STATUS_AGAIN
};
/**
* @ingroup glibmmEnums
* @par Bitwise operators:
* <tt>%IOFlags operator|(IOFlags, IOFlags)</tt><br>
* <tt>%IOFlags operator&(IOFlags, IOFlags)</tt><br>
* <tt>%IOFlags operator^(IOFlags, IOFlags)</tt><br>
* <tt>%IOFlags operator~(IOFlags)</tt><br>
* <tt>%IOFlags& operator|=(IOFlags&, IOFlags)</tt><br>
* <tt>%IOFlags& operator&=(IOFlags&, IOFlags)</tt><br>
* <tt>%IOFlags& operator^=(IOFlags&, IOFlags)</tt><br>
*/
enum IOFlags
{
IO_FLAG_APPEND = 1 << 0,
IO_FLAG_NONBLOCK = 1 << 1,
IO_FLAG_IS_READABLE = 1 << 2,
IO_FLAG_IS_WRITEABLE = 1 << 3,
IO_FLAG_IS_SEEKABLE = 1 << 4,
IO_FLAG_GET_MASK = 0x0,
IO_FLAG_SET_MASK = 0x1
};
/** @ingroup glibmmEnums */
inline IOFlags operator|(IOFlags lhs, IOFlags rhs)
{ return static_cast<IOFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline IOFlags operator&(IOFlags lhs, IOFlags rhs)
{ return static_cast<IOFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline IOFlags operator^(IOFlags lhs, IOFlags rhs)
{ return static_cast<IOFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline IOFlags operator~(IOFlags flags)
{ return static_cast<IOFlags>(~static_cast<unsigned>(flags)); }
/** @ingroup glibmmEnums */
inline IOFlags& operator|=(IOFlags& lhs, IOFlags rhs)
{ return (lhs = static_cast<IOFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline IOFlags& operator&=(IOFlags& lhs, IOFlags rhs)
{ return (lhs = static_cast<IOFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline IOFlags& operator^=(IOFlags& lhs, IOFlags rhs)
{ return (lhs = static_cast<IOFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
/** Exception class for IOChannel errors.
*/
class IOChannelError : public Glib::Error
{
public:
enum Code
{
FILE_TOO_BIG,
INVALID_ARGUMENT,
IO_ERROR,
IS_DIRECTORY,
NO_SPACE_LEFT,
NO_SUCH_DEVICE,
OVERFLOWN,
BROKEN_PIPE,
FAILED
};
IOChannelError(Code error_code, const Glib::ustring& error_message);
explicit IOChannelError(GError* gobject);
Code code() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
private:
static void throw_func(GError* gobject);
friend void wrap_init(); // uses throw_func()
#endif
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS
class GlibmmIOChannel;
#endif
/** IOChannel aims to provide portable I/O support for files, pipes
* and sockets, and to integrate them with the GLib main event loop.
*
* Note that IOChannels implement an automatic implicit character set
* conversion to the data stream, and usually will not pass by default
* binary data unchanged. To set the encoding of the channel, use e.g.
* set_encoding("ISO-8859-15"). To set the channel to no encoding, use
* set_encoding() without any arguments.
*
* You can create an IOChannel with one of the static create methods, or
* implement one yourself, in which case you have to 1)&nbsp;override all
* _vfunc() members. 2)&nbsp;set the GIOChannel flags in your constructor.
*
* @note This feature of being able to implement a custom Glib::IOChannel is
* deprecated in glibmm&nbsp;2.2. The vfunc interface has not yet stabilized
* enough to allow that -- the C++ wrapper went in by pure accident. Besides,
* it isn't terribly useful either. Thus please refrain from overriding any
* IOChannel vfuncs.
*/
class IOChannel : public sigc::trackable
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef IOChannel CppObjectType;
typedef GIOChannel BaseObjectType;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
private:
public:
virtual ~IOChannel();
/** Open a file @a filename as an I/O channel using mode @a mode.
* This channel will be closed when the last reference to it is dropped,
* so there is no need to call close() (though doing so will not cause
* problems, as long as no attempt is made to access the channel after
* it is closed).
* @param filename The name of the file to open.
* @param mode One of <tt>"r"</tt>, <tt>"w"</tt>, <tt>"a"</tt>,
* <tt>"r+"</tt>, <tt>"w+"</tt>, <tt>"a+"</tt>. These have the
* same meaning as in <tt>fopen()</tt>.
* @return An IOChannel for the opened file.
* @throw Glib::FileError
*/
static Glib::RefPtr<IOChannel> create_from_file(const std::string& filename, const std::string& mode);
/** Creates an I/O channel from a file descriptor.
* On Unix, IOChannels created with this function work for any file
* descriptor or socket.
*
* On Win32, this can be used either for files opened with the MSVCRT (the
* Microsoft run-time C library) <tt>_open()</tt> or <tt>_pipe()</tt>,
* including file descriptors 0, 1 and 2 (corresponding to <tt>stdin</tt>,
* <tt>stdout</tt> and <tt>stderr</tt>), or for Winsock <tt>SOCKET</tt>s. If
* the parameter is a legal file descriptor, it is assumed to be such,
* otherwise it should be a <tt>SOCKET</tt>. This relies on <tt>SOCKET</tt>s
* and file descriptors not overlapping. If you want to be certain, call
* either create_from_win32_fd() or create_from_win32_socket() instead as
* appropriate.
*
* The term file descriptor as used in the context of Win32 refers to the
* emulated Unix-like file descriptors MSVCRT provides. The native
* corresponding concept is file <tt>HANDLE</tt>. There isn't as of yet
* a way to get IOChannels for Win32 file <tt>HANDLE</tt>s.
*/
static Glib::RefPtr<IOChannel> create_from_fd(int fd);
/* defined(DOXYGEN_SHOULD_SKIP_THIS) actually does the opposite of what it looks like... */
#if defined(G_OS_WIN32) || defined(DOXYGEN_SHOULD_SKIP_THIS)
/** Create an I/O channel for C runtime (emulated Unix-like) file descriptors.
* After calling add_watch() on a I/O channel returned by this function, you
* shouldn't call read() on the file descriptor. This is because adding
* polling for a file descriptor is implemented on Win32 by starting a thread
* that sits blocked in a <tt>%read()</tt> from the file descriptor most of
* the time. All reads from the file descriptor should be done by this
* internal GLib thread. Your code should call only IOChannel::read().
*/
static Glib::RefPtr<IOChannel> create_from_win32_fd(int fd);
/** Create an I/O channel for a winsock socket. The parameter should be a
* <tt>SOCKET</tt>. Contrary to I/O channels for file descriptors (on Win32),
* you can use normal <tt>recv()</tt> or <tt>recvfrom()</tt> on sockets even
* if GLib is polling them.
*/
static Glib::RefPtr<IOChannel> create_from_win32_socket(int socket);
#endif /* defined(G_OS_WIN32) || defined(DOXYGEN_SHOULD_SKIP_THIS) */
/** Read a single UCS-4 character.
* @retval unichar The Unicode character.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
/** This function cannot be called on a channel with <tt>0</tt> encoding.
* @param thechar A location to return a character.
* @param error A location to return an error of type G::ConvertError
* or G::IOChannelError.
* @return A G::IOStatus.
*/
IOStatus read(gunichar& unichar);
/** Read a character sequence into memory.
* @param buf A buffer to read data into.
* @param count The size of the buffer in bytes. Note that the buffer may
* not be complelely filled even if there is data in the buffer if the
* remaining data is not a complete character.
* @retval bytes_read The number of bytes read. This may be zero even on
* success if @a count < 6 and the channel's encoding is not <tt>""</tt>.
* This indicates that the next UTF-8 character is too wide for the buffer.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
/** Replacement for g_io_channel_read() with the new API.
* @param buf A buffer to read data into.
* @param count The size of the buffer. Note that the buffer may
* not be complelely filled even if there is data
* in the buffer if the remaining data is not a
* complete character.
* @param bytes_read The number of bytes read. This may be zero even on
* success if count &lt; 6 and the channel's encoding is non-<tt>0</tt>.
* This indicates that the next UTF-8 character is too wide for
* the buffer.
* @param error A location to return an error of type G::ConvertError
* or G::IOChannelError.
* @return The status of the operation.
*/
IOStatus read(char* buf, gsize count, gsize& bytes_read);
/** Read a maximum of @a count bytes into @a str.
* @param count The maximum number of bytes to read.
* @retval str The characters that have been read.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
IOStatus read(Glib::ustring& str, gsize count);
/** Read a whole line.
* Reads until the line separator is found, which is included
* in the result string.
* @retval line The line that was read.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
IOStatus read_line(Glib::ustring& line);
/** Reads all the remaining data from the file.
* @retval str The resulting string.
* @return Glib::IO_STATUS_NORMAL on success. This function never
* returns Glib::IO_STATUS_EOF.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
IOStatus read_to_end(Glib::ustring& str);
/** Write a string to the I/O channel.
* Note that this method does not return the number of characters written.
* If the channel is blocking and the returned value is
* Glib::IO_STATUS_NORMAL, the whole string was written.
* @param str the string to write.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
IOStatus write(const Glib::ustring& str);
/** Write a memory area of @a count bytes to the I/O channel.
* @param buf The start of the memory area.
* @param count The number of bytes to write.
* @retval bytes_written The number of bytes written to the channel.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
/** Replacement for g_io_channel_write() with the new API.
*
* On seekable channels with encodings other than <tt>0</tt> or UTF-8, generic
* mixing of reading and writing is not allowed. A call to g_io_channel_write_chars()
* may only be made on a channel from which data has been read in the
* cases described in the documentation for g_io_channel_set_encoding().
* @param buf A buffer to write data from.
* @param count The size of the buffer. If -1, the buffer
* is taken to be a nul-terminated string.
* @param bytes_written The number of bytes written. This can be nonzero
* even if the return value is not G::IO_STATUS_NORMAL.
* If the return value is G::IO_STATUS_NORMAL and the
* channel is blocking, this will always be equal
* to @a count if @a count &gt;= 0.
* @param error A location to return an error of type G::ConvertError
* or G::IOChannelError.
* @return The status of the operation.
*/
IOStatus write(const char* buf, gssize count, gsize& bytes_written);
/** Write a single UCS-4 character to the I/O channel.
* @param unichar The character to write.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
/** This function cannot be called on a channel with <tt>0</tt> encoding.
* @param thechar A character.
* @param error A location to return an error of type G::ConvertError
* or G::IOChannelError.
* @return A G::IOStatus.
*/
IOStatus write(gunichar unichar);
/** Seek the I/O channel to a specific position.
* @param offset The offset in bytes from the position specified by @a type.
* @param type A SeekType. The type Glib::SEEK_TYPE_CUR is only allowed in
* those cases where a call to set_encoding() is allowed. See the
* documentation for set_encoding() for details.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
/** Replacement for g_io_channel_seek() with the new API.
* @param offset The offset in bytes from the position specified by @a type .
* @param type A G::SeekType. The type G::SEEK_CUR is only allowed in those
* cases where a call to g_io_channel_set_encoding()
* is allowed. See the documentation for
* g_io_channel_set_encoding() for details.
* @param error A location to return an error of type G::IOChannelError.
* @return The status of the operation.
*/
IOStatus seek(gint64 offset, SeekType type = SEEK_TYPE_SET);
/** Flush the buffers of the I/O channel.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
/** Flushes the write buffer for the GIOChannel.
* @param error Location to store an error of type G::IOChannelError.
* @return The status of the operation: One of
* G::IO_CHANNEL_NORMAL, G::IO_CHANNEL_AGAIN, or
* G::IO_CHANNEL_ERROR.
*/
IOStatus flush();
/** Close the I/O channel.
* Any pending data to be written will be flushed if @a flush is <tt>true</tt>.
* The channel will not be freed until the last reference is dropped.
* Accessing the channel after closing it is considered an error.
* @param flush Whether to flush() pending data before closing the channel.
* @return The status of the operation.
* @throw Glib::IOChannelError
*/
/** Close an IO channel. Any pending data to be written will be
* flushed if @a flush is <tt>true</tt>. The channel will not be freed until the
* last reference is dropped using g_io_channel_unref().
* @param flush If <tt>true</tt>, flush pending.
* @param err Location to store a G::IOChannelError.
* @return The status of the operation.
*/
IOStatus close(bool flush = true);
/** Get the IOChannel internal buffer size.
* @return The buffer size.
*/
/** Gets the buffer size.
* @return The size of the buffer.
*/
gsize get_buffer_size() const;
/** Set the internal IOChannel buffer size.
* @param size The buffer size the IOChannel should use.
*/
/** Sets the buffer size.
* @param size The size of the buffer. 0 == pick a good size.
*/
void set_buffer_size(gsize size);
/** Get the current flags for a IOChannel, including read-only
* flags such as Glib::IO_FLAG_IS_READABLE.
*
* The values of the flags Glib::IO_FLAG_IS_READABLE and
* Glib::IO_FLAG_IS_WRITEABLE are cached for internal use by the channel when
* it is created. If they should change at some later point (e.g. partial
* shutdown of a socket with the UNIX <tt>shutdown()</tt> function), the user
* should immediately call get_flags() to update the internal values of these
* flags.
* @return Bitwise combination of the flags set on the channel.
*/
/** Gets the current flags for a G::IOChannel, including read-only
* flags such as G::IO_FLAG_IS_READABLE.
*
* The values of the flags G::IO_FLAG_IS_READABLE and G::IO_FLAG_IS_WRITEABLE
* are cached for internal use by the channel when it is created.
* If they should change at some later point (e.g. partial shutdown
* of a socket with the UNIX shutdown() function), the user
* should immediately call g_io_channel_get_flags() to update
* the internal values of these flags.
* @return The flags which are set on the channel.
*/
IOFlags get_flags() const;
/** Set flags on the IOChannel.
* @param flags Bitwise combination of the flags to set.
* @return The operation result code.
* @throw Glib::IOChannelError
*/
/** Sets the (writeable) flags in @a channel to ( @a flags & G::IO_CHANNEL_SET_MASK).
* @param flags The flags to set on the IO channel.
* @param error A location to return an error of type G::IOChannelError.
* @return The status of the operation.
*/
IOStatus set_flags(IOFlags flags);
/** Set the buffering status of the I/O channel.
* The buffering state can only be set if the channel's encoding is
* <tt>""</tt>. For any other encoding, the channel must be buffered.
*
* A buffered channel can only be set unbuffered if the channel's internal
* buffers have been flushed. Newly created channels or channels which have
* returned Glib::IO_STATUS_EOF not require such a flush. For write-only
* channels, a call to flush() is sufficient. For all other channels, the
* buffers may be flushed by a call to seek(). This includes the possibility
* of seeking with seek type Glib::SEEK_TYPE_CUR and an offset of zero. Note
* that this means that socket-based channels cannot be set unbuffered once
* they have had data read from them.
*
* The default state of the channel is buffered.
*
* @param buffered Whether to set the channel buffered or unbuffered.
*/
/** The buffering state can only be set if the channel's encoding
* is <tt>0</tt>. For any other encoding, the channel must be buffered.
*
* A buffered channel can only be set unbuffered if the channel's
* internal buffers have been flushed. Newly created channels or
* channels which have returned G::IO_STATUS_EOF
* not require such a flush. For write-only channels, a call to
* g_io_channel_flush() is sufficient. For all other channels,
* the buffers may be flushed by a call to g_io_channel_seek_position().
* This includes the possibility of seeking with seek type G::SEEK_CUR
* and an offset of zero. Note that this means that socket-based
* channels cannot be set unbuffered once they have had data
* read from them.
*
* On unbuffered channels, it is safe to mix read and write
* calls from the new and old APIs, if this is necessary for
* maintaining old code.
*
* The default state of the channel is buffered.
* @param buffered Whether to set the channel buffered or unbuffered.
*/
void set_buffered(bool buffered);
/** Get the buffering status of the I/O channel.
* @return The buffering status of the channel.
*/
/** Returns whether @a channel is buffered.
* @return <tt>true</tt> if the @a channel is buffered.
*/
bool get_buffered() const;
/** Returns an IOCondition depending on whether there is data to be
* read/space to write data in the internal buffers in the I/O channel.
* Only the flags Glib::IO_IN and Glib::IO_OUT may be set.
* @return Bitwise combination of Glib::IOCondition flags.
*/
/** This function returns a G::IOCondition depending on whether there
* is data to be read/space to write data in the
* internal buffers in the G::IOChannel. Only the flags G::IO_IN and
* G::IO_OUT may be set.
* @return A G::IOCondition.
*/
IOCondition get_buffer_condition() const;
/** Returns whether the file/socket/whatever associated with the I/O channel
* will be closed when the channel receives its final unref and is destroyed.
* The default value of this is <tt>true</tt> for channels created by
* create_from_file(), and <tt>false</tt> for all other channels.
* @return Whether the channel will be closed on the final unref of the
* IOChannel object.
*/
/** Returns whether the file/socket/whatever associated with @a channel
* will be closed when @a channel receives its final unref and is
* destroyed. The default value of this is <tt>true</tt> for channels created
* by g_io_channel_new_file(), and <tt>false</tt> for all other channels.
* @return Whether the channel will be closed on the final unref of
* the GIOChannel data structure.
*/
bool get_close_on_unref() const;
/** Setting this flag to <tt>true</tt> for a channel you have already closed
* can cause problems.
* @param do_close Whether to close the channel on the final unref of the
* IOChannel object. The default value of this is <tt>true</tt> for channels
* created by create_from_file(), and <tt>false</tt> for all other channels.
*/
/** Setting this flag to <tt>true</tt> for a channel you have already closed
* can cause problems.
* @param do_close Whether to close the channel on the final unref of
* the GIOChannel data structure. The default value of
* this is <tt>true</tt> for channels created by g_io_channel_new_file(),
* and <tt>false</tt> for all other channels.
*/
void set_close_on_unref(bool do_close);
/** Sets the encoding for the input/output of the channel.
* The internal encoding is always UTF-8. The default encoding for the
* external file is UTF-8. The encoding <tt>""</tt> is safe to use with
* binary data.
*
* The encoding can only be set if one of the following conditions
* is true:
*
* -# The channel was just created, and has not been written to or read from
* yet.
* -# The channel is write-only.
* -# The channel is a file, and the file pointer was just repositioned by a
* call to seek_position(). (This flushes all the internal buffers.)
* -# The current encoding is <tt>""</tt> or UTF-8.
* -# One of the read methods has just returned Glib::IO_STATUS_EOF (or, in
* the case of read_to_end(), Glib::IO_STATUS_NORMAL).
* -# The read() method has returned Glib::IO_STATUS_AGAIN or thrown
* a Glib::Error exception. This may be useful in the case of
* ConvertError::ILLEGAL_SEQUENCE. Returning one of these statuses
* from read_line() or read_to_end() does <em>not</em> guarantee that
* the encoding can be changed.
*
* Channels which do not meet one of the above conditions cannot call
* seek_position() with a seek type of Glib::SEEK_TYPE_CUR and, if they
* are "seekable", cannot call write() after calling one of the API
* "read" methods.
*
* @param encoding The encoding name, or <tt>""</tt> for binary.
* @return Glib::IO_STATUS_NORMAL if the encoding was successfully set.
* @throw Glib::IOChannelError
*/
IOStatus set_encoding(const std::string& encoding = std::string());
/** Get the encoding of the I/O channel.
* @return The current encoding of the channel.
*/
std::string get_encoding() const;
void set_line_term(const std::string& term = std::string());
std::string get_line_term() const;
/** Creates an IOSource object.
* Create a slot from a function to be called when condition is met
* for the channel with sigc::ptr_fun() or sigc::mem_fun() and pass
* it into the connect() function of the returned IOSource object.
* Polling of the channel will start when you attach a MainContext
* object to the returned IOSource object using its attach() function.
*
* Glib::signal_io().connect() is a simpler interface to the same
* functionality, for the case where you want to add the source to the
* default main context.
* @param condition The condition to watch for.
* @return An IOSource object that can be polled from a MainContext's event loop.
*/
Glib::RefPtr<IOSource> create_watch(IOCondition condition);
virtual void reference() const;
virtual void unreference() const;
GIOChannel* gobj() { return gobject_; }
const GIOChannel* gobj() const { return gobject_; }
protected:
GIOChannel* gobject_;
/** Constructor that should be used by derived classes.
* Use this constructor if you want to inherit from IOChannel.
* It will set up a GIOChannel that will call the vfuncs of your
* class even if it is being used from C code, and it will keep
* a reference to the C++ code while the GIOChannel exists.
*/
IOChannel();
#ifndef DOXYGEN_SHOULD_SKIP_THIS
IOChannel(GIOChannel* gobject, bool take_copy);
#endif
virtual IOStatus read_vfunc(char* buf, gsize count, gsize& bytes_read);
virtual IOStatus write_vfunc(const char* buf, gsize count, gsize& bytes_written);
virtual IOStatus seek_vfunc(gint64 offset, SeekType type);
virtual IOStatus close_vfunc();
virtual IOStatus set_flags_vfunc(IOFlags flags);
virtual IOFlags get_flags_vfunc();
virtual Glib::RefPtr<Glib::Source> create_watch_vfunc(IOCondition cond);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
friend class Glib::GlibmmIOChannel;
#endif
};
Glib::RefPtr<IOChannel> wrap(GIOChannel* gobject, bool take_copy = false);
} // namespace Glib
#endif /* _GLIBMM_IOCHANNEL_H */

View file

@ -1,406 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_LISTHANDLE_H
#define _GLIBMM_LISTHANDLE_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/glist.h>
#include <glibmm/containerhandle_shared.h>
namespace Glib
{
namespace Container_Helpers
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* Create and fill a GList as efficient as possible.
* This requires bidirectional iterators.
*/
template <class Bi, class Tr>
GList* create_list(Bi pbegin, Bi pend, Tr)
{
GList* head = 0;
while(pend != pbegin)
{
// Use & to force a warning if the iterator returns a temporary object.
const void *const item = Tr::to_c_type(*&*--pend);
head = g_list_prepend(head, const_cast<void*>(item));
}
return head;
}
/* Create a GList from a 0-terminated input sequence.
* Build it in reverse order and reverse the whole list afterwards,
* because appending to the list would be horribly inefficient.
*/
template <class For, class Tr>
GList* create_list(For pbegin, Tr)
{
GList* head = 0;
while(*pbegin)
{
// Use & to force a warning if the iterator returns a temporary object.
const void *const item = Tr::to_c_type(*&*pbegin);
head = g_list_prepend(head, const_cast<void*>(item));
++pbegin;
}
return g_list_reverse(head);
}
/* Convert from any container that supports bidirectional iterators.
*/
template <class Tr, class Cont>
struct ListSourceTraits
{
static GList* get_data(const Cont& cont)
{ return Glib::Container_Helpers::create_list(cont.begin(), cont.end(), Tr()); }
static const Glib::OwnershipType initial_ownership = Glib::OWNERSHIP_SHALLOW;
};
/* Convert from a 0-terminated array. The Cont
* argument must be a pointer to the first element.
*/
template <class Tr, class Cont>
struct ListSourceTraits<Tr,Cont*>
{
static GList* get_data(const Cont* array)
{ return (array) ? Glib::Container_Helpers::create_list(array, Tr()) : 0; }
static const Glib::OwnershipType initial_ownership = Glib::OWNERSHIP_SHALLOW;
};
template <class Tr, class Cont>
struct ListSourceTraits<Tr,const Cont*> : ListSourceTraits<Tr,Cont*>
{};
/* Convert from a 0-terminated array. The Cont argument must be a pointer
* to the first element. For consistency, the array must be 0-terminated,
* even though the array size is known at compile time.
*/
template <class Tr, class Cont, size_t N>
struct ListSourceTraits<Tr,Cont[N]>
{
static GList* get_data(const Cont* array)
{ return Glib::Container_Helpers::create_list(array, array + (N - 1), Tr()); }
static const Glib::OwnershipType initial_ownership = Glib::OWNERSHIP_SHALLOW;
};
template <class Tr, class Cont, size_t N>
struct ListSourceTraits<Tr,const Cont[N]> : ListSourceTraits<Tr,Cont[N]>
{};
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
/**
* @ingroup ContHelpers
* If a method takes this as an argument, or has this as a return type, then you can use a standard
* container such as std::list or std::vector.
*/
template <class Tr>
class ListHandleIterator
{
public:
typedef typename Tr::CppType CppType;
typedef typename Tr::CType CType;
typedef std::forward_iterator_tag iterator_category;
typedef CppType value_type;
typedef ptrdiff_t difference_type;
typedef value_type reference;
typedef void pointer;
explicit inline ListHandleIterator(const GList* node);
inline value_type operator*() const;
inline ListHandleIterator<Tr> & operator++();
inline const ListHandleIterator<Tr> operator++(int);
inline bool operator==(const ListHandleIterator<Tr>& rhs) const;
inline bool operator!=(const ListHandleIterator<Tr>& rhs) const;
private:
const GList* node_;
};
} // namespace Container_Helpers
/**
* @ingroup ContHandles
*/
template < class T, class Tr = Glib::Container_Helpers::TypeTraits<T> >
class ListHandle
{
public:
typedef typename Tr::CppType CppType;
typedef typename Tr::CType CType;
typedef CppType value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef Glib::Container_Helpers::ListHandleIterator<Tr> const_iterator;
typedef Glib::Container_Helpers::ListHandleIterator<Tr> iterator;
template <class Cont> inline
ListHandle(const Cont& container);
// Take over ownership of an array created by GTK+ functions.
inline ListHandle(GList* glist, Glib::OwnershipType ownership);
// Copying clears the ownership flag of the source handle.
inline ListHandle(const ListHandle<T,Tr>& other);
~ListHandle();
inline const_iterator begin() const;
inline const_iterator end() const;
template <class U> inline operator std::vector<U>() const;
template <class U> inline operator std::deque<U>() const;
template <class U> inline operator std::list<U>() const;
template <class Cont> inline
void assign_to(Cont& container) const;
template <class Out> inline
void copy(Out pdest) const;
inline GList* data() const;
inline size_t size() const;
inline bool empty() const;
private:
GList * plist_;
mutable Glib::OwnershipType ownership_;
// No copy assignment.
ListHandle<T,Tr>& operator=(const ListHandle<T,Tr>&);
};
/***************************************************************************/
/* Inline implementation */
/***************************************************************************/
#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Container_Helpers
{
/**** Glib::Container_Helpers::ListHandleIterator<> ************************/
template <class Tr> inline
ListHandleIterator<Tr>::ListHandleIterator(const GList* node)
:
node_ (node)
{}
template <class Tr> inline
typename ListHandleIterator<Tr>::value_type ListHandleIterator<Tr>::operator*() const
{
return Tr::to_cpp_type(static_cast<typename Tr::CTypeNonConst>(node_->data));
}
template <class Tr> inline
ListHandleIterator<Tr>& ListHandleIterator<Tr>::operator++()
{
node_ = node_->next;
return *this;
}
template <class Tr> inline
const ListHandleIterator<Tr> ListHandleIterator<Tr>::operator++(int)
{
const ListHandleIterator<Tr> tmp (*this);
node_ = node_->next;
return tmp;
}
template <class Tr> inline
bool ListHandleIterator<Tr>::operator==(const ListHandleIterator<Tr>& rhs) const
{
return (node_ == rhs.node_);
}
template <class Tr> inline
bool ListHandleIterator<Tr>::operator!=(const ListHandleIterator<Tr>& rhs) const
{
return (node_ != rhs.node_);
}
} // namespace Container_Helpers
/**** Glib::ListHandle<> ***************************************************/
template <class T, class Tr>
template <class Cont>
inline
ListHandle<T,Tr>::ListHandle(const Cont& container)
:
plist_ (Glib::Container_Helpers::ListSourceTraits<Tr,Cont>::get_data(container)),
ownership_ (Glib::Container_Helpers::ListSourceTraits<Tr,Cont>::initial_ownership)
{}
template <class T, class Tr> inline
ListHandle<T,Tr>::ListHandle(GList* glist, Glib::OwnershipType ownership)
:
plist_ (glist),
ownership_ (ownership)
{}
template <class T, class Tr> inline
ListHandle<T,Tr>::ListHandle(const ListHandle<T,Tr>& other)
:
plist_ (other.plist_),
ownership_ (other.ownership_)
{
other.ownership_ = Glib::OWNERSHIP_NONE;
}
template <class T, class Tr>
ListHandle<T,Tr>::~ListHandle()
{
if(ownership_ != Glib::OWNERSHIP_NONE)
{
if(ownership_ != Glib::OWNERSHIP_SHALLOW)
{
// Deep ownership: release each container element.
for(GList* node = plist_; node != 0; node = node->next)
Tr::release_c_type(static_cast<typename Tr::CTypeNonConst>(node->data));
}
g_list_free(plist_);
}
}
template <class T, class Tr> inline
typename ListHandle<T,Tr>::const_iterator ListHandle<T,Tr>::begin() const
{
return Glib::Container_Helpers::ListHandleIterator<Tr>(plist_);
}
template <class T, class Tr> inline
typename ListHandle<T,Tr>::const_iterator ListHandle<T,Tr>::end() const
{
return Glib::Container_Helpers::ListHandleIterator<Tr>(0);
}
template <class T, class Tr>
template <class U>
inline
ListHandle<T,Tr>::operator std::vector<U>() const
{
#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
return std::vector<U>(this->begin(), this->end());
#else
std::vector<U> temp;
temp.reserve(this->size());
Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
return temp;
#endif
}
template <class T, class Tr>
template <class U>
inline
ListHandle<T,Tr>::operator std::deque<U>() const
{
#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
return std::deque<U>(this->begin(), this->end());
#else
std::deque<U> temp;
Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
return temp;
#endif
}
template <class T, class Tr>
template <class U>
inline
ListHandle<T,Tr>::operator std::list<U>() const
{
#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
return std::list<U>(this->begin(), this->end());
#else
std::list<U> temp;
Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
return temp;
#endif
}
template <class T, class Tr>
template <class Cont>
inline
void ListHandle<T,Tr>::assign_to(Cont& container) const
{
#ifdef GLIBMM_HAVE_TEMPLATE_SEQUENCE_CTORS
container.assign(this->begin(), this->end());
#else
Cont temp;
Glib::Container_Helpers::fill_container(temp, this->begin(), this->end());
container.swap(temp);
#endif
}
template <class T, class Tr>
template <class Out>
inline
void ListHandle<T,Tr>::copy(Out pdest) const
{
std::copy(this->begin(), this->end(), pdest);
}
template <class T, class Tr> inline
GList* ListHandle<T,Tr>::data() const
{
return plist_;
}
template <class T, class Tr> inline
size_t ListHandle<T,Tr>::size() const
{
return g_list_length(plist_);
}
template <class T, class Tr> inline
bool ListHandle<T,Tr>::empty() const
{
return (plist_ == 0);
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
} // namespace Glib
#endif /* _GLIBMM_LISTHANDLE_H */

View file

@ -1,986 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/main.h>
#include <glibmm/exceptionhandler.h>
#include <glibmm/thread.h>
#include <glibmm/wrap.h>
#include <glibmm/iochannel.h>
#include <glib/gmessages.h>
#include <algorithm>
GLIBMM_USING_STD(min)
namespace
{
class SourceConnectionNode
{
public:
explicit inline SourceConnectionNode(const sigc::slot_base& slot);
static void* notify(void* data);
static void destroy_notify_callback(void* data);
inline void install(GSource* source);
inline sigc::slot_base* get_slot();
private:
sigc::slot_base slot_;
GSource* source_;
};
inline
SourceConnectionNode::SourceConnectionNode(const sigc::slot_base& slot)
:
slot_ (slot),
source_ (0)
{
slot_.set_parent(this, &SourceConnectionNode::notify);
}
void* SourceConnectionNode::notify(void* data)
{
SourceConnectionNode *const self = static_cast<SourceConnectionNode*>(data);
// if there is no object, this call was triggered from destroy_notify_handler(),
// because we set self->source_ to 0 there:
if (self->source_)
{
GSource* s = self->source_;
self->source_ = 0;
g_source_destroy(s);
// Destroying the object triggers execution of destroy_notify_handler(),
// eiter immediately or later, so we leave that to do the deletion.
}
return 0;
}
// static
void SourceConnectionNode::destroy_notify_callback(void* data)
{
SourceConnectionNode *const self = static_cast<SourceConnectionNode*>(data);
if (self)
{
// The GLib side is disconnected now, thus the GSource* is no longer valid.
self->source_ = 0;
delete self;
}
}
inline
void SourceConnectionNode::install(GSource* source)
{
source_ = source;
}
inline
sigc::slot_base* SourceConnectionNode::get_slot()
{
return &slot_;
}
/* We use the callback data member of GSource to store both a pointer to our
* wrapper and a pointer to the connection node that is currently being used.
* The one and only SourceCallbackData object of a Glib::Source is constructed
* in the ctor of Glib::Source and destroyed after the GSource object when the
* reference counter of the GSource object reaches zero!
*/
struct SourceCallbackData
{
explicit inline SourceCallbackData(Glib::Source* wrapper_);
void set_node(SourceConnectionNode* node_);
static void destroy_notify_callback(void* data);
Glib::Source* wrapper;
SourceConnectionNode* node;
};
inline
SourceCallbackData::SourceCallbackData(Glib::Source* wrapper_)
:
wrapper (wrapper_),
node (0)
{}
void SourceCallbackData::set_node(SourceConnectionNode* node_)
{
if(node)
SourceConnectionNode::destroy_notify_callback(node);
node = node_;
}
// static
void SourceCallbackData::destroy_notify_callback(void* data)
{
SourceCallbackData *const self = static_cast<SourceCallbackData*>(data);
if(self->node)
SourceConnectionNode::destroy_notify_callback(self->node);
if(self->wrapper)
Glib::Source::destroy_notify_callback(self->wrapper);
delete self;
}
/* Retrieve the callback data from a wrapped GSource object.
*/
static SourceCallbackData* glibmm_source_get_callback_data(GSource* source)
{
g_return_val_if_fail(source->callback_funcs->get != 0, 0);
GSourceFunc func;
void* user_data = 0;
// Retrieve the callback function and data.
(*source->callback_funcs->get)(source->callback_data, source, &func, &user_data);
return static_cast<SourceCallbackData*>(user_data);
}
/* Glib::Source doesn't use the callback function installed with
* g_source_set_callback(). Instead, it invokes the sigc++ slot
* directly from dispatch_vfunc(), which is both simpler and more
* efficient.
* For correctness, provide a pointer to this dummy callback rather
* than some random pointer. That also allows for sanity checks
* here as well as in Source::dispatch_vfunc().
*/
static gboolean glibmm_dummy_source_callback(void*)
{
g_assert_not_reached();
return 0;
}
/* Only used by SignalTimeout::connect() and SignalIdle::connect().
* These don't use Glib::Source, to avoid the unnecessary overhead
* of a completely unused wrapper object.
*/
static gboolean glibmm_source_callback(void* data)
{
SourceConnectionNode *const conn_data = static_cast<SourceConnectionNode*>(data);
try
{
// Recreate the specific slot from the generic slot node.
return (*static_cast<sigc::slot<bool>*>(conn_data->get_slot()))();
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return 0;
}
static gboolean glibmm_iosource_callback(GIOChannel*, GIOCondition condition, void* data)
{
SourceCallbackData *const callback_data = static_cast<SourceCallbackData*>(data);
g_return_val_if_fail(callback_data->node != 0, 0);
try
{
// Recreate the specific slot from the generic slot node.
return (*static_cast<sigc::slot<bool,Glib::IOCondition>*>(callback_data->node->get_slot()))
((Glib::IOCondition) condition);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return 0;
}
} // anonymous namespace
namespace Glib
{
/**** Glib::PollFD *********************************************************/
PollFD::PollFD()
{
gobject_.fd = 0;
gobject_.events = 0;
gobject_.revents = 0;
}
PollFD::PollFD(int fd)
{
gobject_.fd = fd;
gobject_.events = 0;
gobject_.revents = 0;
}
PollFD::PollFD(int fd, IOCondition events)
{
gobject_.fd = fd;
gobject_.events = events;
gobject_.revents = 0;
}
/**** Glib::SignalTimeout **************************************************/
inline
SignalTimeout::SignalTimeout(GMainContext* context)
:
context_ (context)
{}
sigc::connection SignalTimeout::connect(const sigc::slot<bool>& slot,
unsigned int interval, int priority)
{
SourceConnectionNode *const conn_node = new SourceConnectionNode(slot);
const sigc::connection connection (*conn_node->get_slot());
GSource *const source = g_timeout_source_new(interval);
if(priority != G_PRIORITY_DEFAULT)
g_source_set_priority(source, priority);
g_source_set_callback(
source, &glibmm_source_callback, conn_node,
&SourceConnectionNode::destroy_notify_callback);
g_source_attach(source, context_);
g_source_unref(source); // GMainContext holds a reference
conn_node->install(source);
return connection;
}
SignalTimeout signal_timeout()
{
return SignalTimeout(0); // 0 means default context
}
/**** Glib::SignalIdle *****************************************************/
inline
SignalIdle::SignalIdle(GMainContext* context)
:
context_ (context)
{}
sigc::connection SignalIdle::connect(const sigc::slot<bool>& slot, int priority)
{
SourceConnectionNode *const conn_node = new SourceConnectionNode(slot);
const sigc::connection connection (*conn_node->get_slot());
GSource *const source = g_idle_source_new();
if(priority != G_PRIORITY_DEFAULT)
g_source_set_priority(source, priority);
g_source_set_callback(
source, &glibmm_source_callback, conn_node,
&SourceConnectionNode::destroy_notify_callback);
g_source_attach(source, context_);
g_source_unref(source); // GMainContext holds a reference
conn_node->install(source);
return connection;
}
SignalIdle signal_idle()
{
return SignalIdle(0); // 0 means default context
}
/**** Glib::SignalIO *******************************************************/
inline
SignalIO::SignalIO(GMainContext* context)
:
context_ (context)
{}
sigc::connection SignalIO::connect(const sigc::slot<bool,IOCondition>& slot,
int fd, IOCondition condition, int priority)
{
const Glib::RefPtr<IOSource> source = IOSource::create(fd, condition);
if(priority != G_PRIORITY_DEFAULT)
source->set_priority(priority);
const sigc::connection connection = source->connect(slot);
g_source_attach(source->gobj(), context_);
return connection;
}
sigc::connection SignalIO::connect(const sigc::slot<bool,IOCondition>& slot,
const Glib::RefPtr<IOChannel>& channel,
IOCondition condition, int priority)
{
const Glib::RefPtr<IOSource> source = IOSource::create(channel, condition);
if(priority != G_PRIORITY_DEFAULT)
source->set_priority(priority);
const sigc::connection connection = source->connect(slot);
g_source_attach(source->gobj(), context_);
return connection;
}
SignalIO signal_io()
{
return SignalIO(0); // 0 means default context
}
/**** Glib::MainContext ****************************************************/
// static
Glib::RefPtr<MainContext> MainContext::create()
{
return Glib::RefPtr<MainContext>(reinterpret_cast<MainContext*>(g_main_context_new()));
}
// static
Glib::RefPtr<MainContext> MainContext::get_default()
{
return Glib::wrap(g_main_context_default(), true);
}
bool MainContext::iteration(bool may_block)
{
return g_main_context_iteration(gobj(), may_block);
}
bool MainContext::pending()
{
return g_main_context_pending(gobj());
}
void MainContext::wakeup()
{
g_main_context_wakeup(gobj());
}
bool MainContext::acquire()
{
return g_main_context_acquire(gobj());
}
bool MainContext::wait(Glib::Cond& cond, Glib::Mutex& mutex)
{
return g_main_context_wait(gobj(), cond.gobj(), mutex.gobj());
}
void MainContext::release()
{
g_main_context_release(gobj());
}
bool MainContext::prepare(int& priority)
{
return g_main_context_prepare(gobj(), &priority);
}
bool MainContext::prepare()
{
return g_main_context_prepare(gobj(), 0);
}
void MainContext::query(int max_priority, int& timeout, std::vector<PollFD>& fds)
{
if(fds.empty())
fds.resize(8); // rather bogus number, but better than 0
for(;;)
{
const int size_before = fds.size();
const int size_needed = g_main_context_query(
gobj(), max_priority, &timeout, reinterpret_cast<GPollFD*>(&fds.front()), size_before);
fds.resize(size_needed);
if(size_needed <= size_before)
break;
}
}
bool MainContext::check(int max_priority, std::vector<PollFD>& fds)
{
if(!fds.empty())
return g_main_context_check(gobj(), max_priority, reinterpret_cast<GPollFD*>(&fds.front()), fds.size());
else
return false;
}
void MainContext::dispatch()
{
g_main_context_dispatch(gobj());
}
void MainContext::set_poll_func(GPollFunc poll_func)
{
g_main_context_set_poll_func(gobj(), poll_func);
}
GPollFunc MainContext::get_poll_func()
{
return g_main_context_get_poll_func(gobj());
}
void MainContext::add_poll(PollFD& fd, int priority)
{
g_main_context_add_poll(gobj(), fd.gobj(), priority);
}
void MainContext::remove_poll(PollFD& fd)
{
g_main_context_remove_poll(gobj(), fd.gobj());
}
SignalTimeout MainContext::signal_timeout()
{
return SignalTimeout(gobj());
}
SignalIdle MainContext::signal_idle()
{
return SignalIdle(gobj());
}
SignalIO MainContext::signal_io()
{
return SignalIO(gobj());
}
void MainContext::reference() const
{
g_main_context_ref(reinterpret_cast<GMainContext*>(const_cast<MainContext*>(this)));
}
void MainContext::unreference() const
{
g_main_context_unref(reinterpret_cast<GMainContext*>(const_cast<MainContext*>(this)));
}
GMainContext* MainContext::gobj()
{
return reinterpret_cast<GMainContext*>(this);
}
const GMainContext* MainContext::gobj() const
{
return reinterpret_cast<const GMainContext*>(this);
}
GMainContext* MainContext::gobj_copy() const
{
reference();
return const_cast<GMainContext*>(gobj());
}
Glib::RefPtr<MainContext> wrap(GMainContext* gobject, bool take_copy)
{
if(take_copy && gobject)
g_main_context_ref(gobject);
return Glib::RefPtr<MainContext>(reinterpret_cast<MainContext*>(gobject));
}
/**** Glib::MainLoop *******************************************************/
Glib::RefPtr<MainLoop> MainLoop::create(bool is_running)
{
return Glib::RefPtr<MainLoop>(
reinterpret_cast<MainLoop*>(g_main_loop_new(0, is_running)));
}
Glib::RefPtr<MainLoop> MainLoop::create(const Glib::RefPtr<MainContext>& context, bool is_running)
{
return Glib::RefPtr<MainLoop>(
reinterpret_cast<MainLoop*>(g_main_loop_new(Glib::unwrap(context), is_running)));
}
void MainLoop::run()
{
g_main_loop_run(gobj());
}
void MainLoop::quit()
{
g_main_loop_quit(gobj());
}
bool MainLoop::is_running()
{
return g_main_loop_is_running(gobj());
}
Glib::RefPtr<MainContext> MainLoop::get_context()
{
return Glib::wrap(g_main_loop_get_context(gobj()), true);
}
//static:
int MainLoop::depth()
{
return g_main_depth();
}
void MainLoop::reference() const
{
g_main_loop_ref(reinterpret_cast<GMainLoop*>(const_cast<MainLoop*>(this)));
}
void MainLoop::unreference() const
{
g_main_loop_unref(reinterpret_cast<GMainLoop*>(const_cast<MainLoop*>(this)));
}
GMainLoop* MainLoop::gobj()
{
return reinterpret_cast<GMainLoop*>(this);
}
const GMainLoop* MainLoop::gobj() const
{
return reinterpret_cast<const GMainLoop*>(this);
}
GMainLoop* MainLoop::gobj_copy() const
{
reference();
return const_cast<GMainLoop*>(gobj());
}
Glib::RefPtr<MainLoop> wrap(GMainLoop* gobject, bool take_copy)
{
if(take_copy && gobject)
g_main_loop_ref(gobject);
return Glib::RefPtr<MainLoop>(reinterpret_cast<MainLoop*>(gobject));
}
/**** Glib::Source *********************************************************/
// static
const GSourceFuncs Source::vfunc_table_ =
{
&Source::prepare_vfunc,
&Source::check_vfunc,
&Source::dispatch_vfunc,
0, // finalize_vfunc // We can't use finalize_vfunc because there is no way
// to store a pointer to our wrapper anywhere in GSource so
// that it persists until finalize_vfunc would be called from here.
0, // closure_callback
0, // closure_marshal
};
unsigned int Source::attach(const Glib::RefPtr<MainContext>& context)
{
return g_source_attach(gobject_, Glib::unwrap(context));
}
unsigned int Source::attach()
{
return g_source_attach(gobject_, 0);
}
void Source::destroy()
{
g_source_destroy(gobject_);
}
void Source::set_priority(int priority)
{
g_source_set_priority(gobject_, priority);
}
int Source::get_priority() const
{
return g_source_get_priority(gobject_);
}
void Source::set_can_recurse(bool can_recurse)
{
g_source_set_can_recurse(gobject_, can_recurse);
}
bool Source::get_can_recurse() const
{
return g_source_get_can_recurse(gobject_);
}
unsigned int Source::get_id() const
{
return g_source_get_id(gobject_);
}
Glib::RefPtr<MainContext> Source::get_context()
{
return Glib::wrap(g_source_get_context(gobject_), true);
}
GSource* Source::gobj_copy() const
{
return g_source_ref(gobject_);
}
void Source::reference() const
{
g_source_ref(gobject_);
}
void Source::unreference() const
{
g_source_unref(gobject_);
}
Source::Source()
:
gobject_ (g_source_new(const_cast<GSourceFuncs*>(&vfunc_table_), sizeof(GSource)))
{
g_source_set_callback(
gobject_, &glibmm_dummy_source_callback,
new SourceCallbackData(this), // our persistant callback data object
&SourceCallbackData::destroy_notify_callback);
}
Source::Source(GSource* cast_item, GSourceFunc callback_func)
:
gobject_ (cast_item)
{
g_source_set_callback(
gobject_, callback_func,
new SourceCallbackData(this), // our persistant callback data object
&SourceCallbackData::destroy_notify_callback);
}
Source::~Source()
{
// The dtor should be invoked by destroy_notify_callback() only, which clears
// gobject_ before deleting. However, we might also get to this point if
// a derived ctor threw an exception, and then we need to unref manually.
if(gobject_)
{
SourceCallbackData *const data = glibmm_source_get_callback_data(gobject_);
data->wrapper = 0;
GSource *const tmp_gobject = gobject_;
gobject_ = 0;
g_source_unref(tmp_gobject);
}
}
sigc::connection Source::connect_generic(const sigc::slot_base& slot)
{
SourceConnectionNode *const conn_node = new SourceConnectionNode(slot);
const sigc::connection connection (*conn_node->get_slot());
// Don't override the callback data. Reuse the existing one
// calling SourceCallbackData::set_node() to register conn_node.
SourceCallbackData *const data = glibmm_source_get_callback_data(gobject_);
data->set_node(conn_node);
conn_node->install(gobject_);
return connection;
}
void Source::add_poll(Glib::PollFD& poll_fd)
{
g_source_add_poll(gobject_, poll_fd.gobj());
}
void Source::remove_poll(Glib::PollFD& poll_fd)
{
g_source_remove_poll(gobject_, poll_fd.gobj());
}
void Source::get_current_time(Glib::TimeVal& current_time)
{
g_source_get_current_time(gobject_, &current_time);
}
inline // static
Source* Source::get_wrapper(GSource* source)
{
SourceCallbackData *const data = glibmm_source_get_callback_data(source);
return data->wrapper;
}
// static
gboolean Source::prepare_vfunc(GSource* source, int* timeout)
{
try
{
Source *const self = get_wrapper(source);
return self->prepare(*timeout);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return 0;
}
// static
gboolean Source::check_vfunc(GSource* source)
{
try
{
Source *const self = get_wrapper(source);
return self->check();
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return 0;
}
// static
gboolean Source::dispatch_vfunc(GSource*, GSourceFunc callback, void* user_data)
{
SourceCallbackData *const callback_data = static_cast<SourceCallbackData*>(user_data);
g_return_val_if_fail(callback == &glibmm_dummy_source_callback, 0);
g_return_val_if_fail(callback_data != 0 && callback_data->node != 0, 0);
try
{
Source *const self = callback_data->wrapper;
return self->dispatch(callback_data->node->get_slot());
}
catch(...)
{
Glib::exception_handlers_invoke();
}
return 0;
}
// static
void Source::destroy_notify_callback(void* data)
{
if(data)
{
Source *const self = static_cast<Source*>(data);
// gobject_ is already invalid at this point.
self->gobject_ = 0;
// No exception checking: if the dtor throws, you're out of luck anyway.
delete self;
}
}
/**** Glib::TimeoutSource **************************************************/
// static
Glib::RefPtr<TimeoutSource> TimeoutSource::create(unsigned int interval)
{
return Glib::RefPtr<TimeoutSource>(new TimeoutSource(interval));
}
sigc::connection TimeoutSource::connect(const sigc::slot<bool>& slot)
{
return connect_generic(slot);
}
TimeoutSource::TimeoutSource(unsigned int interval)
:
interval_ (interval)
{
expiration_.assign_current_time();
expiration_.add_milliseconds(std::min<unsigned long>(G_MAXLONG, interval_));
}
TimeoutSource::~TimeoutSource()
{}
bool TimeoutSource::prepare(int& timeout)
{
Glib::TimeVal current_time;
get_current_time(current_time);
Glib::TimeVal remaining = expiration_;
remaining.subtract(current_time);
if(remaining.negative())
{
// Already expired.
timeout = 0;
}
else
{
const unsigned long milliseconds =
static_cast<unsigned long>(remaining.tv_sec) * 1000U +
static_cast<unsigned long>(remaining.tv_usec) / 1000U;
// Set remaining milliseconds.
timeout = std::min<unsigned long>(G_MAXINT, milliseconds);
// Check if the system time has been set backwards. (remaining > interval)
remaining.add_milliseconds(- std::min<unsigned long>(G_MAXLONG, interval_) - 1);
if(!remaining.negative())
{
// Oh well. Reset the expiration time to now + interval;
// this at least avoids hanging for long periods of time.
expiration_ = current_time;
expiration_.add_milliseconds(interval_);
timeout = std::min<unsigned int>(G_MAXINT, interval_);
}
}
return (timeout == 0);
}
bool TimeoutSource::check()
{
Glib::TimeVal current_time;
get_current_time(current_time);
return (expiration_ <= current_time);
}
bool TimeoutSource::dispatch(sigc::slot_base* slot)
{
const bool again = (*static_cast<sigc::slot<bool>*>(slot))();
if(again)
{
get_current_time(expiration_);
expiration_.add_milliseconds(std::min<unsigned long>(G_MAXLONG, interval_));
}
return again;
}
/**** Glib::IdleSource *****************************************************/
// static
Glib::RefPtr<IdleSource> IdleSource::create()
{
return Glib::RefPtr<IdleSource>(new IdleSource());
}
sigc::connection IdleSource::connect(const sigc::slot<bool>& slot)
{
return connect_generic(slot);
}
IdleSource::IdleSource()
{
set_priority(PRIORITY_DEFAULT_IDLE);
}
IdleSource::~IdleSource()
{}
bool IdleSource::prepare(int& timeout)
{
timeout = 0;
return true;
}
bool IdleSource::check()
{
return true;
}
bool IdleSource::dispatch(sigc::slot_base* slot)
{
return (*static_cast<sigc::slot<bool>*>(slot))();
}
/**** Glib::IOSource *******************************************************/
// static
Glib::RefPtr<IOSource> IOSource::create(int fd, IOCondition condition)
{
return Glib::RefPtr<IOSource>(new IOSource(fd, condition));
}
Glib::RefPtr<IOSource> IOSource::create(const Glib::RefPtr<IOChannel>& channel, IOCondition condition)
{
return Glib::RefPtr<IOSource>(new IOSource(channel, condition));
}
sigc::connection IOSource::connect(const sigc::slot<bool,IOCondition>& slot)
{
return connect_generic(slot);
}
IOSource::IOSource(int fd, IOCondition condition)
:
poll_fd_ (fd, condition)
{
add_poll(poll_fd_);
}
IOSource::IOSource(const Glib::RefPtr<IOChannel>& channel, IOCondition condition)
:
Source(g_io_create_watch(channel->gobj(), (GIOCondition) condition),
(GSourceFunc) &glibmm_iosource_callback)
{}
IOSource::~IOSource()
{}
bool IOSource::prepare(int& timeout)
{
timeout = -1;
return false;
}
bool IOSource::check()
{
return ((poll_fd_.get_revents() & poll_fd_.get_events()) != 0);
}
bool IOSource::dispatch(sigc::slot_base* slot)
{
return (*static_cast<sigc::slot<bool,IOCondition>*>(slot))
(poll_fd_.get_revents());
}
} // namespace Glib

View file

@ -1,697 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_MAIN_H
#define _GLIBMM_MAIN_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/giochannel.h>
#include <glib/gmain.h>
#include <vector>
#include <sigc++/sigc++.h>
#include <glibmmconfig.h>
#include <glibmm/refptr.h>
#include <glibmm/timeval.h>
GLIBMM_USING_STD(vector)
namespace Glib
{
class Cond;
class Mutex;
class IOChannel;
/** @defgroup MainLoop The Main Event Loop
* Manages all available sources of events.
* @{
*/
enum
{
/*! Use this for high priority event sources. It is not used within
* GLib or GTK+.<br><br>
*/
PRIORITY_HIGH = -100,
/*! Use this for default priority event sources. In glibmm this
* priority is used by default when installing timeout handlers with
* SignalTimeout::connect(). In GDK this priority is used for events
* from the X server.<br><br>
*/
PRIORITY_DEFAULT = 0,
/*! Use this for high priority idle functions. GTK+ uses
* <tt>PRIORITY_HIGH_IDLE&nbsp;+&nbsp;10</tt> for resizing operations, and
* <tt>PRIORITY_HIGH_IDLE&nbsp;+&nbsp;20</tt> for redrawing operations.
* (This is done to ensure that any pending resizes are processed before
* any pending redraws, so that widgets are not redrawn twice unnecessarily.)
* <br><br>
*/
PRIORITY_HIGH_IDLE = 100,
/*! Use this for default priority idle functions. In glibmm this priority is
* used by default when installing idle handlers with SignalIdle::connect().
* <br><br>
*/
PRIORITY_DEFAULT_IDLE = 200,
/*! Use this for very low priority background tasks. It is not used within
* GLib or GTK+.
*/
PRIORITY_LOW = 300
};
/** A bitwise combination representing an I/O condition to watch for on an
* event source.
* The flags correspond to those used by the <tt>%poll()</tt> system call
* on UNIX (see <tt>man 2 poll</tt>). To test for individual flags, do
* something like this:
* @code
* if((condition & Glib::IO_OUT) != 0)
* do_some_output();
* @endcode
* @par Bitwise operators:
* <tt>IOCondition operator|(IOCondition, IOCondition)</tt><br>
* <tt>IOCondition operator&(IOCondition, IOCondition)</tt><br>
* <tt>IOCondition operator^(IOCondition, IOCondition)</tt><br>
* <tt>IOCondition operator~(IOCondition)</tt><br>
* <tt>IOCondition& operator|=(IOCondition&, IOCondition)</tt><br>
* <tt>IOCondition& operator&=(IOCondition&, IOCondition)</tt><br>
* <tt>IOCondition& operator^=(IOCondition&, IOCondition)</tt><br>
*/
enum IOCondition
{
IO_IN = G_IO_IN, /*!< @hideinitializer There is data to read. */
IO_OUT = G_IO_OUT, /*!< @hideinitializer Data can be written (without blocking). */
IO_PRI = G_IO_PRI, /*!< @hideinitializer There is urgent data to read. */
IO_ERR = G_IO_ERR, /*!< @hideinitializer %Error condition. */
IO_HUP = G_IO_HUP, /*!< @hideinitializer Hung up (the connection has been broken,
usually for pipes and sockets). */
IO_NVAL = G_IO_NVAL /*!< @hideinitializer Invalid request. The file descriptor is not open. */
};
inline IOCondition operator|(IOCondition lhs, IOCondition rhs)
{ return static_cast<IOCondition>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
inline IOCondition operator&(IOCondition lhs, IOCondition rhs)
{ return static_cast<IOCondition>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
inline IOCondition operator^(IOCondition lhs, IOCondition rhs)
{ return static_cast<IOCondition>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
inline IOCondition operator~(IOCondition flags)
{ return static_cast<IOCondition>(~static_cast<unsigned>(flags)); }
inline IOCondition& operator|=(IOCondition& lhs, IOCondition rhs)
{ return (lhs = static_cast<IOCondition>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
inline IOCondition& operator&=(IOCondition& lhs, IOCondition rhs)
{ return (lhs = static_cast<IOCondition>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
inline IOCondition& operator^=(IOCondition& lhs, IOCondition rhs)
{ return (lhs = static_cast<IOCondition>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
class PollFD
{
public:
PollFD();
explicit PollFD(int fd);
PollFD(int fd, IOCondition events);
void set_fd(int fd) { gobject_.fd = fd; }
int get_fd() const { return gobject_.fd; }
void set_events(IOCondition events) { gobject_.events = events; }
IOCondition get_events() const { return static_cast<IOCondition>(gobject_.events); }
void set_revents(IOCondition revents) { gobject_.revents = revents; }
IOCondition get_revents() const { return static_cast<IOCondition>(gobject_.revents); }
GPollFD* gobj() { return &gobject_; }
const GPollFD* gobj() const { return &gobject_; }
private:
GPollFD gobject_;
};
class SignalTimeout
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
explicit inline SignalTimeout(GMainContext* context);
#endif
/** Connects a timeout handler.
* @code
* Glib::signal_timeout().connect(sigc::ptr_fun(&timeout_handler), 1000);
* @endcode
* is equivalent to:
* @code
* const Glib::RefPtr<Glib::TimeoutSource> timeout_source = Glib::TimeoutSource::create(1000);
* timeout_source->connect(sigc::ptr_fun(&timeout_handler));
* timeout_source->attach(Glib::MainContext::get_default());
* @endcode
* @param slot A slot to call when @a interval elapsed.
* @param interval The timeout in milliseconds.
* @param priority The priority of the new event source.
* @return A connection handle, which can be used to disconnect the handler.
*/
sigc::connection connect(const sigc::slot<bool>& slot, unsigned int interval,
int priority = PRIORITY_DEFAULT);
private:
GMainContext* context_;
// no copy assignment
SignalTimeout& operator=(const SignalTimeout&);
};
class SignalIdle
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
explicit inline SignalIdle(GMainContext* context);
#endif
/** Connects an idle handler.
* @code
* Glib::signal_idle().connect(sigc::ptr_fun(&idle_handler));
* @endcode
* is equivalent to:
* @code
* const Glib::RefPtr<Glib::IdleSource> idle_source = Glib::IdleSource::create();
* idle_source->connect(sigc::ptr_fun(&idle_handler));
* idle_source->attach(Glib::MainContext::get_default());
* @endcode
* @param slot A slot to call when the main loop is idle.
* @param priority The priority of the new event source.
* @return A connection handle, which can be used to disconnect the handler.
*/
sigc::connection connect(const sigc::slot<bool>& slot, int priority = PRIORITY_DEFAULT_IDLE);
private:
GMainContext* context_;
// no copy assignment
SignalIdle& operator=(const SignalIdle&);
};
class SignalIO
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
explicit inline SignalIO(GMainContext* context);
#endif
/** Connects an I/O handler.
* @code
* Glib::signal_io().connect(sigc::ptr_fun(&io_handler), fd, Glib::IO_IN | Glib::IO_HUP);
* @endcode
* is equivalent to:
* @code
* const Glib::RefPtr<Glib::IOSource> io_source = Glib::IOSource::create(fd, Glib::IO_IN | Glib::IO_HUP);
* io_source->connect(sigc::ptr_fun(&io_handler));
* io_source->attach(Glib::MainContext::get_default());
* @endcode
* @param slot A slot to call when polling @a fd results in an event that matches @a condition.
* The event will be passed as a parameter to @a slot.
* If @a io_handler returns <tt>false</tt> the signal is disconnected.
* @param fd The file descriptor (or a @c HANDLE on Win32 systems) to watch.
* @param condition The conditions to watch for.
* @param priority The priority of the new event source.
* @return A connection handle, which can be used to disconnect the handler.
*/
sigc::connection connect(const sigc::slot<bool,IOCondition>& slot, int fd,
IOCondition condition, int priority = PRIORITY_DEFAULT);
/** Connects an I/O channel.
* @code
* Glib::signal_io().connect(sigc::ptr_fun(&io_handler), channel, Glib::IO_IN | Glib::IO_HUP);
* @endcode
* is equivalent to:
* @code
* const Glib::RefPtr<Glib::IOSource> io_source = Glib::IOSource::create(channel, Glib::IO_IN | Glib::IO_HUP);
* io_source->connect(sigc::ptr_fun(&io_handler));
* io_source->attach(Glib::MainContext::get_default());
* @endcode
* @param slot A slot to call when polling @a channel results in an event that matches @a condition.
* The event will be passed as a parameter to @a slot.
* If @a io_handler returns <tt>false</tt> the signal is disconnected.
* @param channel The IOChannel object to watch.
* @param condition The conditions to watch for.
* @param priority The priority of the new event source.
* @return A connection handle, which can be used to disconnect the handler.
*/
sigc::connection connect(const sigc::slot<bool,IOCondition>& slot, const Glib::RefPtr<IOChannel>& channel,
IOCondition condition, int priority = PRIORITY_DEFAULT);
private:
GMainContext* context_;
// no copy assignment
SignalIO& operator=(const SignalIO&);
};
/** Convenience timeout signal.
* @return A signal proxy; you want to use SignalTimeout::connect().
*/
SignalTimeout signal_timeout();
/** Convenience idle signal.
* @return A signal proxy; you want to use SignalIdle::connect().
*/
SignalIdle signal_idle();
/** Convenience I/O signal.
* @return A signal proxy; you want to use SignalIO::connect().
*/
SignalIO signal_io();
/** Main context.
*/
class MainContext
{
public:
typedef Glib::MainContext CppObjectType;
typedef GMainContext BaseObjectType;
/** Creates a new MainContext.
* @return The new MainContext.
*/
static Glib::RefPtr<MainContext> create();
/** Returns the default main context.
* This is the main context used for main loop functions when a main loop is not explicitly specified.
* @return The new MainContext.
*/
static Glib::RefPtr<MainContext> get_default();
/** Runs a single iteration for the given main loop.
* This involves checking to see if any event sources are ready to be processed, then if no events sources are ready and may_block is true, waiting for a source to become ready, then dispatching the highest priority events sources that are ready. Note that even when may_block is true, it is still possible for iteration() to return FALSE, since the the wait may be interrupted for other reasons than an event source becoming ready.
* @param may_block Whether the call may block.
* @return true if events were dispatched.
*/
bool iteration(bool may_block);
/** Checks if any sources have pending events for the given context.
* @return true if events are pending.
*/
bool pending();
/** If context is currently waiting in a poll(), interrupt the poll(), and continue the iteration process.
*/
void wakeup();
/** Tries to become the owner of the specified context.
* If some other context is the owner of the context, returns FALSE immediately. Ownership is properly recursive: the owner can require ownership again and will release ownership when release() is called as many times as acquire().
* You must be the owner of a context before you can call prepare(), query(), check(), dispatch().
* @return true if the operation succeeded, and this thread is now the owner of context.
*/
bool acquire();
/** Tries to become the owner of the specified context, as with acquire(). But if another thread is the owner, atomically drop mutex and wait on cond until that owner releases ownership or until cond is signaled, then try again (once) to become the owner.
* @param cond A condition variable.
* @param mutex A mutex, currently held.
* @return true if the operation succeeded, and this thread is now the owner of context.
*/
bool wait(Glib::Cond& cond, Glib::Mutex& mutex);
/** Releases ownership of a context previously acquired by this thread with acquire(). If the context was acquired multiple times, the only release ownership when release() is called as many times as it was acquired.
*/
void release();
/** Prepares to poll sources within a main loop. The resulting information for polling is determined by calling query().
* @param priority Location to store priority of highest priority source already ready.
* @return true if some source is ready to be dispatched prior to polling.
*/
bool prepare(int& priority);
/** Prepares to poll sources within a main loop. The resulting information for polling is determined by calling query().
* @return true if some source is ready to be dispatched prior to polling.
*/
bool prepare();
/** Determines information necessary to poll this main loop.
* @param max_priority Maximum priority source to check.
* @param timeout Location to store timeout to be used in polling.
* @param fds Location to store Glib::PollFD records that need to be polled.
* @return the number of records actually stored in fds, or, if more than n_fds records need to be stored, the number of records that need to be stored.
*/
void query(int max_priority, int& timeout, std::vector<PollFD>& fds);
/** Passes the results of polling back to the main loop.
* @param max_priority Maximum numerical priority of sources to check.
* @param fds Vector of Glib::PollFD's that was passed to the last call to query()
* @return true if some sources are ready to be dispatched.
*/
bool check(int max_priority, std::vector<PollFD>& fds);
/** Dispatches all pending sources.
*/
void dispatch();
//TODO: Use slot instead?
/** Sets the function to use to handle polling of file descriptors. It will be used instead of the poll() system call (or GLib's replacement function, which is used where poll() isn't available).
* This function could possibly be used to integrate the GLib event loop with an external event loop.
* @param poll_func The function to call to poll all file descriptors.
*/
void set_poll_func(GPollFunc poll_func);
/** Gets the poll function set by g_main_context_set_poll_func().
* @return The poll function
*/
GPollFunc get_poll_func();
/** Adds a file descriptor to the set of file descriptors polled for this context. This will very seldomly be used directly. Instead a typical event source will use Glib::Source::add_poll() instead.
* @param fd A PollFD structure holding information about a file descriptor to watch.
* @param priority The priority for this file descriptor which should be the same as the priority used for Glib::Source::attach() to ensure that the file descriptor is polled whenever the results may be needed.
*/
void add_poll(PollFD& fd, int priority);
/** Removes file descriptor from the set of file descriptors to be polled for a particular context.
* @param fd A PollFD structure holding information about a file descriptor.
*/
void remove_poll(PollFD& fd);
/** Timeout signal, attached to this MainContext.
* @return A signal proxy; you want to use SignalTimeout::connect().
*/
SignalTimeout signal_timeout();
/** Idle signal, attached to this MainContext.
* @return A signal proxy; you want to use SignalIdle::connect().
*/
SignalIdle signal_idle();
/** I/O signal, attached to this MainContext.
* @return A signal proxy; you want to use SignalIO::connect().
*/
SignalIO signal_io();
void reference() const;
void unreference() const;
GMainContext* gobj();
const GMainContext* gobj() const;
GMainContext* gobj_copy() const;
private:
// Glib::MainContext can neither be constructed nor deleted.
MainContext();
void operator delete(void*, size_t);
// noncopyable
MainContext(const MainContext& other);
MainContext& operator=(const MainContext& other);
};
/** @relates Glib::MainContext */
Glib::RefPtr<MainContext> wrap(GMainContext* gobject, bool take_copy = false);
class MainLoop
{
public:
typedef Glib::MainLoop CppObjectType;
typedef GMainLoop BaseObjectType;
static Glib::RefPtr<MainLoop> create(bool is_running = false);
static Glib::RefPtr<MainLoop> create(const Glib::RefPtr<MainContext>& context,
bool is_running = false);
/** Runs a main loop until quit() is called on the loop.
* If this is called for the thread of the loop's MainContext, it will process events from the loop, otherwise it will simply wait.
*/
void run();
/** Stops a MainLoop from running. Any calls to run() for the loop will return.
*/
void quit();
/** Checks to see if the main loop is currently being run via run().
* @return true if the mainloop is currently being run.
*/
bool is_running();
/** Returns the MainContext of loop.
* @return The MainContext of loop.
*/
Glib::RefPtr<MainContext> get_context();
//TODO: C++ize the (big) g_main_depth docs here.
static int depth();
/** Increases the reference count on a MainLoop object by one.
*/
void reference() const;
/** Decreases the reference count on a MainLoop object by one.
* If the result is zero, free the loop and free all associated memory.
*/
void unreference() const;
GMainLoop* gobj();
const GMainLoop* gobj() const;
GMainLoop* gobj_copy() const;
private:
// Glib::MainLoop can neither be constructed nor deleted.
MainLoop();
void operator delete(void*, size_t);
MainLoop(const MainLoop&);
MainLoop& operator=(const MainLoop&);
};
/** @relates Glib::MainLoop */
Glib::RefPtr<MainLoop> wrap(GMainLoop* gobject, bool take_copy = false);
class Source
{
public:
typedef Glib::Source CppObjectType;
typedef GSource BaseObjectType;
static Glib::RefPtr<Source> create() /* = 0 */;
/** Adds a Source to a context so that it will be executed within that context.
* @param context A MainContext.
* @return The ID for the source within the MainContext.
*/
unsigned int attach(const Glib::RefPtr<MainContext>& context);
/** Adds a Source to a context so that it will be executed within that context.
* The default context will be used.
* @return The ID for the source within the MainContext.
*/
unsigned int attach();
//TODO: Does this destroy step make sense in C++? Should it just be something that happens in a destructor?
/** Removes a source from its MainContext, if any, and marks it as destroyed.
* The source cannot be subsequently added to another context.
*/
void destroy();
/** Sets the priority of a source. While the main loop is being run, a source will be dispatched if it is ready to be dispatched and no sources at a higher (numerically smaller) priority are ready to be dispatched.
* @param priority The new priority.
*/
void set_priority(int priority);
/** Gets the priority of a source.
* @return The priority of the source.
*/
int get_priority() const;
/** Sets whether a source can be called recursively.
* If @a can_recurse is true, then while the source is being dispatched then this source will be processed normally. Otherwise, all processing of this source is blocked until the dispatch function returns.
* @param can_recurse Whether recursion is allowed for this source.
*/
void set_can_recurse(bool can_recurse);
/** Checks whether a source is allowed to be called recursively. see set_can_recurse().
* @return Whether recursion is allowed.
*/
bool get_can_recurse() const;
/** Returns the numeric ID for a particular source.
* The ID of a source is unique within a particular main loop context. The reverse mapping from ID to source is done by MainContext::find_source_by_id().
* @return The ID for the source.
*/
unsigned int get_id() const;
//TODO: Add a const version of this method?
/** Gets the MainContext with which the source is associated.
* Calling this function on a destroyed source is an error.
* @return The MainContext with which the source is associated, or a null RefPtr if the context has not yet been added to a source.
*/
Glib::RefPtr<MainContext> get_context();
GSource* gobj() { return gobject_; }
const GSource* gobj() const { return gobject_; }
GSource* gobj_copy() const;
void reference() const;
void unreference() const;
protected:
/** Construct an object that uses the virtual functions prepare(), check() and dispatch().
*/
Source();
/** Wrap an existing GSource object and install the given callback function.
* The constructed object doesn't use the virtual functions prepare(), check() and dispatch().
* This constructor is for use by derived types that need to wrap a GSource object.
* The callback function can be a static member function. But beware -
* depending on the actual implementation of the GSource's virtual functions
* the expected type of the callback function can differ from GSourceFunc.
*/
Source(GSource* cast_item, GSourceFunc callback_func);
virtual ~Source();
sigc::connection connect_generic(const sigc::slot_base& slot);
/** Adds a file descriptor to the set of file descriptors polled for this source.
* The event source's check function will typically test the revents field in the PollFD and return true if events need to be processed.
* @param poll_fd A PollFD object holding information about a file descriptor to watch.
*/
void add_poll(PollFD& poll_fd);
/** Removes a file descriptor from the set of file descriptors polled for this source.
* @param poll_fd A PollFD object previously passed to add_poll().
*/
void remove_poll(PollFD& poll_fd);
/** Gets the "current time" to be used when checking this source. The advantage of calling this function over calling get_current_time() directly is that when checking multiple sources, GLib can cache a single value instead of having to repeatedly get the system time.
* @param current_time Glib::TimeVal in which to store current time
*/
void get_current_time(Glib::TimeVal& current_time);
virtual bool prepare(int& timeout) = 0;
virtual bool check() = 0;
virtual bool dispatch(sigc::slot_base* slot) = 0;
private:
GSource* gobject_;
#ifndef DOXGEN_SHOULD_SKIP_THIS
static inline Source* get_wrapper(GSource* source);
static const GSourceFuncs vfunc_table_;
static gboolean prepare_vfunc(GSource* source, int* timeout);
static gboolean check_vfunc(GSource* source);
static gboolean dispatch_vfunc(GSource* source, GSourceFunc callback, void* user_data);
public:
static void destroy_notify_callback(void* data);
private:
#endif /* DOXGEN_SHOULD_SKIP_THIS */
// noncopyable
Source(const Source&);
Source& operator=(const Source&);
};
class TimeoutSource : public Glib::Source
{
public:
typedef Glib::TimeoutSource CppObjectType;
static Glib::RefPtr<TimeoutSource> create(unsigned int interval);
sigc::connection connect(const sigc::slot<bool>& slot);
protected:
explicit TimeoutSource(unsigned int interval);
virtual ~TimeoutSource();
virtual bool prepare(int& timeout);
virtual bool check();
virtual bool dispatch(sigc::slot_base* slot);
private:
Glib::TimeVal expiration_;
unsigned int interval_;
};
class IdleSource : public Glib::Source
{
public:
typedef Glib::IdleSource CppObjectType;
static Glib::RefPtr<IdleSource> create();
sigc::connection connect(const sigc::slot<bool>& slot);
protected:
IdleSource();
virtual ~IdleSource();
virtual bool prepare(int& timeout);
virtual bool check();
virtual bool dispatch(sigc::slot_base* slot_data);
};
class IOSource : public Glib::Source
{
public:
typedef Glib::IOSource CppObjectType;
static Glib::RefPtr<IOSource> create(int fd, IOCondition condition);
static Glib::RefPtr<IOSource> create(const Glib::RefPtr<IOChannel>& channel, IOCondition condition);
sigc::connection connect(const sigc::slot<bool,IOCondition>& slot);
protected:
IOSource(int fd, IOCondition condition);
IOSource(const Glib::RefPtr<IOChannel>& channel, IOCondition condition);
virtual ~IOSource();
virtual bool prepare(int& timeout);
virtual bool check();
virtual bool dispatch(sigc::slot_base* slot);
private:
PollFD poll_fd_;
};
/** @} group MainLoop */
} // namespace Glib
#endif /* _GLIBMM_MAIN_H */

View file

@ -1,350 +0,0 @@
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <glibmm/markup.h>
#include <glibmm/private/markup_p.h>
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/markup.h>
#include <glibmm/exceptionhandler.h>
#include <glibmm/utility.h>
#include <glib.h>
namespace Glib
{
namespace Markup
{
Glib::ustring escape_text(const Glib::ustring& text)
{
const Glib::ScopedPtr<char> buf (g_markup_escape_text(text.data(), text.bytes()));
return Glib::ustring(buf.get());
}
/**** Glib::Markup::AttributeKeyLess ***************************************/
bool AttributeKeyLess::operator()(const Glib::ustring& lhs, const Glib::ustring& rhs) const
{
return (lhs.raw() < rhs.raw());
}
/**** Glib::Markup::ParserCallbacks ****************************************/
class ParserCallbacks
{
public:
static const GMarkupParser vfunc_table;
static void start_element(GMarkupParseContext* context,
const char* element_name,
const char** attribute_names,
const char** attribute_values,
void* user_data,
GError** error);
static void end_element(GMarkupParseContext* context,
const char* element_name,
void* user_data,
GError** error);
static void text(GMarkupParseContext* context,
const char* text,
gsize text_len,
void* user_data,
GError** error);
static void passthrough(GMarkupParseContext* context,
const char* passthrough_text,
gsize text_len,
void* user_data,
GError** error);
static void error(GMarkupParseContext* context,
GError* error,
void* user_data);
};
const GMarkupParser ParserCallbacks::vfunc_table =
{
&ParserCallbacks::start_element,
&ParserCallbacks::end_element,
&ParserCallbacks::text,
&ParserCallbacks::passthrough,
&ParserCallbacks::error,
};
void ParserCallbacks::start_element(GMarkupParseContext* context,
const char* element_name,
const char** attribute_names,
const char** attribute_values,
void* user_data,
GError** error)
{
ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
g_return_if_fail(context == cpp_context.gobj());
try
{
Parser::AttributeMap attributes;
if(attribute_names && attribute_values)
{
const char *const * pname = attribute_names;
const char *const * pvalue = attribute_values;
for(; *pname && *pvalue; ++pname, ++pvalue)
attributes.insert(Parser::AttributeMap::value_type(*pname, *pvalue));
g_return_if_fail(*pname == 0 && *pvalue == 0);
}
cpp_context.get_parser()->on_start_element(cpp_context, element_name, attributes);
}
catch(MarkupError& err)
{
err.propagate(error);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
void ParserCallbacks::end_element(GMarkupParseContext* context,
const char* element_name,
void* user_data,
GError** error)
{
ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
g_return_if_fail(context == cpp_context.gobj());
try
{
cpp_context.get_parser()->on_end_element(cpp_context, element_name);
}
catch(MarkupError& err)
{
err.propagate(error);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
void ParserCallbacks::text(GMarkupParseContext* context,
const char* text,
gsize text_len,
void* user_data,
GError** error)
{
ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
g_return_if_fail(context == cpp_context.gobj());
try
{
cpp_context.get_parser()->on_text(cpp_context, Glib::ustring(text, text + text_len));
}
catch(MarkupError& err)
{
err.propagate(error);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
void ParserCallbacks::passthrough(GMarkupParseContext* context,
const char* passthrough_text,
gsize text_len,
void* user_data,
GError** error)
{
ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
g_return_if_fail(context == cpp_context.gobj());
try
{
cpp_context.get_parser()->on_passthrough(
cpp_context, Glib::ustring(passthrough_text, passthrough_text + text_len));
}
catch(MarkupError& err)
{
err.propagate(error);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
void ParserCallbacks::error(GMarkupParseContext* context,
GError* error,
void* user_data)
{
ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
g_return_if_fail(context == cpp_context.gobj());
g_return_if_fail(error->domain == G_MARKUP_ERROR);
try
{
cpp_context.get_parser()->on_error(cpp_context, MarkupError(g_error_copy(error)));
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
/**** Glib::Markup::Parser *************************************************/
Parser::Parser()
{}
Parser::~Parser()
{}
void Parser::on_start_element(ParseContext&, const Glib::ustring&, const Parser::AttributeMap&)
{}
void Parser::on_end_element(ParseContext&, const Glib::ustring&)
{}
void Parser::on_text(ParseContext&, const Glib::ustring&)
{}
void Parser::on_passthrough(ParseContext&, const Glib::ustring&)
{}
void Parser::on_error(ParseContext&, const MarkupError&)
{}
/**** Glib::Markup::ParseContext *******************************************/
ParseContext::ParseContext(Parser& parser, ParseFlags flags)
:
parser_ (&parser),
gobject_ (g_markup_parse_context_new(&ParserCallbacks::vfunc_table, (GMarkupParseFlags) flags,
this, &ParseContext::destroy_notify_callback))
{}
ParseContext::~ParseContext()
{
parser_ = 0;
g_markup_parse_context_free(gobject_);
}
void ParseContext::parse(const Glib::ustring& text)
{
GError* error = 0;
g_markup_parse_context_parse(gobject_, text.data(), text.bytes(), &error);
if(error)
Glib::Error::throw_exception(error);
}
void ParseContext::parse(const char* text_begin, const char* text_end)
{
GError* error = 0;
g_markup_parse_context_parse(gobject_, text_begin, text_end - text_begin, &error);
if(error)
Glib::Error::throw_exception(error);
}
void ParseContext::end_parse()
{
GError* error = 0;
g_markup_parse_context_end_parse(gobject_, &error);
if(error)
Glib::Error::throw_exception(error);
}
Glib::ustring ParseContext::get_element() const
{
const char *const element_name = g_markup_parse_context_get_element(gobject_);
return (element_name) ? Glib::ustring(element_name) : Glib::ustring();
}
int ParseContext::get_line_number() const
{
int line_number = 0;
g_markup_parse_context_get_position(gobject_, &line_number, 0);
return line_number;
}
int ParseContext::get_char_number() const
{
int char_number = 0;
g_markup_parse_context_get_position(gobject_, 0, &char_number);
return char_number;
}
// static
void ParseContext::destroy_notify_callback(void* data)
{
ParseContext *const self = static_cast<ParseContext*>(data);
// Detect premature destruction.
g_return_if_fail(self->parser_ == 0);
}
} // namespace Markup
} // namespace Glib
namespace
{
} // anonymous namespace
Glib::MarkupError::MarkupError(Glib::MarkupError::Code error_code, const Glib::ustring& error_message)
:
Glib::Error (G_MARKUP_ERROR, error_code, error_message)
{}
Glib::MarkupError::MarkupError(GError* gobject)
:
Glib::Error (gobject)
{}
Glib::MarkupError::Code Glib::MarkupError::code() const
{
return static_cast<Code>(Glib::Error::code());
}
void Glib::MarkupError::throw_func(GError* gobject)
{
throw Glib::MarkupError(gobject);
}

View file

@ -1,420 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_MARKUP_H
#define _GLIBMM_MARKUP_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/error.h>
#include <sigc++/sigc++.h>
#include <map>
#include <glibmmconfig.h>
GLIBMM_USING_STD(map)
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GMarkupParseContext GMarkupParseContext; }
#endif
namespace Glib
{
/** @defgroup Markup Simple XML Subset Parser
*
* The Glib::Markup parser is intended to parse a simple markup format that's a
* subset of XML. This is a small, efficient, easy-to-use parser. It should not
* be used if you expect to interoperate with other applications generating
* full-scale XML. However, it's very useful for application data files, config
* files, etc. where you know your application will be the only one writing the
* file. Full-scale XML parsers should be able to parse the subset used by
* Glib::Markup parser, so you can easily migrate to full-scale XML at a later
* time if the need arises.
*
* Glib::Markup is not guaranteed to signal an error on all invalid XML;
* the parser may accept documents that an XML parser would not. However,
* invalid XML documents are not considered valid Glib::Markup documents.
*
* @par Simplifications to XML include:
*
* - Only UTF-8 encoding is allowed.
* - No user-defined entities.
* - Processing instructions, comments and the doctype declaration are "passed
* through" but are not interpreted in any way.
* - No DTD or validation.
*
* @par The markup format does support:
*
* - Elements
* - Attributes
* - 5 standard entities: <tt>\&amp; \&lt; \&gt; \&quot; \&apos;</tt>
* - Character references
* - Sections marked as <tt>CDATA</tt>
*
* @{
*/
/** %Exception class for markup parsing errors.
*/
class MarkupError : public Glib::Error
{
public:
enum Code
{
BAD_UTF8,
EMPTY,
PARSE,
UNKNOWN_ELEMENT,
UNKNOWN_ATTRIBUTE,
INVALID_CONTENT
};
MarkupError(Code error_code, const Glib::ustring& error_message);
explicit MarkupError(GError* gobject);
Code code() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
private:
static void throw_func(GError* gobject);
friend void wrap_init(); // uses throw_func()
#endif
};
/*! @var MarkupError::Code MarkupError::BAD_UTF8
* Text being parsed was not valid UTF-8.
*/
/*! @var MarkupError::Code MarkupError::EMPTY
* Document contained nothing, or only whitespace.
*/
/*! @var MarkupError::Code MarkupError::PARSE
* Document was ill-formed.
*/
/*! @var MarkupError::Code MarkupError::UNKNOWN_ELEMENT
* This error should be set by Glib::Markup::Parser virtual methods;
* element wasn't known.
*/
/*! @var MarkupError::Code MarkupError::UNKNOWN_ATTRIBUTE
* This error should be set by Glib::Markup::Parser virtual methods;
* attribute wasn't known.
*/
/*! @var MarkupError::Code MarkupError::INVALID_CONTENT
* This error should be set by Glib::Markup::Parser virtual methods;
* something was wrong with contents of the document, e.g. invalid attribute value.
*/
/** @} group Markup */
namespace Markup
{
class ParseContext;
/** @ingroup Markup */
typedef Glib::MarkupError Error;
/** Escapes text so that the markup parser will parse it verbatim.
* Less than, greater than, ampersand, etc. are replaced with the corresponding
* entities. This function would typically be used when writing out a file to
* be parsed with the markup parser.
* @ingroup Markup
* @param text Some valid UTF-8 text.
* @return Escaped text.
*/
Glib::ustring escape_text(const Glib::ustring& text);
/** @addtogroup glibmmEnums Enums and Flags */
/** There are no flags right now. Pass <tt>Glib::Markup::ParseFlags(0)</tt> for
* the flags argument to all functions (this should be the default argument
* anyway).
* @ingroup glibmmEnums
* @par Bitwise operators:
* <tt>%ParseFlags operator|(ParseFlags, ParseFlags)</tt><br>
* <tt>%ParseFlags operator&(ParseFlags, ParseFlags)</tt><br>
* <tt>%ParseFlags operator^(ParseFlags, ParseFlags)</tt><br>
* <tt>%ParseFlags operator~(ParseFlags)</tt><br>
* <tt>%ParseFlags& operator|=(ParseFlags&, ParseFlags)</tt><br>
* <tt>%ParseFlags& operator&=(ParseFlags&, ParseFlags)</tt><br>
* <tt>%ParseFlags& operator^=(ParseFlags&, ParseFlags)</tt><br>
*/
enum ParseFlags
{
DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0
};
/** @ingroup glibmmEnums */
inline ParseFlags operator|(ParseFlags lhs, ParseFlags rhs)
{ return static_cast<ParseFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline ParseFlags operator&(ParseFlags lhs, ParseFlags rhs)
{ return static_cast<ParseFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline ParseFlags operator^(ParseFlags lhs, ParseFlags rhs)
{ return static_cast<ParseFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline ParseFlags operator~(ParseFlags flags)
{ return static_cast<ParseFlags>(~static_cast<unsigned>(flags)); }
/** @ingroup glibmmEnums */
inline ParseFlags& operator|=(ParseFlags& lhs, ParseFlags rhs)
{ return (lhs = static_cast<ParseFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline ParseFlags& operator&=(ParseFlags& lhs, ParseFlags rhs)
{ return (lhs = static_cast<ParseFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline ParseFlags& operator^=(ParseFlags& lhs, ParseFlags rhs)
{ return (lhs = static_cast<ParseFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
/*! @var Markup::ParseFlags DO_NOT_USE_THIS_UNSUPPORTED_FLAG
* Flag you should not use.
*/
/** Binary predicate used by Markup::Parser::AttributeMap.
* @ingroup Markup
* Unlike <tt>operator<(const ustring& lhs, const ustring& rhs)</tt>
* which would be used by the default <tt>std::less<></tt> predicate,
* the AttributeKeyLess predicate is locale-independent. This is both
* more correct and much more efficient.
*/
class AttributeKeyLess
{
public:
typedef Glib::ustring first_argument_type;
typedef Glib::ustring second_argument_type;
typedef bool result_type;
bool operator()(const Glib::ustring& lhs, const Glib::ustring& rhs) const;
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS
class ParserCallbacks;
#endif
/** The abstract markup parser base class.
* @ingroup Markup
* To implement a parser for your markup format, derive from
* Glib::Markup::Parser and implement the virtual methods.
*
* You don't have to override all of the virtual methods. If a particular
* method is not implement the data passed to it will be ignored. Except for
* the error method, any of these callbacks can throw an error exception; in
* particular the MarkupError::UNKNOWN_ELEMENT,
* MarkupError::UNKNOWN_ATTRIBUTE, and MarkupError::INVALID_CONTENT errors
* are intended to be thrown from these overridden methods. If you throw an
* error from a method, Glib::Markup::ParseContext::parse() will report that
* error back to its caller.
*/
class Parser : public sigc::trackable
{
public:
typedef std::map<Glib::ustring, Glib::ustring, Glib::Markup::AttributeKeyLess> AttributeMap;
virtual ~Parser() = 0;
protected:
/** Constructs a Parser object.
* Note that Markup::Parser is an abstract class which can't be instantiated
* directly. To implement the parser for your markup format, derive from
* Markup::Parser and implement the virtual methods.
*/
Parser();
/** Called for open tags <tt>\<foo bar="baz"\></tt>.
* This virtual method is invoked when the opening tag of an element is seen.
* @param context The Markup::ParseContext object the parsed data belongs to.
* @param element_name The name of the element.
* @param attributes A map of attribute name/value pairs.
* @throw Glib::MarkupError An exception <em>you</em> should throw if
* something went wrong, for instance if an unknown attribute name was
* encountered. In particular the MarkupError::UNKNOWN_ELEMENT,
* MarkupError::UNKNOWN_ATTRIBUTE, and MarkupError::INVALID_CONTENT
* errors are intended to be thrown from user-implemented methods.
*/
virtual void on_start_element(ParseContext& context,
const Glib::ustring& element_name,
const AttributeMap& attributes);
/** Called for close tags <tt>\</foo\></tt>.
* This virtual method is invoked when the closing tag of an element is seen.
* @param context The Markup::ParseContext object the parsed data belongs to.
* @param element_name The name of the element.
* @throw Glib::MarkupError An exception <em>you</em> should throw if
* something went wrong, for instance if an unknown attribute name was
* encountered. In particular the MarkupError::UNKNOWN_ELEMENT,
* MarkupError::UNKNOWN_ATTRIBUTE, and MarkupError::INVALID_CONTENT
* errors are intended to be thrown from user-implemented methods.
*/
virtual void on_end_element(ParseContext& context, const Glib::ustring& element_name);
/** Called for character data.
* This virtual method is invoked when some text is seen (text is always
* inside an element).
* @param context The Markup::ParseContext object the parsed data belongs to.
* @param text The parsed text in UTF-8 encoding.
* @throw Glib::MarkupError An exception <em>you</em> should throw if
* something went wrong, for instance if an unknown attribute name was
* encountered. In particular the MarkupError::UNKNOWN_ELEMENT,
* MarkupError::UNKNOWN_ATTRIBUTE, and MarkupError::INVALID_CONTENT
* errors are intended to be thrown from user-implemented methods.
*/
virtual void on_text(ParseContext& context, const Glib::ustring& text);
/** Called for strings that should be re-saved verbatim in this same
* position, but are not otherwise interpretable.
* This virtual method is invoked for comments, processing instructions and
* doctype declarations; if you're re-writing the parsed document, write the
* passthrough text back out in the same position.
* @param context The Markup::ParseContext object the parsed data belongs to.
* @param passthrough_text The text that should be passed through.
* @throw Glib::MarkupError An exception <em>you</em> should throw if
* something went wrong, for instance if an unknown attribute name was
* encountered. In particular the MarkupError::UNKNOWN_ELEMENT,
* MarkupError::UNKNOWN_ATTRIBUTE, and MarkupError::INVALID_CONTENT
* errors are intended to be thrown from user-implemented methods.
*/
virtual void on_passthrough(ParseContext& context, const Glib::ustring& passthrough_text);
/** Called on error, including one thrown by an overridden virtual method.
* @param context The Markup::ParseContext object the parsed data belongs to.
* @param error A MarkupError object with detailed information about the error.
*/
virtual void on_error(ParseContext& context, const MarkupError& error);
private:
// noncopyable
Parser(const Parser&);
Parser& operator=(const Parser&);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
friend class Glib::Markup::ParserCallbacks;
#endif
};
/** A parse context is used to parse marked-up documents.
* @ingroup Markup
* You can feed any number of documents into a context, as long as no errors
* occur; once an error occurs, the parse context can't continue to parse text
* (you have to destroy it and create a new parse context).
*/
class ParseContext : public sigc::trackable
{
public:
/** Creates a new parse context.
* @param parser A Markup::Parser instance.
* @param flags Bitwise combination of Markup::ParseFlags.
*/
explicit ParseContext(Parser& parser, ParseFlags flags = ParseFlags(0));
virtual ~ParseContext();
/** Feed some data to the ParseContext.
* The data need not be valid UTF-8; an error will be signalled if it's
* invalid. The data need not be an entire document; you can feed a document
* into the parser incrementally, via multiple calls to this function.
* Typically, as you receive data from a network connection or file, you feed
* each received chunk of data into this function, aborting the process if an
* error occurs. Once an error is reported, no further data may be fed to the
* ParseContext; all errors are fatal.
* @param text Chunk of text to parse.
* @throw Glib::MarkupError
*/
void parse(const Glib::ustring& text);
/** Feed some data to the ParseContext.
* The data need not be valid UTF-8; an error will be signalled if it's
* invalid. The data need not be an entire document; you can feed a document
* into the parser incrementally, via multiple calls to this function.
* Typically, as you receive data from a network connection or file, you feed
* each received chunk of data into this function, aborting the process if an
* error occurs. Once an error is reported, no further data may be fed to the
* ParseContext; all errors are fatal.
* @param text_begin Begin of chunk of text to parse.
* @param text_end End of chunk of text to parse.
* @throw Glib::MarkupError
*/
void parse(const char* text_begin, const char* text_end);
/** Signals to the ParseContext that all data has been fed into the parse
* context with parse(). This method reports an error if the document isn't
* complete, for example if elements are still open.
* @throw Glib::MarkupError
*/
void end_parse();
/** Retrieves the name of the currently open element.
* @return The name of the currently open element, or <tt>""</tt>.
*/
Glib::ustring get_element() const;
/** Retrieves the current line number.
* Intended for use in error messages; there are no strict semantics for what
* constitutes the "current" line number other than "the best number we could
* come up with for error messages."
*/
int get_line_number() const;
/** Retrieves the number of the current character on the current line.
* Intended for use in error messages; there are no strict semantics for what
* constitutes the "current" character number other than "the best number we
* could come up with for error messages."
*/
int get_char_number() const;
Parser* get_parser() { return parser_; }
const Parser* get_parser() const { return parser_; }
#ifndef DOXYGEN_SHOULD_SKIP_THIS
GMarkupParseContext* gobj() { return gobject_; }
const GMarkupParseContext* gobj() const { return gobject_; }
#endif
private:
Markup::Parser* parser_;
GMarkupParseContext* gobject_;
// noncopyable
ParseContext(const ParseContext&);
ParseContext& operator=(const ParseContext&);
static void destroy_notify_callback(void* data);
};
} // namespace Markup
} // namespace Glib
#endif /* _GLIBMM_MARKUP_H */

View file

@ -1,243 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <cstddef>
#include <cstring>
#include <glibmm/miscutils.h>
#include <glibmm/utility.h>
#include <glib.h>
namespace Glib
{
Glib::ustring get_application_name()
{
if(const char *const application_name = g_get_application_name())
{
// Lets be a bit more strict than the original GLib function and ensure
// we always return valid UTF-8. gtkmm coders surely won't expect invalid
// UTF-8 in a Glib::ustring returned by a glibmm function.
if(g_utf8_validate(application_name, -1, 0))
return Glib::ustring(application_name);
char *const appname_utf8 = g_filename_to_utf8(application_name, -1, 0, 0, 0);
g_return_val_if_fail(appname_utf8 != 0, "");
return Glib::ustring(ScopedPtr<char>(appname_utf8).get());
}
return Glib::ustring();
}
void set_application_name(const Glib::ustring& application_name)
{
g_set_application_name(application_name.c_str());
}
std::string get_prgname()
{
const char *const prgname = g_get_prgname();
return (prgname) ? std::string(prgname) : std::string();
}
void set_prgname(const std::string& prgname)
{
g_set_prgname(prgname.c_str());
}
std::string getenv(const std::string& variable, bool& found)
{
const char *const value = g_getenv(variable.c_str());
found = (value != 0);
return (value) ? std::string(value) : std::string();
}
std::string getenv(const std::string& variable)
{
const char *const value = g_getenv(variable.c_str());
return (value) ? std::string(value) : std::string();
}
bool setenv(const std::string& variable, const std::string& value, bool overwrite)
{
return g_setenv(variable.c_str(), value.c_str(), overwrite);
}
void unsetenv(const std::string& variable)
{
g_unsetenv(variable.c_str());
}
std::string get_user_name()
{
return std::string(g_get_user_name());
}
std::string get_real_name()
{
return std::string(g_get_real_name());
}
std::string get_home_dir()
{
return std::string(g_get_home_dir());
}
std::string get_tmp_dir()
{
return std::string(g_get_tmp_dir());
}
std::string get_current_dir()
{
const ScopedPtr<char> buf (g_get_current_dir());
return std::string(buf.get());
}
bool path_is_absolute(const std::string& filename)
{
return g_path_is_absolute(filename.c_str());
}
std::string path_skip_root(const std::string& filename)
{
// g_path_skip_root() returns a pointer _into_ the argument string,
// or NULL if there was no root component.
if(const char *const ptr = g_path_skip_root(filename.c_str()))
return std::string(ptr);
else
return std::string();
}
std::string path_get_basename(const std::string& filename)
{
const ScopedPtr<char> buf (g_path_get_basename(filename.c_str()));
return std::string(buf.get());
}
std::string path_get_dirname(const std::string& filename)
{
const ScopedPtr<char> buf (g_path_get_dirname(filename.c_str()));
return std::string(buf.get());
}
std::string build_filename(const Glib::ArrayHandle<std::string>& elements)
{
return build_path(G_DIR_SEPARATOR_S, elements);
}
std::string build_filename(const std::string& elem1, const std::string& elem2)
{
const char *const elements[] = { elem1.c_str(), elem2.c_str(), 0 };
return build_path(G_DIR_SEPARATOR_S, elements);
}
/* Yes, this reimplements the functionality of g_build_path() -- because
* it takes a varargs list, and calling it several times would result
* in different behaviour.
*/
std::string build_path(const std::string& separator, const Glib::ArrayHandle<std::string>& elements)
{
std::string result;
result.reserve(256); //TODO: Explain why this magic number is useful. murrayc
const char *const sep = separator.c_str();
const size_t seplen = separator.length();
bool is_first = true;
bool have_leading = false;
const char* single_element = 0;
const char* last_trailing = 0;
const char *const *const elements_begin = elements.data();
const char *const *const elements_end = elements_begin + elements.size();
for(const char *const * pelement = elements_begin; pelement != elements_end; ++pelement)
{
const char* start = *pelement;
if(*start == '\0')
continue; // ignore empty elements
if(seplen != 0)
{
while(strncmp(start, sep, seplen) == 0)
start += seplen;
}
const char* end = start + strlen(start);
if(seplen != 0)
{
while(end >= start + seplen && strncmp(end - seplen, sep, seplen) == 0)
end -= seplen;
last_trailing = end;
while(last_trailing >= *pelement + seplen && strncmp(last_trailing - seplen, sep, seplen) == 0)
last_trailing -= seplen;
if(!have_leading)
{
// If the leading and trailing separator strings are in the
// same element and overlap, the result is exactly that element.
//
if(last_trailing <= start)
single_element = *pelement;
result.append(*pelement, start);
have_leading = true;
}
else
single_element = 0;
}
if(end == start)
continue;
if(!is_first)
result += separator;
result.append(start, end);
is_first = false;
}
if(single_element)
result = single_element;
else if(last_trailing)
result += last_trailing;
return result;
}
std::string find_program_in_path(const std::string& program)
{
if(char *const buf = g_find_program_in_path(program.c_str()))
return std::string(ScopedPtr<char>(buf).get());
else
return std::string();
}
} // namespace Glib

View file

@ -1,272 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_MISCUTILS_H
#define _GLIBMM_MISCUTILS_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/arrayhandle.h>
#include <glibmm/ustring.h>
namespace Glib
{
/** @defgroup MiscUtils Miscellaneous Utility Functions
* Miscellaneous Utility Functions -- a selection of portable utility functions.
* @{
*/
/** Gets a human-readable name for the application,
* as set by Glib::set_application_name().
* This name should be localized if possible, and is intended for display to
* the user. Contrast with Glib::get_prgname(), which gets a non-localized
* name. If Glib::set_application_name() has not been called, returns the
* result of Glib::get_prgname() (which may be empty if Glib::set_prgname()
* has also not been called).
*
* @return Human-readable application name. May return <tt>""</tt>.
*/
Glib::ustring get_application_name();
/** Sets a human-readable name for the application.
* This name should be localized if possible, and is intended for display to
* the user. Contrast with Glib::set_prgname(), which sets a non-localized
* name. Glib::set_prgname() will be called automatically by
* <tt>gtk_init()</tt>, but Glib::set_application_name() will not.
*
* Note that for thread safety reasons, this function can only be called once.
*
* The application name will be used in contexts such as error messages,
* or when displaying an application's name in the task list.
*
* @param application_name Localized name of the application.
*/
void set_application_name(const Glib::ustring& application_name);
/** Gets the name of the program.
* If you are using GDK or GTK+ the program name is set in <tt>gdk_init()</tt>,
* which is called by <tt>gtk_init()</tt>. The program name is found by taking
* the last component of <tt>argv[0]</tt>.
* @return The name of the program.
*/
std::string get_prgname();
/** Sets the name of the program.
* @param prgname The name of the program.
*/
void set_prgname(const std::string& prgname);
/** Returns the value of an environment variable. The name and value
* are in the GLib file name encoding. On Unix, this means the actual
* bytes which might or might not be in some consistent character set
* and encoding. On Windows, it is in UTF-8. On Windows, in case the
* environment variable's value contains references to other
* environment variables, they are expanded.
*
* @param variable The environment variable to get.
* @retval found <tt>true</tt> Whether the environment variable has been found.
* @return The value of the environment variable, or <tt>""</tt> if not found.
*/
std::string getenv(const std::string& variable, bool& found);
/** Returns the value of an environment variable. The name and value
* are in the GLib file name encoding. On Unix, this means the actual
* bytes which might or might not be in some consistent character set
* and encoding. On Windows, it is in UTF-8. On Windows, in case the
* environment variable's value contains references to other
* environment variables, they are expanded.
*
* @param variable The environment variable to get.
* @return The value of the environment variable, or <tt>""</tt> if not found.
*/
std::string getenv(const std::string& variable);
/** Sets an environment variable. Both the variable's name and value
* should be in the GLib file name encoding. On Unix, this means that
* they can be any sequence of bytes. On Windows, they should be in
* UTF-8.
*
* Note that on some systems, when variables are overwritten, the memory
* used for the previous variables and its value isn't reclaimed.
*
* @param variable The environment variable to set. It must not contain '='.
* @param value The value to which the variable should be set.
* @param overwrite Whether to change the variable if it already exists.
* @result false if the environment variable couldn't be set.
*/
bool setenv(const std::string& variable, const std::string& value, bool overwrite = true);
/** Removes an environment variable from the environment.
*
* Note that on some systems, when variables are overwritten, the memory
* used for the previous variables and its value isn't reclaimed.
* Furthermore, this function can't be guaranteed to operate in a
* threadsafe way.
*
* @param variable: the environment variable to remove. It must not contain '='.
**/
void unsetenv(const std::string& variable);
/** Gets the user name of the current user.
* @return The name of the current user.
*/
std::string get_user_name();
/** Gets the real name of the user.
* This usually comes from the user's entry in the <tt>passwd</tt> file.
* @return The user's real name.
*/
std::string get_real_name();
/** Gets the current user's home directory.
* @return The current user's home directory.
*/
std::string get_home_dir();
/** Gets the directory to use for temporary files.
* This is found from inspecting the environment variables <tt>TMPDIR</tt>,
* <tt>TMP</tt>, and <tt>TEMP</tt> in that order. If none of those are defined
* <tt>"/tmp"</tt> is returned on UNIX and <tt>"C:\\"</tt> on Windows.
* @return The directory to use for temporary files.
*/
std::string get_tmp_dir();
/** Gets the current directory.
* @return The current directory.
*/
std::string get_current_dir();
/** Returns @c true if the given @a filename is an absolute file name, i.e.\ it
* contains a full path from the root directory such as <tt>"/usr/local"</tt>
* on UNIX or <tt>"C:\\windows"</tt> on Windows systems.
* @param filename A file name.
* @return Whether @a filename is an absolute path.
*/
bool path_is_absolute(const std::string& filename);
/** Returns the remaining part of @a filename after the root component,
* i.e.\ after the <tt>"/"</tt> on UNIX or <tt>"C:\\"</tt> on Windows.
* If @a filename is not an absolute path, <tt>""</tt> will be returned.
* @param filename A file name.
* @return The file name without the root component, or <tt>""</tt>.
*/
std::string path_skip_root(const std::string& filename);
/** Gets the name of the file without any leading directory components.
* @param filename The name of the file.
* @return The name of the file without any leading directory components.
*/
std::string path_get_basename(const std::string& filename);
/** Gets the directory components of a file name.
* If the file name has no directory components <tt>"."</tt> is returned.
* @param filename The name of the file.
* @return The directory components of the file.
*/
std::string path_get_dirname(const std::string& filename);
/** Creates a filename from a series of elements using the correct
* separator for filenames.
* This function behaves identically to Glib::build_path(G_DIR_SEPARATOR_S,
* elements). No attempt is made to force the resulting filename to be an
* absolute path. If the first element is a relative path, the result will
* be a relative path.
* @param elements A container holding the elements of the path to build.
* Any STL compatible container type is accepted.
* @return The resulting path.
*/
std::string build_filename(const Glib::ArrayHandle<std::string>& elements);
/** Creates a filename from two elements using the correct separator for filenames.
* No attempt is made to force the resulting filename to be an absolute path.
* If the first element is a relative path, the result will be a relative path.
* @param elem1 First path element.
* @param elem2 Second path element.
* @return The resulting path.
*/
std::string build_filename(const std::string& elem1, const std::string& elem2);
/** Creates a path from a series of elements using @a separator as the
* separator between elements.
*
* At the boundary between two elements, any trailing occurrences of
* @a separator in the first element, or leading occurrences of @a separator
* in the second element are removed and exactly one copy of the separator is
* inserted.
*
* Empty elements are ignored.
*
* The number of leading copies of the separator on the result is
* the same as the number of leading copies of the separator on
* the first non-empty element.
*
* The number of trailing copies of the separator on the result is the same
* as the number of trailing copies of the separator on the last non-empty
* element. (Determination of the number of trailing copies is done without
* stripping leading copies, so if the separator is <tt>"ABA"</tt>,
* <tt>"ABABA"</tt> has 1 trailing copy.)
*
* However, if there is only a single non-empty element, and there
* are no characters in that element not part of the leading or
* trailing separators, then the result is exactly the original value
* of that element.
*
* Other than for determination of the number of leading and trailing
* copies of the separator, elements consisting only of copies
* of the separator are ignored.
*
* @param separator A string used to separate the elements of the path.
* @param elements A container holding the elements of the path to build.
* Any STL compatible container type is accepted.
* @return The resulting path.
*/
std::string build_path(const std::string& separator,
const Glib::ArrayHandle<std::string>& elements);
/** Locates the first executable named @a program in the user's path, in the
* same way that <tt>execvp()</tt> would locate it.
* Returns a string with the absolute path name, or <tt>""</tt> if the program
* is not found in the path. If @a program is already an absolute path,
* returns a copy of @a program if @a program exists and is executable, and
* <tt>""</tt> otherwise.
*
* On Windows, if @a program does not have a file type suffix, tries to append
* the suffixes in the <tt>PATHEXT</tt> environment variable (if that doesn't
* exist, the suffixes .com, .exe, and .bat) in turn, and then look for the
* resulting file name in the same way as CreateProcess() would. This means
* first in the directory where the program was loaded from, then in the
* current directory, then in the Windows 32-bit system directory, then in the
* Windows directory, and finally in the directories in the <tt>PATH</tt>
* environment variable. If the program is found, the return value contains
* the full name including the type suffix.
*
* @param program A program name.
* @return An absolute path, or <tt>""</tt>.
*/
std::string find_program_in_path(const std::string& program);
/** @} group MiscUtils */
} // namespace Glib
#endif /* _GLIBMM_FILEUTILS_H */

View file

@ -1,93 +0,0 @@
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <glibmm/module.h>
#include <glibmm/private/module_p.h>
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/utility.h>
#include <gmodule.h>
namespace Glib
{
Module::Module(const std::string& file_name, ModuleFlags flags)
:
gobject_ (g_module_open(file_name.c_str(), (GModuleFlags) flags))
{}
Module::~Module()
{
if(gobject_)
g_module_close(gobject_);
}
Module::operator bool() const
{
return (gobject_ != 0);
}
} // namespace Glib
namespace
{
} // anonymous namespace
namespace Glib
{
bool Module::get_supported()
{
return g_module_supported();
}
void Module::make_resident()
{
g_module_make_resident(gobj());
}
std::string Module::get_last_error()
{
return Glib::convert_const_gchar_ptr_to_stdstring(g_module_error());
}
bool Module::get_symbol(const std::string& symbol_name, void*& symbol) const
{
return g_module_symbol(const_cast<GModule*>(gobj()), symbol_name.c_str(), &(symbol));
}
std::string Module::get_name() const
{
return Glib::convert_const_gchar_ptr_to_stdstring(g_module_name(const_cast<GModule*>(gobj())));
}
std::string Module::build_path(const std::string& directory, const std::string& module_name)
{
return Glib::convert_return_gchar_ptr_to_stdstring(g_module_build_path(directory.c_str(), module_name.c_str()));
}
} // namespace Glib

View file

@ -1,221 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_MODULE_H
#define _GLIBMM_MODULE_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmmconfig.h>
#include <string>
GLIBMM_USING_STD(string)
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GModule GModule; }
#endif
namespace Glib
{
/** @addtogroup glibmmEnums Enums and Flags */
/**
* @ingroup glibmmEnums
* @par Bitwise operators:
* <tt>%ModuleFlags operator|(ModuleFlags, ModuleFlags)</tt><br>
* <tt>%ModuleFlags operator&(ModuleFlags, ModuleFlags)</tt><br>
* <tt>%ModuleFlags operator^(ModuleFlags, ModuleFlags)</tt><br>
* <tt>%ModuleFlags operator~(ModuleFlags)</tt><br>
* <tt>%ModuleFlags& operator|=(ModuleFlags&, ModuleFlags)</tt><br>
* <tt>%ModuleFlags& operator&=(ModuleFlags&, ModuleFlags)</tt><br>
* <tt>%ModuleFlags& operator^=(ModuleFlags&, ModuleFlags)</tt><br>
*/
enum ModuleFlags
{
MODULE_BIND_LAZY = 1 << 0,
MODULE_BIND_MASK = 0x01
};
/** @ingroup glibmmEnums */
inline ModuleFlags operator|(ModuleFlags lhs, ModuleFlags rhs)
{ return static_cast<ModuleFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline ModuleFlags operator&(ModuleFlags lhs, ModuleFlags rhs)
{ return static_cast<ModuleFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline ModuleFlags operator^(ModuleFlags lhs, ModuleFlags rhs)
{ return static_cast<ModuleFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
/** @ingroup glibmmEnums */
inline ModuleFlags operator~(ModuleFlags flags)
{ return static_cast<ModuleFlags>(~static_cast<unsigned>(flags)); }
/** @ingroup glibmmEnums */
inline ModuleFlags& operator|=(ModuleFlags& lhs, ModuleFlags rhs)
{ return (lhs = static_cast<ModuleFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline ModuleFlags& operator&=(ModuleFlags& lhs, ModuleFlags rhs)
{ return (lhs = static_cast<ModuleFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
/** @ingroup glibmmEnums */
inline ModuleFlags& operator^=(ModuleFlags& lhs, ModuleFlags rhs)
{ return (lhs = static_cast<ModuleFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
//TODO: Replace get_last_error() with exceptions?
//Provide operator()?
/** Dynamic Loading of Modules
* These functions provide a portable way to dynamically load object
* files (commonly known as 'plug-ins'). The current implementation
* supports all systems that provide an implementation of dlopen()
* (e.g. Linux/Sun), as well as HP-UX via its shl_load() mechanism,
* and Windows platforms via DLLs.
*/
class Module
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef Module CppObjectType;
typedef GModule BaseObjectType;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
private:
public:
/** Opens a module.
*
* First of all it tries to open file_name as a module. If that
* fails and file_name has the ".la"-suffix (and is a libtool
* archive) it tries to open the corresponding module. If that fails
* and it doesn't have the proper module suffix for the platform
* (G_MODULE_SUFFIX), this suffix will be appended and the
* corresponding module will be opended. If that fails and file_name
* doesn't have the ".la"-suffix, this suffix is appended and
* it tries to open the corresponding module.
*
* Use operator bool() to see whether the operation succeeded. For instance,
* @code
* Glib::Module module("plugins/helloworld");
* if(module)
* {
* void* func = 0;
* bool found = get_symbol("some_function", func);
* }
* @endcode
*
* @param file_name The library filename to open
* @param flags Flags to configure the load process
*/
explicit Module(const std::string& file_name, ModuleFlags flags = ModuleFlags(0));
/** Close a module. The module will be removed from memory, unless
* <tt>make_resident</tt> has been called.
*/
virtual ~Module();
/** Check whether the module was found.
*/
operator bool() const;
/** Checks if modules are supported on the current platform.
* @returns true if available, false otherwise
*/
static bool get_supported();
/** Ensures that a module will never be unloaded. Any calls to the
* Glib::Module destructor will not unload the module.
*/
void make_resident();
/** Gets a string describing the last module error.
* @returns The error string
*/
static std::string get_last_error();
/** Gets a symbol pointer from the module.
* @param symbol_name The name of the symbol to lookup
* @param symbol A pointer to set to the symbol
* @returns True if the symbol was found, false otherwise.
*/
bool get_symbol(const std::string& symbol_name, void*& symbol) const;
/** Get the name of the module.
* @returns The name of the module
*/
std::string get_name() const;
/** A portable way to build the filename of a module. The
* platform-specific prefix and suffix are added to the filename, if
* needed, and the result is added to the directory, using the
* correct separator character.
*
* The directory should specify the directory where the module can
* be found. It can be an empty string to indicate that the
* module is in a standard platform-specific directory, though this
* is not recommended since the wrong module may be found.
*
* For example, calling <tt>g_module_build_path()</tt> on a Linux
* system with a directory of <tt>/lib</tt> and a module_name of
* "mylibrary" will return <tt>/lib/libmylibrary.so</tt>. On a
* Windows system, using <tt>\\Windows</tt> as the directory it will
* return <tt>\\Windows\\mylibrary.dll</tt>.
*
* @param directory The directory the module is in
* @param module_name The name of the module
* @returns The system-specific filename of the module
*/
// TODO: add an override which doesn't take a directory
// TODO: check what happens when directory is ""
static std::string build_path(const std::string& directory, const std::string& module_name);
GModule* gobj() { return gobject_; }
const GModule* gobj() const { return gobject_; }
protected:
GModule* gobject_;
private:
// noncopyable
Module(const Module&);
Module& operator=(const Module&);
};
} // namespace Glib
#endif /* _GLIBMM_MODULE_H */

View file

@ -1,312 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* Copyright 1998-2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/object.h>
#include <glibmm/private/object_p.h>
#include <glibmm/property.h>
#include <glib.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.h>
#include <cstdarg>
#include <cstring>
//Weak references:
//I'm not sure what the point of these are apart from being a hacky way out of circular references,
//but maybe we could make it easier to use them by making a Java Reference Object -style class like so:
// Glib::WeakRef<SomeDerivedObject> weakrefSomeObject(object1);
// ...
// if(weakrefSomeObject->isStillAlive())
// {
// weakrefSomeObject->some_method();
// }
// else
// {
// //Deal with it, maybe recreating the object.
// }
//
// Without this, the coder has to define his own signal handler which sets his own isStillAlive boolean.
// weakrefSomeObject<> could still have its own signal_destroyed signal so that coders can choose to deal
// with the destruction as soon as it happens instead of just checking later before they try to use it.
namespace Glib
{
ConstructParams::ConstructParams(const Glib::Class& glibmm_class_)
:
glibmm_class (glibmm_class_),
n_parameters (0),
parameters (0)
{}
/* The implementation is mostly copied from gobject.c, with some minor tweaks.
* Basically, it looks up each property name to get its GType, and then uses
* G_VALUE_COLLECT() to store the varargs argument in a GValue of the correct
* type.
*/
ConstructParams::ConstructParams(const Glib::Class& glibmm_class_,
const char* first_property_name, ...)
:
glibmm_class (glibmm_class_),
n_parameters (0),
parameters (0)
{
va_list var_args;
va_start(var_args, first_property_name);
GObjectClass *const g_class =
static_cast<GObjectClass*>(g_type_class_ref(glibmm_class.get_type()));
unsigned int n_alloced_params = 0;
char* collect_error = 0; // output argument of G_VALUE_COLLECT()
for(const char* name = first_property_name;
name != 0;
name = va_arg(var_args, char*))
{
GParamSpec *const pspec = g_object_class_find_property(g_class, name);
if(!pspec)
{
g_warning("Glib::ConstructParams::ConstructParams(): "
"object class `%s' has no property named `%s'",
g_type_name(glibmm_class.get_type()), name);
break;
}
if(n_parameters >= n_alloced_params)
parameters = g_renew(GParameter, parameters, n_alloced_params += 8);
GParameter& param = parameters[n_parameters];
param.name = name;
param.value.g_type = 0;
// Fill the GValue with the current vararg, and move on to the next one.
g_value_init(&param.value, G_PARAM_SPEC_VALUE_TYPE(pspec));
G_VALUE_COLLECT(&param.value, var_args, 0, &collect_error);
if(collect_error)
{
g_warning("Glib::ConstructParams::ConstructParams(): %s", collect_error);
g_free(collect_error);
g_value_unset(&param.value);
break;
}
++n_parameters;
}
g_type_class_unref(g_class);
va_end(var_args);
}
ConstructParams::~ConstructParams()
{
while(n_parameters > 0)
g_value_unset(&parameters[--n_parameters].value);
g_free(parameters);
}
/*
* Some compilers require the existance of a copy constructor in certain
* usage contexts. This implementation is fully functional, but unlikely
* to be ever actually called due to optimization.
*/
ConstructParams::ConstructParams(const ConstructParams& other)
:
glibmm_class (other.glibmm_class),
n_parameters (other.n_parameters),
parameters (g_new(GParameter, n_parameters))
{
for(unsigned int i = 0; i < n_parameters; ++i)
{
parameters[i].name = other.parameters[i].name;
parameters[i].value.g_type = 0;
g_value_init(&parameters[i].value, G_VALUE_TYPE(&other.parameters[i].value));
g_value_copy(&other.parameters[i].value, &parameters[i].value);
}
}
/**** Glib::Object_Class ***************************************************/
const Glib::Class& Object_Class::init()
{
if(!gtype_)
{
class_init_func_ = &Object_Class::class_init_function;
register_derived_type(G_TYPE_OBJECT);
}
return *this;
}
void Object_Class::class_init_function(void*, void*)
{}
Object* Object_Class::wrap_new(GObject* object)
{
return new Object(object);
}
/**** Glib::Object *********************************************************/
// static data
Object::CppClassType Object::object_class_;
Object::Object()
{
// This constructor is ONLY for derived classes that are NOT wrappers of
// derived C objects. For instance, Gtk::Object should NOT use this
// constructor.
//g_warning("Object::Object(): Did you really mean to call this?");
// If Glib::ObjectBase has been constructed with a custom typeid, we derive
// a new GType on the fly. This works because ObjectBase is a virtual base
// class, therefore its constructor is always executed first.
GType object_type = G_TYPE_OBJECT; // the default -- not very useful
if(custom_type_name_ && !is_anonymous_custom_())
{
object_class_.init();
object_type = object_class_.clone_custom_type(custom_type_name_); //A type that is derived from GObject.
}
// Create a new GObject with the specified array of construct properties.
// This works with custom types too, since those inherit the properties of
// their base class.
void *const new_object = g_object_newv(object_type, 0, 0);
// Connect the GObject and Glib::Object instances.
ObjectBase::initialize(static_cast<GObject*>(new_object));
}
Object::Object(const Glib::ConstructParams& construct_params)
{
GType object_type = construct_params.glibmm_class.get_type();
// If Glib::ObjectBase has been constructed with a custom typeid, we derive
// a new GType on the fly. This works because ObjectBase is a virtual base
// class, therefore its constructor is always executed first.
if(custom_type_name_ && !is_anonymous_custom_())
object_type = construct_params.glibmm_class.clone_custom_type(custom_type_name_);
// Create a new GObject with the specified array of construct properties.
// This works with custom types too, since those inherit the properties of
// their base class.
void *const new_object = g_object_newv(
object_type, construct_params.n_parameters, construct_params.parameters);
// Connect the GObject and Glib::Object instances.
ObjectBase::initialize(static_cast<GObject*>(new_object));
}
Object::Object(GObject* castitem)
{
//I disabled this check because libglademm really does need to do this.
//(actually it tells libglade to instantiate "gtkmm_" types.
//The 2nd instance bug will be caught elsewhere anyway.
/*
static const char gtkmm_prefix[] = "gtkmm__";
const char *const type_name = G_OBJECT_TYPE_NAME(castitem);
if(strncmp(type_name, gtkmm_prefix, sizeof(gtkmm_prefix) - 1) == 0)
{
g_warning("Glib::Object::Object(GObject*): "
"An object of type '%s' was created directly via g_object_new(). "
"The Object::Object(const Glib::ConstructParams&) constructor "
"should be used instead.\n"
"This could happen if the C instance lived longer than the C++ instance, so that "
"a second C++ instance was created automatically to wrap it. That would be a gtkmm bug that you should report.",
type_name);
}
*/
// Connect the GObject and Glib::Object instances.
ObjectBase::initialize(castitem);
}
Object::~Object()
{
cpp_destruction_in_progress_ = true;
}
/*
RefPtr<Object> Object::create()
{
// Derived classes will actually return RefPtr<>s that contain useful instances.
return RefPtr<Object>();
}
*/
GType Object::get_type()
{
return object_class_.init().get_type();
}
GType Object::get_base_type()
{
return G_TYPE_OBJECT;
}
// Data services
void* Object::get_data(const QueryQuark& id)
{
return g_object_get_qdata(gobj(),id);
}
void Object::set_data(const Quark& id, void* data)
{
g_object_set_qdata(gobj(),id,data);
}
void Object::set_data(const Quark& id, void* data, DestroyNotify destroy)
{
g_object_set_qdata_full(gobj(), id, data, destroy);
}
void Object::remove_data(const QueryQuark& id)
{
// missing in glib??
g_return_if_fail(id.id() > 0);
g_datalist_id_remove_data(&gobj()->qdata, id);
}
void* Object::steal_data(const QueryQuark& id)
{
return g_object_steal_qdata(gobj(), id);
}
} // namespace Glib

View file

@ -1,282 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_OBJECT_H
#define _GLIBMM_OBJECT_H
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/objectbase.h>
#include <glibmm/wrap.h>
#include <glibmm/quark.h>
#include <glibmm/refptr.h>
#include <glibmm/utility.h> /* Could be private, but that would be tedious. */
#include <glibmm/containerhandle_shared.h> //Because its specializations may be here.
#include <glibmm/value.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C"
{
typedef struct _GObject GObject;
typedef struct _GObjectClass GObjectClass;
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
namespace Glib
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
class Class;
class Object_Class;
class GSigConnectionNode;
/* ConstructParams::ConstructParams() takes a varargs list of properties
* and values, like g_object_new() does. This list will then be converted
* to a GParameter array, for use with g_object_newv(). No overhead is
* involved, since g_object_new() is just a wrapper around g_object_newv()
* as well.
*
* The advantage of an auxilary ConstructParams object over g_object_new()
* is that the actual construction is always done in the Glib::Object ctor.
* This allows for neat tricks like easy creation of derived custom types,
* without adding special support to each ctor of every class.
*
* The comments in object.cc and objectbase.cc should explain in detail
* how this works.
*/
class ConstructParams
{
public:
const Glib::Class& glibmm_class;
unsigned int n_parameters;
GParameter* parameters;
explicit ConstructParams(const Glib::Class& glibmm_class_);
ConstructParams(const Glib::Class& glibmm_class_, const char* first_property_name, ...);
~ConstructParams();
// This is only used by the C++ compiler (since g++ 3.4) to create temporary instances.
// Apparently the compiler will actually optimize away the use of this.
// See bug #132300.
ConstructParams(const ConstructParams& other);
private:
// noncopyable
ConstructParams& operator=(const ConstructParams&);
};
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
class Object : virtual public ObjectBase
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef Object CppObjectType;
typedef Object_Class CppClassType;
typedef GObject BaseObjectType;
typedef GObjectClass BaseClassType;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
protected:
Object(); //For use by C++-only sub-types.
explicit Object(const Glib::ConstructParams& construct_params);
explicit Object(GObject* castitem);
virtual ~Object(); //It should only be deleted by the callback.
public:
//static RefPtr<Object> create(); //You must reimplement this in each derived class.
#ifndef DOXYGEN_SHOULD_SKIP_THIS
static GType get_type() G_GNUC_CONST;
static GType get_base_type() G_GNUC_CONST;
#endif
//GObject* gobj_copy(); //Give a ref-ed copy to someone. Use for direct struct access.
// Glib::Objects contain a list<Quark, pair<void*, DestroyNotify> >
// to store run time data added to the object at run time.
//TODO: Use slots instead:
void* get_data(const QueryQuark &key);
void set_data(const Quark &key, void* data);
typedef void (*DestroyNotify) (gpointer data);
void set_data(const Quark &key, void* data, DestroyNotify notify);
void remove_data(const QueryQuark& quark);
// same as remove without notifying
void* steal_data(const QueryQuark& quark);
// convenience functions
//template <class T>
//void set_data_typed(const Quark& quark, const T& data)
// { set_data(quark, new T(data), delete_typed<T>); }
//template <class T>
//T& get_data_typed(const QueryQuark& quark)
// { return *static_cast<T*>(get_data(quark)); }
#ifndef DOXYGEN_SHOULD_SKIP_THIS
private:
friend class Glib::Object_Class;
static CppClassType object_class_;
// noncopyable
Object(const Object&);
Object& operator=(const Object&);
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
// Glib::Object can not be dynamic because it lacks a float state.
//virtual void set_manage();
};
//For some (proably, more spec-compliant) compilers, these specializations must
//be next to the objects that they use.
#ifndef GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION
#ifndef DOXYGEN_SHOULD_SKIP_THIS /* hide the specializations */
namespace Container_Helpers
{
/** Partial specialization for pointers to GObject instances.
* @ingroup ContHelpers
* The C++ type is always a Glib::RefPtr<>.
*/
template <class T>
struct TypeTraits< Glib::RefPtr<T> >
{
typedef Glib::RefPtr<T> CppType;
typedef typename T::BaseObjectType * CType;
typedef typename T::BaseObjectType * CTypeNonConst;
static CType to_c_type (const CppType& ptr) { return Glib::unwrap(ptr); }
static CType to_c_type (CType ptr) { return ptr; }
static CppType to_cpp_type (CType ptr)
{
//return Glib::wrap(ptr, true);
//We copy/paste the wrap() implementation here,
//because we can not use a specific Glib::wrap(CType) overload here,
//because that would be "dependent", and g++ 3.4 does not allow that.
//The specific Glib::wrap() overloads don't do anything special anyway.
GObject* cobj = (GObject*)const_cast<CTypeNonConst>(ptr);
return Glib::RefPtr<T>( dynamic_cast<T*>(Glib::wrap_auto(cobj, true /* take_copy */)) );
//We use dynamic_cast<> in case of multiple inheritance.
}
static void release_c_type (CType ptr)
{
GLIBMM_DEBUG_UNREFERENCE(0, ptr);
g_object_unref(ptr);
}
};
//This confuse the SUN Forte compiler, so we ifdef it out:
#ifdef GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS
/** Partial specialization for pointers to const GObject instances.
* @ingroup ContHelpers
* The C++ type is always a Glib::RefPtr<>.
*/
template <class T>
struct TypeTraits< Glib::RefPtr<const T> >
{
typedef Glib::RefPtr<const T> CppType;
typedef const typename T::BaseObjectType * CType;
typedef typename T::BaseObjectType * CTypeNonConst;
static CType to_c_type (const CppType& ptr) { return Glib::unwrap(ptr); }
static CType to_c_type (CType ptr) { return ptr; }
static CppType to_cpp_type (CType ptr)
{
//return Glib::wrap(ptr, true);
//We copy/paste the wrap() implementation here,
//because we can not use a specific Glib::wrap(CType) overload here,
//because that would be "dependent", and g++ 3.4 does not allow that.
//The specific Glib::wrap() overloads don't do anything special anyway.
GObject* cobj = (GObject*)(ptr);
return Glib::RefPtr<const T>( dynamic_cast<const T*>(Glib::wrap_auto(cobj, true /* take_copy */)) );
//We use dynamic_cast<> in case of multiple inheritance.
}
static void release_c_type (CType ptr)
{
GLIBMM_DEBUG_UNREFERENCE(0, ptr);
g_object_unref(const_cast<CTypeNonConst>(ptr));
}
};
#endif //GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS
} //namespace Container_Helpers
template <class T, class PtrT> inline
PtrT Value_Pointer<T,PtrT>::get_(Glib::Object*) const
{
return dynamic_cast<T*>(get_object());
}
/** Partial specialization for RefPtr<> to Glib::Object.
* @ingroup glibmmValue
*/
template <class T>
class Value< Glib::RefPtr<T> > : public ValueBase_Object
{
public:
typedef Glib::RefPtr<T> CppType;
typedef typename T::BaseObjectType* CType;
static GType value_type() { return T::get_base_type(); }
void set(const CppType& data) { set_object(data.operator->()); }
CppType get() const { return Glib::RefPtr<T>::cast_dynamic(get_object_copy()); }
};
//The SUN Forte Compiler has a problem with this:
#ifdef GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS
/** Partial specialization for RefPtr<> to const Glib::Object.
* @ingroup glibmmValue
*/
template <class T>
class Value< Glib::RefPtr<const T> > : public ValueBase_Object
{
public:
typedef Glib::RefPtr<const T> CppType;
typedef typename T::BaseObjectType* CType;
static GType value_type() { return T::get_base_type(); }
void set(const CppType& data) { set_object(const_cast<T*>(data.operator->())); }
CppType get() const { return Glib::RefPtr<T>::cast_dynamic(get_object_copy()); }
};
#endif //GLIBMM_HAVE_DISAMBIGUOUS_CONST_TEMPLATE_SPECIALIZATIONS
#endif //DOXYGEN_SHOULD_SKIP_THIS
#endif //GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION
} // namespace Glib
#endif /* _GLIBMM_OBJECT_H */

View file

@ -1,271 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib-object.h>
#include <glibmm/quark.h>
#include <glibmm/objectbase.h>
namespace
{
// Used by the Glib::ObjectBase default ctor. Using an explicitly defined
// char array rather than a string literal allows for fast pointer comparison,
// which is otherwise not guaranteed to work.
const char anonymous_custom_type_name[] = "gtkmm__anonymous_custom_type";
} // anonymous namespace
namespace Glib
{
/**** Glib::ObjectBase *****************************************************/
ObjectBase::ObjectBase()
:
gobject_ (0),
custom_type_name_ (anonymous_custom_type_name),
cpp_destruction_in_progress_ (false)
{}
ObjectBase::ObjectBase(const char* custom_type_name)
:
gobject_ (0),
custom_type_name_ (custom_type_name),
cpp_destruction_in_progress_ (false)
{}
ObjectBase::ObjectBase(const std::type_info& custom_type_info)
:
gobject_ (0),
custom_type_name_ (custom_type_info.name()),
cpp_destruction_in_progress_ (false)
{}
// initialize() actually initializes the wrapper. Glib::ObjectBase is used
// as virtual base class, which means the most-derived class' ctor invokes
// the Glib::ObjectBase ctor -- thus it's useless for Glib::Object.
//
void ObjectBase::initialize(GObject* castitem)
{
if(gobject_)
{
// initialize() might be called twice when used with MI, e.g. by the ctors
// of Glib::Object and Glib::Interface. However, they must both refer to
// the same underlying GObject instance.
//
g_assert(gobject_ == castitem);
// TODO: Think about it. Will this really be called twice?
g_printerr("ObjectBase::initialize() called twice for the same GObject\n");
return; // Don't initialize the wrapper twice.
}
//g_print("%s : %s\n", G_GNUC_PRETTY_FUNCTION, G_OBJECT_TYPE_NAME(castitem));
gobject_ = castitem;
_set_current_wrapper(castitem);
}
ObjectBase::~ObjectBase()
{
// Normally, gobject_ should always be 0 at this point, because:
//
// a) Gtk::Object handles memory management on its own and always resets
// the gobject_ pointer in its destructor.
//
// b) Glib::Object instances that aren't Gtk::Objects will always be
// deleted by the destroy_notify_() virtual method. Calling delete
// on a Glib::Object is a programming error.
//
// The *only* situation where gobject_ is validly not 0 at this point
// happens if a derived class's ctor throws an exception. In that case
// we have to call g_object_unref() on our own.
//
if(GObject *const gobject = gobject_)
{
#ifdef GLIBMM_DEBUG_REFCOUNTING
g_warning("(Glib::ObjectBase::~ObjectBase): gobject_ = %p", (void*) gobject_);
#endif
gobject_ = 0;
#ifdef GLIBMM_DEBUG_REFCOUNTING
g_warning("(Glib::ObjectBase::~ObjectBase): before g_object_steal_qdata()");
#endif
// Remove the pointer to the wrapper from the underlying instance.
// This does _not_ cause invocation of the destroy_notify callback.
g_object_steal_qdata(gobject, quark_);
#ifdef GLIBMM_DEBUG_REFCOUNTING
g_warning("(Glib::ObjectBase::~ObjectBase): calling g_object_unref()");
#endif
g_object_unref(gobject);
}
}
void ObjectBase::reference() const
{
GLIBMM_DEBUG_REFERENCE(this, gobject_);
g_object_ref(gobject_);
}
void ObjectBase::unreference() const
{
GLIBMM_DEBUG_UNREFERENCE(this, gobject_);
g_object_unref(gobject_);
}
GObject* ObjectBase::gobj_copy() const
{
reference();
return gobject_;
}
void ObjectBase::_set_current_wrapper(GObject* object)
{
// Store a pointer to this wrapper in the underlying instance, so that we
// never create a second wrapper for the same underlying instance. Also,
// specify a callback that will tell us when it's time to delete this C++
// wrapper instance:
if(object)
{
if(!g_object_get_qdata(object, Glib::quark_))
{
g_object_set_qdata_full(object, Glib::quark_, this, &destroy_notify_callback_);
}
else
{
g_warning("This object, of type %s, already has a wrapper.\n"
"You should use wrap() instead of a constructor.",
G_OBJECT_TYPE_NAME(object));
}
}
}
// static
ObjectBase* ObjectBase::_get_current_wrapper(GObject* object)
{
if(object)
return static_cast<ObjectBase*>(g_object_get_qdata(object, Glib::quark_));
else
return 0;
}
// static
void ObjectBase::destroy_notify_callback_(void* data)
{
//GLIBMM_LIFECYCLE
// This method is called (indirectly) from g_object_run_dispose().
// Get the C++ instance associated with the C instance:
ObjectBase* cppObject = static_cast<ObjectBase*>(data); //Previously set with g_object_set_qdata_full().
#ifdef GLIBMM_DEBUG_REFCOUNTING
g_warning("ObjectBase::destroy_notify_callback_: cppObject = %p, gobject_ = %p, gtypename = %s",
(void*) cppObject, (void*) cppObject->gobject_, cppObject->gobject_);
#endif
if(cppObject) //This will be 0 if the C++ destructor has already run.
{
cppObject->destroy_notify_(); //Virtual - it does different things for GObject and GtkObject.
}
}
void ObjectBase::destroy_notify_()
{
// The C instance is about to be disposed, making it unusable. Now is a
// good time to delete the C++ wrapper of the C instance. There is no way
// to force the disposal of the GObject (though GtkObject has
// gtk_object_destroy()), So this is the *only* place where we delete the
// C++ wrapper.
//
// This will only happen after the last unreference(), which will be done by
// the RefPtr<> destructor. There should be no way to access the wrapper or
// the undobjecterlying instance after that, so it's OK to delete this.
#ifdef GLIBMM_DEBUG_REFCOUNTING
g_warning("Glib::ObjectBase::destroy_notify_: gobject_ = %p", (void*) gobject_);
#endif
gobject_ = 0; // Make sure we don't unref it again in the dtor.
delete this;
}
bool ObjectBase::is_anonymous_custom_() const
{
// Doing high-speed pointer comparison is OK here.
return (custom_type_name_ == anonymous_custom_type_name);
}
bool ObjectBase::is_derived_() const
{
// gtkmmproc-generated classes initialize this to 0 by default.
return (custom_type_name_ != 0);
}
void ObjectBase::set_manage()
{
// This is a private method and Gtk::manage() is a template function.
// Thus this will probably never run, unless you do something like:
//
// manage(static_cast<Gtk::Object*>(refptr.operator->()));
g_error("Glib::ObjectBase::set_manage(): "
"only Gtk::Object instances can be managed");
}
bool ObjectBase::_cpp_destruction_is_in_progress() const
{
return cpp_destruction_in_progress_;
}
void ObjectBase::set_property_value(const Glib::ustring& property_name, const Glib::ValueBase& value)
{
g_object_set_property(gobj(), property_name.c_str(), value.gobj());
}
void ObjectBase::get_property_value(const Glib::ustring& property_name, Glib::ValueBase& value) const
{
g_object_get_property(const_cast<GObject*>(gobj()), property_name.c_str(), value.gobj());
}
bool _gobject_cppinstance_already_deleted(GObject* gobject)
{
//This function is used to prevent calling wrap() on a GTK+ instance whose gtkmm instance has been deleted.
if(gobject)
return (bool)g_object_get_qdata(gobject, Glib::quark_cpp_wrapper_deleted_); //true means that something is odd.
else
return false; //Nothing is particularly wrong.
}
} // namespace Glib

View file

@ -1,171 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_OBJECTBASE_H
#define _GLIBMM_OBJECTBASE_H
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/signalproxy.h>
#include <glibmm/propertyproxy.h>
#include <sigc++/trackable.h>
#include <typeinfo>
#include <glibmmconfig.h>
#include <glibmm/debug.h>
GLIBMM_USING_STD(type_info)
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GObject GObject; }
#endif
namespace Glib
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
class GSigConnectionNode;
#endif
//This inherits virtually from sigc::trackable so that people can multiply inherit glibmm classes from other sigc::trackable-derived classes.
//See bugzilla.gnome.org bug # 116280
class ObjectBase : virtual public sigc::trackable
{
protected:
// Glib::ObjectBase is used as virtual base class. This means the ObjectBase
// ctor runs before all others -- either implicitly or explicitly. Each of
// the available ctors initializes custom_type_name_ in a different way:
//
// 1) default: custom_type_name_ = "gtkmm__anonymous_custom_type"
// 2) const char*: custom_type_name_ = custom_type_name
// 3) type_info: custom_type_name_ = custom_type_info.name()
//
// All classes generated by gtkmmproc use ctor 2) with custom_type_name = 0,
// which essentially means it's not a custom type. This is used to optimize
// vfunc and signal handler callbacks -- since the C++ virtual methods are
// not overridden, invocation can be skipped.
//
// The default ctor 1) is called implicitly from the ctor of user-derived
// classes -- yes, even if e.g. Gtk::Button calls ctor 2), a derived ctor
// always overrides this choice. The language itself ensures that the ctor
// is only invoked once.
//
// Ctor 3) is a special feature to allow creation of derived types on the
// fly, without having to use g_object_new() manually. This feature is
// sometimes necessary, e.g. to implement a custom Gtk::CellRenderer. The
// neat trick with the virtual base class ctor makes it possible to reuse
// the same direct base class' ctor as with non-custom types.
ObjectBase();
explicit ObjectBase(const char* custom_type_name);
explicit ObjectBase(const std::type_info& custom_type_info);
virtual ~ObjectBase() = 0;
// Called by Glib::Object and Glib::Interface constructors. See comments there.
void initialize(GObject* castitem);
public:
/// You probably want to use a specific property_*() accessor method instead.
void set_property_value(const Glib::ustring& property_name, const Glib::ValueBase& value);
/// You probably want to use a specific property_*() accessor method instead.
void get_property_value(const Glib::ustring& property_name, Glib::ValueBase& value) const;
/// You probably want to use a specific property_*() accessor method instead.
template <class PropertyType>
void set_property(const Glib::ustring& property_name, const PropertyType& value);
/// You probably want to use a specific property_*() accessor method instead.
template <class PropertyType>
void get_property(const Glib::ustring& property_name, PropertyType& value) const;
virtual void reference() const;
virtual void unreference() const;
inline GObject* gobj() { return gobject_; }
inline const GObject* gobj() const { return gobject_; }
// Give a ref-ed copy to someone. Use for direct struct access.
GObject* gobj_copy() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
static ObjectBase* _get_current_wrapper(GObject* object);
bool _cpp_destruction_is_in_progress() const;
#endif
protected:
GObject* gobject_; // the GLib/GDK/GTK+ object instance
const char* custom_type_name_;
bool cpp_destruction_in_progress_;
bool is_anonymous_custom_() const;
bool is_derived_() const;
static void destroy_notify_callback_(void* data);
virtual void destroy_notify_();
void _set_current_wrapper(GObject* object);
private:
// noncopyable
ObjectBase(const ObjectBase&);
ObjectBase& operator=(const ObjectBase&);
virtual void set_manage(); // calls g_error()
#ifndef DOXYGEN_SHOULD_SKIP_THIS
friend class Glib::GSigConnectionNode; // for GSigConnectionNode::notify()
#endif
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS
template <class PropertyType>
void ObjectBase::set_property(const Glib::ustring& property_name, const PropertyType& value)
{
Glib::Value<PropertyType> property_value;
property_value.init(Glib::Value<PropertyType>::value_type());
property_value.set(value);
this->set_property_value(property_name, property_value);
}
template <class PropertyType>
void ObjectBase::get_property(const Glib::ustring& property_name, PropertyType& value) const
{
Glib::Value<PropertyType> property_value;
property_value.init(Glib::Value<PropertyType>::value_type());
this->get_property_value(property_name, property_value);
value = property_value.get();
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
bool _gobject_cppinstance_already_deleted(GObject* gobject);
} // namespace Glib
#endif /* _GLIBMM_OBJECTBASE_H */

View file

@ -1,141 +0,0 @@
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <glibmm/optioncontext.h>
#include <glibmm/private/optioncontext_p.h>
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/utility.h>
#include <glib/goption.h>
namespace Glib
{
OptionContext::OptionContext(const Glib::ustring& parameter_string)
: gobject_( g_option_context_new(parameter_string.c_str()) ),
has_ownership_(true)
{
}
OptionContext::OptionContext(GOptionContext* castitem, bool take_ownership)
: gobject_(castitem),
has_ownership_(take_ownership)
{
}
OptionContext::~OptionContext()
{
if(has_ownership_)
g_option_context_free(gobj());
gobject_ = 0;
}
void OptionContext::add_group(OptionGroup& group)
{
//Strangely, GObjectContext actually takes ownership of the GOptionGroup, deleting it later.
g_option_context_add_group(gobj(), (group).gobj_give_ownership());
}
void OptionContext::set_main_group(OptionGroup& group)
{
//Strangely, GObjectContext actually takes ownership of the GOptionGroup, deleting it later.
g_option_context_set_main_group(gobj(), (group).gobj_give_ownership());
}
/*
OptionGroup OptionContext::get_main_group() const
{
const GOptionGroup* cobj = g_option_context_get_main_group(const_cast<GOptionContext*>( gobj()) );
OptionGroup cppObj(const_cast<GOptionGroup*>(cobj), true); // take_copy
return cppObj;
}
*/
} // namespace Glib
namespace
{
} // anonymous namespace
Glib::OptionError::OptionError(Glib::OptionError::Code error_code, const Glib::ustring& error_message)
:
Glib::Error (G_OPTION_ERROR, error_code, error_message)
{}
Glib::OptionError::OptionError(GError* gobject)
:
Glib::Error (gobject)
{}
Glib::OptionError::Code Glib::OptionError::code() const
{
return static_cast<Code>(Glib::Error::code());
}
void Glib::OptionError::throw_func(GError* gobject)
{
throw Glib::OptionError(gobject);
}
namespace Glib
{
void OptionContext::set_help_enabled(bool help_enabled)
{
g_option_context_set_help_enabled(gobj(), static_cast<int>(help_enabled));
}
bool OptionContext::get_help_enabled() const
{
return g_option_context_get_help_enabled(const_cast<GOptionContext*>(gobj()));
}
void OptionContext::set_ignore_unknown_options(bool ignore_unknown)
{
g_option_context_set_ignore_unknown_options(gobj(), static_cast<int>(ignore_unknown));
}
bool OptionContext::get_ignore_unknown_options() const
{
return g_option_context_get_ignore_unknown_options(const_cast<GOptionContext*>(gobj()));
}
bool OptionContext::parse(int& argc, char**& argv)
{
GError *error = 0;
bool retvalue = g_option_context_parse(gobj(), &argc, &(argv), &(error));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
} // namespace Glib

View file

@ -1,197 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_OPTIONCONTEXT_H
#define _GLIBMM_OPTIONCONTEXT_H
/* $Id$ */
/* Copyright (C) 2004 The glibmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/optionentry.h>
#include <glibmm/optiongroup.h>
#include <glibmm/error.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GOptionContext GOptionContext; }
#endif
namespace Glib
{
/** Exception class for options.
*/
class OptionError : public Glib::Error
{
public:
enum Code
{
UNKNOWN_OPTION,
BAD_VALUE,
FAILED
};
OptionError(Code error_code, const Glib::ustring& error_message);
explicit OptionError(GError* gobject);
Code code() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
private:
static void throw_func(GError* gobject);
friend void wrap_init(); // uses throw_func()
#endif
};
/** An OptionContext defines which options are accepted by the commandline option parser.
*/
class OptionContext
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef OptionContext CppObjectType;
typedef GOptionContext BaseObjectType;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
private:
public:
/** Creates a new option context.
* @param parameter_string A string which is displayed in the first line of --help output, after programname [OPTION...]
*/
explicit OptionContext(const Glib::ustring& parameter_string = Glib::ustring());
//Note that, unlike Glib::Wrap(), this would create a second C++ instance for the same C instance,
//so it should be used carefully. For instance you could not access data in a derived class via this second instance.
explicit OptionContext(GOptionContext* castitem, bool take_ownership = false);
virtual ~OptionContext();
/** Enables or disables automatic generation of &lt;option&gt;--help&lt;/option&gt;
* output. By default, g_option_context_parse() recognizes
* &lt;option&gt;--help&lt;/option&gt;, &lt;option&gt;-?&lt;/option&gt;, &lt;option&gt;--help-all&lt;/option&gt;
* and &lt;option&gt;--help-&lt;/option&gt;&lt;replaceable&gt;groupname&lt;/replaceable&gt; and creates
* suitable output to stdout.
*
* Since: 2.6
* @param help_enabled <tt>true</tt> to enable &lt;option&gt;--help&lt;/option&gt;, <tt>false</tt> to disable it.
*/
void set_help_enabled(bool help_enabled = true);
/** Returns whether automatic &lt;option&gt;--help&lt;/option&gt; generation
* is turned on for @a context . See g_option_context_set_help_enabled().
* @return <tt>true</tt> if automatic help generation is turned on.
*
* Since: 2.6.
*/
bool get_help_enabled() const;
/** Sets whether to ignore unknown options or not. If an argument is
* ignored, it is left in the @a argv array after parsing. By default,
* g_option_context_parse() treats unknown options as error.
*
* This setting does not affect non-option arguments (i.e. arguments
* which don't start with a dash). But note that GOption cannot reliably
* determine whether a non-option belongs to a preceding unknown option.
*
* Since: 2.6
* @param ignore_unknown <tt>true</tt> to ignore unknown options, <tt>false</tt> to produce
* an error when unknown options are met.
*/
void set_ignore_unknown_options(bool ignore_unknown = true);
/** Returns whether unknown options are ignored or not. See
* g_option_context_set_ignore_unknown_options().
* @return <tt>true</tt> if unknown options are ignored.
*
* Since: 2.6.
*/
bool get_ignore_unknown_options() const;
/** Parses the command line arguments, recognizing options
* which have been added to @a context . A side-effect of
* calling this function is that g_set_prgname() will be
* called.
*
* If the parsing is successful, any parsed arguments are
* removed from the array and @a argc and @a argv are updated
* accordingly. In case of an error, @a argc and @a argv are
* left unmodified.
*
* If automatic &lt;option&gt;--help&lt;/option&gt; support is enabled
* (see g_option_context_set_help_enabled()), and the
* @a argv array contains one of the recognized help options,
* this function will produce help output to stdout and
* call <tt>exit (0)</tt>.
* @param argc A pointer to the number of command line arguments.
* @param argv A pointer to the array of command line arguments.
* @param error A return location for errors.
* @return <tt>true</tt> if the parsing was successful,
* <tt>false</tt> if an error occurred
*
* Since: 2.6.
*/
bool parse(int& argc, char**& argv);
//g_option_context_add_main_entries(), just creates a group internally, adds them to it, and does a set_main_group()
//- a group without callbacks seems to do some simple default parsing.
/** Adds an OptionGroup to the context, so that parsing with context will recognize the options in the group.
* Note that the group will not be copied, so it should exist for as long as the context exists.
*
* @param group The group to add.
*/
void add_group(OptionGroup& group);
/** Sets an OptionGroup as the main group of the context. This has the same effect as calling add_group(), the only
* difference is that the options in the main group are treated differently when generating --help output.
* Note that the group will not be copied, so it should exist for as long as the context exists.
*
* @param group The group to add.
*/
void set_main_group(OptionGroup& group);
//We don't need this (hopefully), and the memory management would be really awkward.
//OptionGroup& get_main_group();
//const OptionGroup& get_main_group() const;
GOptionContext* gobj() { return gobject_; }
const GOptionContext* gobj() const { return gobject_; }
protected:
GOptionContext* gobject_;
bool has_ownership_;
};
} // namespace Glib
#endif /* _GLIBMM_OPTIONCONTEXT_H */

View file

@ -1,149 +0,0 @@
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <glibmm/optionentry.h>
#include <glibmm/private/optionentry_p.h>
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/utility.h>
#include <glib/goption.h>
#include <glib/gmem.h>
namespace Glib
{
OptionEntry::OptionEntry()
: gobject_( new GOptionEntry() )
{
gobject_ = g_new0(GOptionEntry, 1);
}
OptionEntry::~OptionEntry()
{
g_free(const_cast<char*>(gobject_->long_name));
g_free(const_cast<char*>(gobject_->description));
g_free(const_cast<char*>(gobject_->arg_description));
g_free(gobject_);
}
OptionEntry::OptionEntry(const OptionEntry& src)
{
gobject_ = g_new0(GOptionEntry, 1);
operator=(src);
}
OptionEntry& OptionEntry::operator=(const OptionEntry& src)
{
if(this != &src)
{
if(gobject_->long_name)
g_free(const_cast<char*>(gobject_->long_name));
gobject_->long_name = g_strdup(src.gobject_->long_name);
gobject_->short_name = src.gobject_->short_name; //It's just one char.
gobject_->flags = src.gobject_->flags;
gobject_->arg = src.gobject_->arg;
gobject_->arg_data = src.gobject_->arg_data; //Shared, because it's not owned by any instance of this class anyway.
if(gobject_->description)
g_free(const_cast<char*>(gobject_->description));
gobject_->description = g_strdup(src.gobject_->description);
if(gobject_->arg_description)
g_free(const_cast<char*>(gobject_->arg_description));
gobject_->arg_description = g_strdup(src.gobject_->arg_description);
}
return *this;
}
} // namespace Glib
namespace
{
} // anonymous namespace
namespace Glib
{
Glib::ustring OptionEntry::get_long_name() const
{
return Glib::convert_const_gchar_ptr_to_ustring(gobj()->long_name);
}
void OptionEntry::set_long_name(const Glib::ustring& value)
{
gobj()->long_name = g_strdup((value).c_str());
}
gchar OptionEntry::get_short_name() const
{
return gobj()->short_name;
}
void OptionEntry::set_short_name(const gchar& value)
{
gobj()->short_name = value;
}
int OptionEntry::get_flags() const
{
return gobj()->flags;
}
void OptionEntry::set_flags(const int& value)
{
gobj()->flags = value;
}
Glib::ustring OptionEntry::get_description() const
{
return Glib::convert_const_gchar_ptr_to_ustring(gobj()->description);
}
void OptionEntry::set_description(const Glib::ustring& value)
{
gobj()->description = g_strdup((value).c_str());
}
Glib::ustring OptionEntry::get_arg_description() const
{
return Glib::convert_const_gchar_ptr_to_ustring(gobj()->arg_description);
}
void OptionEntry::set_arg_description(const Glib::ustring& value)
{
gobj()->arg_description = g_strdup((value).c_str());
}
} // namespace Glib

View file

@ -1,108 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_OPTIONENTRY_H
#define _GLIBMM_OPTIONENTRY_H
/* $Id$ */
/* Copyright (C) 2004 The glibmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/ustring.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GOptionEntry GOptionEntry; }
#endif
namespace Glib
{
/** An OptionEntry defines a single option. To have an effect, it must be added to an OptionGroup with
* OptionGroup::add_entry().
*
* The long name of an option can be used to specify it in a commandline as --long_name.
* Every option must have a long name. To resolve conflicts if multiple option groups contain the same long name, it is also
* possible to specify the option as --groupname-long_name.
*
* If an option has a short name, it can be specified as -short_name in a commandline.
*
* The description for the option is shown in the --help output.
*
* The arg_descripton is the placeholder to use for the extra argument parsed by the option in --help output.
*/
class OptionEntry
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef OptionEntry CppObjectType;
typedef GOptionEntry BaseObjectType;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
private:
public:
//Copied from goption.h, instead of generated, so that we can put it inside the class.
enum Flags
{
FLAG_HIDDEN = 1 << 0,
FLAG_IN_MAIN = 1 << 1,
FLAG_REVERSE = 1 << 2
} GOptionFlags;
OptionEntry();
OptionEntry(const OptionEntry& src);
virtual ~OptionEntry();
OptionEntry& operator=(const OptionEntry& src);
Glib::ustring get_long_name() const;
void set_long_name(const Glib::ustring& value);
gchar get_short_name() const;
void set_short_name(const gchar& value);
int get_flags() const;
void set_flags(const int& value);
//TODO: G_OPTION_ARG_CALLBACK,
Glib::ustring get_description() const;
void set_description(const Glib::ustring& value);
Glib::ustring get_arg_description() const;
void set_arg_description(const Glib::ustring& value);
GOptionEntry* gobj() { return gobject_; }
const GOptionEntry* gobj() const { return gobject_; }
protected:
GOptionEntry* gobject_;
};
} // namespace Glib
#endif /* _GLIBMM_OPTIONENTRY_H */

View file

@ -1,453 +0,0 @@
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <glibmm/optiongroup.h>
#include <glibmm/private/optiongroup_p.h>
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/optionentry.h>
#include <glibmm/optioncontext.h>
#include <glibmm/utility.h>
//#include <glibmm/containers.h>
#include <glib/goption.h>
namespace Glib
{
namespace //anonymous
{
extern "C"
{
static gboolean g_callback_pre_parse(GOptionContext* context, GOptionGroup* /* group */, gpointer data, GError** /* TODO error */)
{
OptionContext cppContext(context, false /* take_ownership */);
//OptionGroup cppGroup(group, true /* take_copy */); //Maybe this should be option_group.
OptionGroup* option_group = static_cast<OptionGroup*>(data);
if(option_group)
return option_group->on_pre_parse(cppContext, *option_group);
else
return false;
}
static gboolean g_callback_post_parse(GOptionContext* context, GOptionGroup* /* group */, gpointer data, GError** /* TODO error */)
{
OptionContext cppContext(context, false /* take_ownership */);
//OptionGroup cppGroup(group, true /* take_copy */); //Maybe this should be option_group.
OptionGroup* option_group = static_cast<OptionGroup*>(data);
if(option_group)
{
return option_group->on_post_parse(cppContext, *option_group);
}
else
return false;
}
static void g_callback_error(GOptionContext* context, GOptionGroup* /* group */, gpointer data, GError** /* TODO error*/)
{
OptionContext cppContext(context, false /* take_ownership */);
//OptionGroup cppGroup(group); //Maybe this should be option_group.
OptionGroup* option_group = static_cast<OptionGroup*>(data);
if(option_group)
return option_group->on_error(cppContext, *option_group);
}
} /* extern "C" */
} //anonymous namespace
OptionGroup::OptionGroup(const Glib::ustring& name, const Glib::ustring& description, const Glib::ustring& help_description)
: gobject_( g_option_group_new(name.c_str(), description.c_str(), help_description.c_str(), this, 0 /* destroy_func */) ),
has_ownership_(true)
{
//Connect callbacks, so that derived classes can override the virtual methods:
g_option_group_set_parse_hooks(gobj(), &g_callback_pre_parse, &g_callback_post_parse);
g_option_group_set_error_hook(gobj(), &g_callback_error);
}
OptionGroup::OptionGroup(GOptionGroup* castitem)
: gobject_(castitem),
has_ownership_(true)
{
//Always takes ownership - never takes copy.
}
OptionGroup::~OptionGroup()
{
//Free any C types that were allocated during add_entry():
for(type_map_entries::iterator iter = map_entries_.begin(); iter != map_entries_.end(); ++iter)
{
CppOptionEntry& cpp_entry = iter->second;
cpp_entry.release_c_arg();
}
if(has_ownership_)
{
g_option_group_free(gobj());
gobject_ = 0;
}
}
void OptionGroup::add_entry(const OptionEntry& entry)
{
//It does not copy the entry, so it needs to live as long as the group.
//g_option_group_add_entries takes an array, with the last item in the array having a null long_name.
//Hopefully this will be properly documented eventually - see bug #
//Create a temporary array, just so we can give the correct thing to g_option_group_add_entries:
GOptionEntry array[2];
array[0] = *(entry.gobj()); //Copy contents.
GLIBMM_INITIALIZE_STRUCT(array[1], GOptionEntry);
g_option_group_add_entries(gobj(), array);
}
void OptionGroup::add_entry(const OptionEntry& entry, bool& arg)
{
add_entry_with_wrapper(entry, G_OPTION_ARG_NONE /* Actually a boolean on/off, depending on whether the argument name was given, without argument parameters. */, &arg);
}
void OptionGroup::add_entry(const OptionEntry& entry, int& arg)
{
add_entry_with_wrapper(entry, G_OPTION_ARG_INT, &arg);
}
void OptionGroup::add_entry(const OptionEntry& entry, Glib::ustring& arg)
{
add_entry_with_wrapper(entry, G_OPTION_ARG_STRING, &arg);
}
void OptionGroup::add_entry(const OptionEntry& entry, vecustrings& arg)
{
add_entry_with_wrapper(entry, G_OPTION_ARG_STRING_ARRAY, &arg);
}
void OptionGroup::add_entry_filename(const OptionEntry& entry, std::string& arg)
{
add_entry_with_wrapper(entry, G_OPTION_ARG_FILENAME, &arg);
}
void OptionGroup::add_entry_filename(const OptionEntry& entry, vecstrings& arg)
{
add_entry_with_wrapper(entry, G_OPTION_ARG_FILENAME_ARRAY, &arg);
}
void OptionGroup::add_entry_with_wrapper(const OptionEntry& entry, GOptionArg arg_type, void* cpp_arg)
{
const Glib::ustring name = entry.get_long_name();
type_map_entries::iterator iterFind = map_entries_.find(name);
if( iterFind == map_entries_.end() ) //If we have not added this entry already
{
CppOptionEntry cppEntry;
cppEntry.carg_type_ = arg_type;
cppEntry.allocate_c_arg();
cppEntry.cpparg_ = cpp_arg;
//Remember the C++/C mapping so that we can use it later:
map_entries_[name] = cppEntry;
//Give the information to the C API:
cppEntry.entry_ = new OptionEntry(entry); //g_option_group_add_entry() does not take its own copy, so we must keep the instance alive.*/
cppEntry.entry_->gobj()->arg = arg_type;
cppEntry.entry_->gobj()->arg_data = cppEntry.carg_;
add_entry(*(cppEntry.entry_));
}
}
bool OptionGroup::on_pre_parse(OptionContext& /* context */, OptionGroup& /* group */)
{
return true;
}
bool OptionGroup::on_post_parse(OptionContext& /* context */, OptionGroup& /* group */)
{
//Call this at the start of overrides.
//TODO: Maybe put this in the C callback:
//The C args have now been given values by GOption.
//Convert C values to C++ values:
for(type_map_entries::iterator iter = map_entries_.begin(); iter != map_entries_.end(); ++iter)
{
CppOptionEntry& cpp_entry = iter->second;
cpp_entry.convert_c_to_cpp();
}
return true;
}
void OptionGroup::on_error(OptionContext& /* context */, OptionGroup& /* group */)
{
}
OptionGroup::CppOptionEntry::CppOptionEntry()
: carg_type_(G_OPTION_ARG_NONE), carg_(0), cpparg_(0), entry_(0)
{}
void OptionGroup::CppOptionEntry::allocate_c_arg()
{
//Create an instance of the appropriate C type.
//This will be destroyed in the OptionGroup destructor.
switch(carg_type_)
{
case G_OPTION_ARG_STRING: //The char* will be for UTF8 strins.
case G_OPTION_ARG_FILENAME: //The char* will be for strings in the current locale's encoding.
{
char** typed_arg = new char*;
*typed_arg = 0; //The C code will allocate a char* and put it here, for us to g_free() later.
carg_ = typed_arg;
break;
}
case G_OPTION_ARG_INT:
{
int* typed_arg = new int;
*typed_arg = 0;
carg_ = typed_arg;
break;
}
case G_OPTION_ARG_STRING_ARRAY:
case G_OPTION_ARG_FILENAME_ARRAY:
{
char*** typed_arg = new char**;
*typed_arg = 0;
carg_ = typed_arg;
break;
}
case G_OPTION_ARG_NONE: /* Actually a boolean. */
{
gboolean* typed_arg = new gboolean;
*typed_arg = 0;
carg_ = typed_arg;
break;
}
default:
{
break;
}
}
}
void OptionGroup::CppOptionEntry::release_c_arg()
{
//Delete the instances that we created in allocate_c_arg().
//Notice that we delete the type that we created, but not the value to which it points.
if(carg_)
{
switch(carg_type_)
{
case G_OPTION_ARG_STRING:
case G_OPTION_ARG_FILENAME:
{
char** typed_arg = (char**)carg_;
g_free(*typed_arg); //Free the char* string at type_arg, which was allocated by the C code.
delete typed_arg; //Delete the char** that we allocated in allocate_c_arg;
break;
}
case G_OPTION_ARG_INT:
{
int* typed_arg = (int*)carg_;
delete typed_arg;
break;
}
case G_OPTION_ARG_STRING_ARRAY:
case G_OPTION_ARG_FILENAME_ARRAY:
{
delete (char**)carg_;
break;
}
case G_OPTION_ARG_NONE: /* Actually a boolean. */
{
gboolean* typed_arg = (gboolean*)carg_;
delete typed_arg;
break;
}
default:
{
/* TODO:
G_OPTION_ARG_CALLBACK,
*/
break;
}
}
carg_ = 0;
}
if(entry_)
delete entry_;
}
void OptionGroup::CppOptionEntry::convert_c_to_cpp()
{
switch(carg_type_)
{
case G_OPTION_ARG_STRING:
{
char** typed_arg = (char**)carg_;
Glib::ustring* typed_cpp_arg = (Glib::ustring*)cpparg_;
if(typed_arg && typed_cpp_arg)
{
char* pch = *typed_arg;
(*typed_cpp_arg) = Glib::convert_const_gchar_ptr_to_ustring(pch);
break;
}
}
case G_OPTION_ARG_FILENAME:
{
char** typed_arg = (char**)carg_;
std::string* typed_cpp_arg = (std::string*)cpparg_;
if(typed_arg && typed_cpp_arg)
{
char* pch = *typed_arg;
(*typed_cpp_arg) = Glib::convert_const_gchar_ptr_to_stdstring(pch);
break;
}
}
case G_OPTION_ARG_INT:
{
*((int*)cpparg_) = *((int*)carg_);
break;
}
case G_OPTION_ARG_STRING_ARRAY:
{
char*** typed_arg = (char***)carg_;
vecustrings* typed_cpp_arg = (vecustrings*)cpparg_;
if(typed_arg && typed_cpp_arg)
{
typed_cpp_arg->clear();
//The C array seems to be null-terminated.
//Glib::StringArrayHandle array_handle(*typed_arg, Glib::OWNERSHIP_NONE);
//The SUN Forte compiler complains about this:
// "optiongroup.cc", line 354: Error: Cannot assign Glib::ArrayHandle<Glib::ustring,
// Glib::Container_Helpers::TypeTraits<Glib::ustring>> to std::vector<Glib::ustring> without
// "std::vector<Glib::ustring>::operator=(const std::vector<Glib::ustring>&)";.
//
//(*typed_cpp_arg) = array_handle;
//
//And the Tru64 compiler does not even like us to instantiate the StringArrayHandle:
//
// cxx: Error: ../../glib/glibmm/containerhandle_shared.h, line 149: the operand
// of a pointer dynamic_cast must be a pointer to a complete class type
// return dynamic_cast<CppType>(Glib::wrap_auto(cobj, false /* take_copy */));
//for(Glib::StringArrayHandle::iterator iter = array_handle.begin(); iter != array_handle.end(); ++iter)
//{
// typed_cpp_arg->push_back(*iter);
//}
//So we do this:
char** char_array_next = *typed_arg;
while(char_array_next && *char_array_next)
{
typed_cpp_arg->push_back(*char_array_next);
++char_array_next;
}
}
break;
}
case G_OPTION_ARG_FILENAME_ARRAY:
{
char*** typed_arg = (char***)carg_;
vecustrings* typed_cpp_arg = (vecustrings*)cpparg_;
if(typed_arg && typed_cpp_arg)
{
typed_cpp_arg->clear();
//See comments above about the SUN Forte and Tru64 compilers.
char** char_array_next = *typed_arg;
while(char_array_next && *char_array_next)
{
typed_cpp_arg->push_back(*char_array_next);
++char_array_next;
}
}
break;
}
case G_OPTION_ARG_NONE: /* Actually a boolean. */
{
*((bool*)cpparg_) = *((gboolean*)carg_);
break;
}
default:
{
/* TODO:
G_OPTION_ARG_CALLBACK,
*/
break;
}
}
}
GOptionGroup* OptionGroup::gobj_give_ownership()
{
has_ownership_ = false;
return gobj();
}
} // namespace Glib
namespace
{
} // anonymous namespace
namespace Glib
{
void OptionGroup::set_translation_domain(const Glib::ustring& domain)
{
g_option_group_set_translation_domain(gobj(), domain.c_str());
}
} // namespace Glib

View file

@ -1,141 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_OPTIONGROUP_H
#define _GLIBMM_OPTIONGROUP_H
/* $Id$ */
/* Copyright (C) 2004 The glibmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/ustring.h>
#include <map>
#include <vector>
#include <glib/goption.h> //TODO: Try to hide this.
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GOptionGroup GOptionGroup; }
#endif //DOXYGEN_SHOULD_SKIP_THIS
namespace Glib
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
class OptionEntry;
class OptionContext;
#endif //DOXYGEN_SHOULD_SKIP_THIS
/** An OptionGroup defines the options in a single group.
* Libraries which need to parse commandline options are expected to provide a function that allows their OptionGroups to
* be added to the application's OptionContext.
*/
class OptionGroup
{
public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef OptionGroup CppObjectType;
typedef GOptionGroup BaseObjectType;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
private:
public:
OptionGroup(const Glib::ustring& name, const Glib::ustring& description, const Glib::ustring& help_description = Glib::ustring());
/** This always takes ownership of the underlying GOptionGroup,
* so it is only useful with C functions that return newly-allocated GOptionGroups.
*/
explicit OptionGroup(GOptionGroup* castitem);
virtual ~OptionGroup();
virtual bool on_pre_parse(OptionContext& context, OptionGroup& group);
virtual bool on_post_parse(OptionContext& context, OptionGroup& group);
virtual void on_error(OptionContext& context, OptionGroup& group);
void add_entry(const OptionEntry& entry);
typedef std::vector<Glib::ustring> vecustrings;
typedef std::vector<std::string> vecstrings;
void add_entry(const OptionEntry& entry, bool& arg);
void add_entry(const OptionEntry& entry, int& arg);
void add_entry(const OptionEntry& entry, Glib::ustring& arg);
void add_entry_filename(const OptionEntry& entry, std::string& arg);
void add_entry(const OptionEntry& entry, vecustrings& arg);
void add_entry_filename(const OptionEntry& entry, vecstrings& arg);
/* TODO:
void g_option_group_set_translate_func (GOptionGroup *group,
GTranslateFunc func,
gpointer data,
GDestroyNotify destroy_notify);
*/
/** A convenience function to use gettext() for translating
* user-visible strings.
*
* Since: 2.6
* @param domain The domain to use.
*/
void set_translation_domain(const Glib::ustring& domain);
GOptionGroup* gobj() { return gobject_; }
const GOptionGroup* gobj() const { return gobject_; }
GOptionGroup* gobj_give_ownership();
protected:
class CppOptionEntry
{
public:
CppOptionEntry();
void allocate_c_arg();
void convert_c_to_cpp();
void release_c_arg();
GOptionArg carg_type_;
void* carg_;
void* cpparg_;
OptionEntry* entry_;
};
void add_entry_with_wrapper(const OptionEntry& entry, GOptionArg arg_type, void* cpp_arg);
//Map of entry names to CppOptionEntry:
typedef std::map<Glib::ustring, CppOptionEntry> type_map_entries;
type_map_entries map_entries_;
GOptionGroup* gobject_;
bool has_ownership_; //Whether the gobject_ belongs to this C++ instance.
};
} // namespace Glib
#endif /* _GLIBMM_OPTIONGROUP_H */

View file

@ -1,66 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* pattern.cc
*
* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gpattern.h>
#include <glibmm/pattern.h>
namespace Glib
{
PatternSpec::PatternSpec(const Glib::ustring& pattern)
:
gobject_ (g_pattern_spec_new(pattern.c_str()))
{}
PatternSpec::PatternSpec(GPatternSpec* gobject)
:
gobject_ (gobject)
{}
PatternSpec::~PatternSpec()
{
g_pattern_spec_free(gobject_);
}
bool PatternSpec::match(const Glib::ustring& str) const
{
return g_pattern_match(gobject_, str.bytes(), str.c_str(), 0);
}
bool PatternSpec::match(const Glib::ustring& str, const Glib::ustring& str_reversed) const
{
return g_pattern_match(gobject_, str.bytes(), str.c_str(), str_reversed.c_str());
}
bool PatternSpec::operator==(const PatternSpec& rhs) const
{
return g_pattern_spec_equal(gobject_, rhs.gobject_);
}
bool PatternSpec::operator!=(const PatternSpec& rhs) const
{
return !g_pattern_spec_equal(gobject_, rhs.gobject_);
}
} // namespace Glib

View file

@ -1,69 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_PATTERN_H
#define _GLIBMM_PATTERN_H
/* $Id$ */
/* pattern.h
*
* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
extern "C" { typedef struct _GPatternSpec GPatternSpec; }
#include <glibmm/ustring.h>
namespace Glib
{
/** @defgroup PatternMatching Glob-style Pattern Matching
* Match strings against patterns containing '*' (wildcard) and '?' (joker).
* @{
*/
class PatternSpec
{
public:
explicit PatternSpec(const Glib::ustring& pattern);
explicit PatternSpec(GPatternSpec* gobject);
~PatternSpec();
bool match(const Glib::ustring& str) const;
bool match(const Glib::ustring& str, const Glib::ustring& str_reversed) const;
bool operator==(const PatternSpec& rhs) const;
bool operator!=(const PatternSpec& rhs) const;
GPatternSpec* gobj() { return gobject_; }
const GPatternSpec* gobj() const { return gobject_; }
private:
GPatternSpec* gobject_;
// noncopyable
PatternSpec(const PatternSpec&);
PatternSpec& operator=(const PatternSpec&);
};
/** @} group PatternMatching */
} // namespace Glib
#endif /* _GLIBMM_PATTERN_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_CONVERT_P_H
#define _GLIBMM_CONVERT_P_H
#endif /* _GLIBMM_CONVERT_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_DATE_P_H
#define _GLIBMM_DATE_P_H
#endif /* _GLIBMM_DATE_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_FILEUTILS_P_H
#define _GLIBMM_FILEUTILS_P_H
#endif /* _GLIBMM_FILEUTILS_P_H */

View file

@ -1,24 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_INTERFACE_P_H
#define _GLIBMM_INTERFACE_P_H
#include <glibmm/class.h>
namespace Glib
{
class Interface_Class : public Glib::Class
{
public:
typedef Interface CppObjectType;
typedef GTypeInterface BaseClassType;
void add_interface(GType instance_type) const;
};
} // namespace Glib
#endif /* _GLIBMM_INTERFACE_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_IOCHANNEL_P_H
#define _GLIBMM_IOCHANNEL_P_H
#endif /* _GLIBMM_IOCHANNEL_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_MARKUP_P_H
#define _GLIBMM_MARKUP_P_H
#endif /* _GLIBMM_MARKUP_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_MODULE_P_H
#define _GLIBMM_MODULE_P_H
#endif /* _GLIBMM_MODULE_P_H */

View file

@ -1,28 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_OBJECT_P_H
#define _GLIBMM_OBJECT_P_H
#include <glibmm/class.h>
namespace Glib
{
class Object_Class : public Glib::Class
{
public:
typedef Object CppObjectType;
typedef GObject BaseObjectType;
typedef GObjectClass BaseClassType;
static void class_init_function(void* g_class, void* class_data);
const Glib::Class& init();
static Glib::Object* wrap_new(GObject*);
};
} // namespace Glib
#endif /* _GLIBMM_OBJECT_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_OPTIONCONTEXT_P_H
#define _GLIBMM_OPTIONCONTEXT_P_H
#endif /* _GLIBMM_OPTIONCONTEXT_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_OPTIONENTRY_P_H
#define _GLIBMM_OPTIONENTRY_P_H
#endif /* _GLIBMM_OPTIONENTRY_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_OPTIONGROUP_P_H
#define _GLIBMM_OPTIONGROUP_P_H
#endif /* _GLIBMM_OPTIONGROUP_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_SHELL_P_H
#define _GLIBMM_SHELL_P_H
#endif /* _GLIBMM_SHELL_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_SPAWN_P_H
#define _GLIBMM_SPAWN_P_H
#endif /* _GLIBMM_SPAWN_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_THREAD_P_H
#define _GLIBMM_THREAD_P_H
#endif /* _GLIBMM_THREAD_P_H */

View file

@ -1,6 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_UNICODE_P_H
#define _GLIBMM_UNICODE_P_H
#endif /* _GLIBMM_UNICODE_P_H */

View file

@ -1,198 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/property.h>
#include <glibmm/object.h>
#include <cstddef>
// Temporary hack till GLib gets fixed.
#undef G_STRLOC
#define G_STRLOC __FILE__ ":" G_STRINGIFY(__LINE__)
namespace
{
// OK guys, please don't kill me for that. Let me explain what happens here.
//
// The task:
// ---------
// a) Autogenerate a property ID number for each custom property. This is an
// unsigned integer, which doesn't have to be assigned continuously. I.e.,
// it can be everything but 0.
// b) If more than one object of the same class is instantiated, then of course
// the already installed properties must be used. That means, a property ID
// must not be associated with a single Glib::Property<> instance. Rather,
// the ID has to be associated with the class somehow.
// c) With only a GObject pointer and a property ID (and perhaps GParamSpec*
// if necessary), it must be possible to acquire a reference to the property
// wrapper instance.
//
// The current solution:
// ---------------------
// a) Assign an ID to a Glib::PropertyBase by calculating its offset in bytes
// relative to the beginning of the object's memory. dynamic_cast<void*>
// is used to retrieve a pointer to the very beginning of an instance.
// b) Recalculate a specific PropertyBase pointer by adding the property ID
// (i.e. the byte offset) to the object start pointer. The result is then
// just casted to PropertyBase*.
//
// Drawbacks:
// ----------
// a) It's a low-level hack. Should be portable, yes, but we can only do very
// limited error checking.
// b) All Glib::Property<> instances are absolutely required to be direct data
// members of the class that implements the property. That seems a natural
// thing to do, but it's questionable whether it should be a requirement.
//
// Advantages:
// -----------
// a) Although low-level, it's extremely easy to implement. The nasty code is
// concentrated in only two non-exposed utility functions, and it works
// just fine.
// b) It's efficient, and the memory footprint is very small too.
// c) I actually tried other ways, too, but ran into dead-ends everywhere.
// It's probably possible to implement this without calculating offsets,
// but it'll be very complicated, and involve a lot of qdata pointers to
// property tables andwhatnot.
//
// We can reimplement this later if necessary.
unsigned int property_to_id(Glib::ObjectBase& object, Glib::PropertyBase& property)
{
void *const base_ptr = dynamic_cast<void*>(&object);
void *const prop_ptr = &property;
const ptrdiff_t offset = static_cast<guint8*>(prop_ptr) - static_cast<guint8*>(base_ptr);
g_return_val_if_fail(offset > 0 && offset < G_MAXINT, 0);
return static_cast<unsigned int>(offset);
}
Glib::PropertyBase& property_from_id(Glib::ObjectBase& object, unsigned int property_id)
{
void *const base_ptr = dynamic_cast<void*>(&object);
void *const prop_ptr = static_cast<guint8*>(base_ptr) + property_id;
return *static_cast<Glib::PropertyBase*>(prop_ptr);
}
} // anonymous namespace
namespace Glib
{
void custom_get_property_callback(GObject* object, unsigned int property_id,
GValue* value, GParamSpec* param_spec)
{
if(Glib::ObjectBase *const wrapper = Glib::ObjectBase::_get_current_wrapper(object))
{
PropertyBase& property = property_from_id(*wrapper, property_id);
if((property.object_ == wrapper) && (property.param_spec_ == param_spec))
g_value_copy(property.value_.gobj(), value);
else
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, param_spec);
}
}
void custom_set_property_callback(GObject* object, unsigned int property_id,
const GValue* value, GParamSpec* param_spec)
{
if(Glib::ObjectBase *const wrapper = Glib::ObjectBase::_get_current_wrapper(object))
{
PropertyBase& property = property_from_id(*wrapper, property_id);
if((property.object_ == wrapper) && (property.param_spec_ == param_spec))
{
g_value_copy(value, property.value_.gobj());
g_object_notify(object, g_param_spec_get_name(param_spec));
}
else
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, param_spec);
}
}
/**** Glib::PropertyBase ***************************************************/
PropertyBase::PropertyBase(Glib::Object& object, GType value_type)
:
object_ (&object),
value_ (),
param_spec_ (0)
{
value_.init(value_type);
}
PropertyBase::~PropertyBase()
{
if(param_spec_)
g_param_spec_unref(param_spec_);
}
bool PropertyBase::lookup_property(const Glib::ustring& name)
{
g_assert(param_spec_ == 0);
param_spec_ = g_object_class_find_property(G_OBJECT_GET_CLASS(object_->gobj()), name.c_str());
if(param_spec_)
{
g_assert(G_PARAM_SPEC_VALUE_TYPE(param_spec_) == G_VALUE_TYPE(value_.gobj()));
g_param_spec_ref(param_spec_);
}
return (param_spec_ != 0);
}
void PropertyBase::install_property(GParamSpec* param_spec)
{
g_return_if_fail(param_spec != 0);
const unsigned int property_id = property_to_id(*object_, *this);
g_object_class_install_property(G_OBJECT_GET_CLASS(object_->gobj()), property_id, param_spec);
param_spec_ = param_spec;
g_param_spec_ref(param_spec_);
}
const char* PropertyBase::get_name_internal() const
{
const char *const name = g_param_spec_get_name(param_spec_);
g_return_val_if_fail(name != 0, "");
return name;
}
Glib::ustring PropertyBase::get_name() const
{
return Glib::ustring(get_name_internal());
}
void PropertyBase::notify()
{
g_object_notify(object_->gobj(), g_param_spec_get_name(param_spec_));
}
} // namespace Glib

View file

@ -1,171 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_PROPERTY_H
#define _GLIBMM_PROPERTY_H
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/propertyproxy.h>
#include <glibmm/value.h>
namespace Glib
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifdef GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
//For the AIX xlC compiler, I can not find a way to do this without putting the functions in the global namespace. murrayc
extern "C"
{
#endif //GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
void custom_get_property_callback(GObject* object, unsigned int property_id,
GValue* value, GParamSpec* param_spec);
void custom_set_property_callback(GObject* object, unsigned int property_id,
const GValue* value, GParamSpec* param_spec);
#ifdef GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
} //extern "C"
#endif //GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
class PropertyBase
{
public:
Glib::ustring get_name() const;
void notify();
protected:
Glib::Object* object_;
Glib::ValueBase value_;
GParamSpec* param_spec_;
PropertyBase(Glib::Object& object, GType value_type);
~PropertyBase();
bool lookup_property(const Glib::ustring& name);
void install_property(GParamSpec* param_spec);
const char* get_name_internal() const;
private:
// noncopyable
PropertyBase(const PropertyBase&);
PropertyBase& operator=(const PropertyBase&);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
friend void Glib::custom_get_property_callback(GObject* object, unsigned int property_id,
GValue* value, GParamSpec* param_spec);
friend void Glib::custom_set_property_callback(GObject* object, unsigned int property_id,
const GValue* value, GParamSpec* param_spec);
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
};
template <class T>
class Property : public PropertyBase
{
public:
typedef T PropertyType;
typedef Glib::Value<T> ValueType;
Property(Glib::Object& object, const Glib::ustring& name);
Property(Glib::Object& object, const Glib::ustring& name, const PropertyType& default_value);
inline void set_value(const PropertyType& data);
inline PropertyType get_value() const;
inline Property<T>& operator=(const PropertyType& data);
inline operator PropertyType() const;
inline Glib::PropertyProxy<T> get_proxy();
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/**** Glib::Property<T> ****************************************************/
template <class T>
Property<T>::Property(Glib::Object& object, const Glib::ustring& name)
:
PropertyBase(object, ValueType::value_type())
{
if(!lookup_property(name))
install_property(static_cast<ValueType&>(value_).create_param_spec(name));
}
template <class T>
Property<T>::Property(Glib::Object& object, const Glib::ustring& name,
const typename Property<T>::PropertyType& default_value)
:
PropertyBase(object, ValueType::value_type())
{
static_cast<ValueType&>(value_).set(default_value);
if(!lookup_property(name))
install_property(static_cast<ValueType&>(value_).create_param_spec(name));
}
template <class T> inline
void Property<T>::set_value(const typename Property<T>::PropertyType& data)
{
static_cast<ValueType&>(value_).set(data);
this->notify();
}
template <class T> inline
typename Property<T>::PropertyType Property<T>::get_value() const
{
return static_cast<const ValueType&>(value_).get();
}
template <class T> inline
Property<T>& Property<T>::operator=(const typename Property<T>::PropertyType& data)
{
static_cast<ValueType&>(value_).set(data);
this->notify();
return *this;
}
template <class T> inline
Property<T>::operator T() const
{
return static_cast<const ValueType&>(value_).get();
}
template <class T> inline
Glib::PropertyProxy<T> Property<T>::get_proxy()
{
return Glib::PropertyProxy<T>(object_, get_name_internal());
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
} // namespace Glib
#endif /* _GLIBMM_PROPERTY_H */

View file

@ -1,24 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* propertyproxy.cc
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/propertyproxy.h>

View file

@ -1,163 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_PROPERTYPROXY_H
#define _GLIBMM_PROPERTYPROXY_H
/* $Id$ */
/* propertyproxy.h
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/propertyproxy_base.h>
namespace Glib
{
/** A PropertyProxy can be used to get and set the value of an object's property.
* There are usually also get and set methods on the class itself, which you might find more convenient.
* With the PropertyProxy, you may use either get_value() and set_value(), or operator=() and
* operator PropertyType(), like so:
* @code
* int height = cellrenderer.property_height();
* cellrenderer.property_editable() = true;
* @endcode
*
* You may also receive notification when a property's value changes, by connecting to signal_changed().
*/
template <class T>
class PropertyProxy : public PropertyProxy_Base
{
public:
typedef T PropertyType;
PropertyProxy(ObjectBase* obj, const char* name)
: PropertyProxy_Base(obj, name) {}
/** Set the value of this property.
* @param data The new value for the property.
*/
void set_value(const PropertyType& data);
/** Get the value of this property.
* @result The current value of the property.
*/
PropertyType get_value() const;
/** Set the value of this property back to its default value
*/
void reset_value()
{ reset_property_(); }
PropertyProxy<T>& operator=(const PropertyType& data)
{ this->set_value(data); return *this; }
operator PropertyType() const
{ return this->get_value(); }
};
/** See PropertyProxy().
* This property can be written, but not read, so there is no get_value() method.
*/
template <class T>
class PropertyProxy_WriteOnly : public PropertyProxy_Base
{
public:
typedef T PropertyType;
PropertyProxy_WriteOnly(ObjectBase* obj, const char* name)
: PropertyProxy_Base(obj, name) {}
/** Set the value of this property.
* @param data The new value for the property.
*/
void set_value(const PropertyType& data)
{
PropertyProxy_Base& base = *this;
// The downcast to PropertyProxy<T> is safe, and avoids code duplication.
static_cast<PropertyProxy<T>&>(base).set_value(data);
}
/** Set the value of this property back to its default value
*/
void reset_value()
{ reset_property_(); }
PropertyProxy_WriteOnly<T>& operator=(const PropertyType& data)
{ this->set_value(data); return *this; }
};
/** See PropertyProxy().
* This property can be read, but not written, so there is no set_value() method.
*/
template <class T>
class PropertyProxy_ReadOnly : public PropertyProxy_Base
{
public:
typedef T PropertyType;
//obj is const, because this should be returned by const accessors.
PropertyProxy_ReadOnly(const ObjectBase* obj, const char* name)
: PropertyProxy_Base(const_cast<ObjectBase*>(obj), name) {}
/** Get the value of this property.
* @result The current value of the property.
*/
PropertyType get_value() const
{
const PropertyProxy_Base& base = *this;
// The downcast to PropertyProxy<T> is safe, and avoids code duplication.
return static_cast<const PropertyProxy<T>&>(base).get_value();
}
operator PropertyType() const
{ return this->get_value(); }
};
/**** Template Implementation **********************************************/
#ifndef DOXYGEN_SHOULD_SKIP_THIS
template <class T>
void PropertyProxy<T>::set_value(const T& data)
{
Glib::Value<T> value;
value.init(Glib::Value<T>::value_type());
value.set(data);
set_property_(value);
}
template <class T>
T PropertyProxy<T>::get_value() const
{
Glib::Value<T> value;
value.init(Glib::Value<T>::value_type());
get_property_(value);
return value.get();
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
} // namespace Glib
#endif /* _GLIBMM_PROPERTYPROXY_H */

View file

@ -1,151 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* propertyproxy_base.h
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/propertyproxy_base.h>
#include <glibmm/signalproxy_connectionnode.h>
#include <glibmm/object.h>
#include <glibmm/private/object_p.h>
namespace Glib
{
/** PropertyProxyConnectionNode is a connection node for use with SignalProxyProperty.
* It's like ProxyConnectionNode, but it contains the property name too.
*/
class PropertyProxyConnectionNode : public SignalProxyConnectionNode
{
public:
friend class SignalProxyProperty;
PropertyProxyConnectionNode(const sigc::slot_base& slot, GObject* gobject, const gchar* property_name);
protected:
//This will be examined in the callback.
//Should be a static string literal.
const gchar* property_name_;
};
PropertyProxyConnectionNode::PropertyProxyConnectionNode(const sigc::slot_base& slot, GObject* gobject, const gchar* property_name)
: SignalProxyConnectionNode(slot, gobject),
property_name_(property_name)
{
}
//SignalProxyProperty implementation:
SignalProxyProperty::SignalProxyProperty(Glib::ObjectBase* obj, const gchar* property_name)
: SignalProxyBase(obj),
property_name_(property_name)
{
}
SignalProxyProperty::~SignalProxyProperty()
{
}
sigc::connection SignalProxyProperty::connect(const SlotType& sl)
{
// create a proxy to hold our connection info
PropertyProxyConnectionNode* pConnectionNode = new PropertyProxyConnectionNode(sl, obj_->gobj(), property_name_ );
// connect it to gtk+
// pConnectionNode will be passed as the data argument to the callback.
// The callback will then call the virtual Object::property_change_notify() method,
// which will contain a switch/case statement which will examine the property name.
pConnectionNode->connection_id_ = g_signal_connect_data(obj_->gobj(),
"notify", (GCallback)(&callback), pConnectionNode,
&PropertyProxyConnectionNode::destroy_notify_handler,
G_CONNECT_AFTER);
return sigc::connection(pConnectionNode->slot_);
}
void SignalProxyProperty::callback(GObject*, GParamSpec* pspec, gpointer data) //static
{
if(pspec && data)
{
//Get the name of the property that has changed:
const char* property_name_changed = pspec->name;
//Get the name of the property that we are waiting for:
PropertyProxyConnectionNode* conn = static_cast<PropertyProxyConnectionNode*>(data);
const char* property_name_monitored = conn->property_name_;
//If it's the correct property, then call the signal handler:
if(strcmp(property_name_changed, property_name_monitored) == 0)
{
if(sigc::slot_base *const slot = data_to_slot(data))
(*static_cast<sigc::slot<void>*>(slot))();
}
}
}
//PropertyProxy_Base implementation:
PropertyProxy_Base::PropertyProxy_Base(ObjectBase* obj, const char* property_name)
:
obj_ (obj),
property_name_ (property_name)
{}
PropertyProxy_Base::PropertyProxy_Base(const PropertyProxy_Base& other)
:
obj_ (other.obj_),
property_name_ (other.property_name_)
{}
SignalProxyProperty PropertyProxy_Base::signal_changed()
{
return SignalProxyProperty(obj_, property_name_);
}
void PropertyProxy_Base::set_property_(const Glib::ValueBase& value)
{
g_object_set_property(obj_->gobj(), property_name_, value.gobj());
}
void PropertyProxy_Base::get_property_(Glib::ValueBase& value) const
{
g_object_get_property(obj_->gobj(), property_name_, value.gobj());
}
void PropertyProxy_Base::reset_property_()
{
// Get information about the parameter:
const GParamSpec *const pParamSpec =
g_object_class_find_property(G_OBJECT_GET_CLASS(obj_->gobj()), property_name_);
g_return_if_fail(pParamSpec != 0);
Glib::ValueBase value;
value.init(G_PARAM_SPEC_VALUE_TYPE(pParamSpec));
// An explicit reset is not needed, because ValueBase:init()
// has already initialized it to the default value for this type.
// value.reset();
g_object_set_property(obj_->gobj(), property_name_, value.gobj());
}
} // namespace Glib

View file

@ -1,84 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_PROPERTYPROXY_BASE_H
#define _GLIBMM_PROPERTYPROXY_BASE_H
/* $Id$ */
/* propertyproxy_base.h
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/value.h>
#include <glibmm/signalproxy.h>
namespace Glib
{
class ObjectBase;
/// Use the connect() method, with sigc::ptr_fun() or sig::mem_fun() to connect signals to signal handlers.
class SignalProxyProperty : public SignalProxyBase
{
public:
friend class PropertyProxy_Base;
SignalProxyProperty(Glib::ObjectBase* obj, const gchar* property_name);
~SignalProxyProperty();
typedef sigc::slot<void> SlotType;
sigc::connection connect(const SlotType& sl);
protected:
static void callback(GObject* object, GParamSpec* pspec, gpointer data);
const char* property_name_; //Should be a static string literal.
private:
SignalProxyProperty& operator=(const SignalProxyProperty&); // not implemented
};
class PropertyProxy_Base
{
public:
PropertyProxy_Base(ObjectBase* obj, const char* property_name);
PropertyProxy_Base(const PropertyProxy_Base& other);
///This signal will be emitted when the property changes.
SignalProxyProperty signal_changed();
ObjectBase* get_object() const { return obj_; }
const char* get_name() const { return property_name_; }
protected:
void set_property_(const Glib::ValueBase& value);
void get_property_(Glib::ValueBase& value) const;
void reset_property_();
ObjectBase* obj_; //The C++ wrapper instance of which this PropertyProxy is a member.
const char* property_name_; //Should be a static string literal.
private:
//Declared as private, but not implemented to prevent any automatically generated implementation.
PropertyProxy_Base& operator=(const PropertyProxy_Base&);
};
} // namespace Glib
#endif /* _GLIBMM_PROPERTYPROXY_BASE_H */

View file

@ -1,66 +0,0 @@
/* $Id$ */
/* quark.cc
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gquark.h>
#include <glibmm/quark.h>
namespace Glib
{
QueryQuark::QueryQuark(const GQuark& q)
: quark_(q)
{}
QueryQuark::QueryQuark(const ustring& s)
: quark_(g_quark_try_string(s.c_str()))
{}
QueryQuark::QueryQuark(const char* s)
: quark_(g_quark_try_string(s))
{}
QueryQuark& QueryQuark::operator=(const QueryQuark& q)
{ quark_=q.quark_;
return *this;
}
QueryQuark::operator ustring() const
{
return ustring(g_quark_to_string(quark_));
}
Quark::Quark(const ustring& s)
: QueryQuark(g_quark_from_string(s.c_str()))
{}
Quark::Quark(const char* s)
: QueryQuark(g_quark_from_string(s))
{}
Quark::~Quark()
{}
GQuark quark_ = 0;
GQuark quark_cpp_wrapper_deleted_ = 0;
} /* namespace Glib */

View file

@ -1,88 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_QUARK_H
#define _GLIBMM_QUARK_H
/* $Id$ */
/* quark.h
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gquark.h>
#include <glibmm/ustring.h>
namespace Glib
{
/** Quarks are unique IDs in Glib for strings for use in
* hash table lookups. Each Quark is unique but may change
* between runs.
*
* QueryQuark is a converter class for looking up but not
* allocating an ID. An id means the quark lookup failed.
*
* Quark is used for actions for which the id should live on
* While QueryQuark should be used for queries.
* ie.
* void set_data (const Quark&, void * data);
* void* get_data (const QueryQuark&);
*/
class QueryQuark
{
public:
QueryQuark(const GQuark& q);
QueryQuark(const ustring& s);
QueryQuark(const char*s);
~QueryQuark() {}
QueryQuark& operator=(const QueryQuark& q);
operator ustring() const;
operator GQuark() const {return quark_;}
GQuark id() const {return quark_;}
private:
GQuark quark_;
};
class Quark: public QueryQuark
{
public:
Quark(const ustring& s);
Quark(const char* s);
~Quark();
};
/** @relates Glib::QueryQuark */
inline bool operator==(const QueryQuark& a, const QueryQuark& b)
{ return a.id() == b.id(); }
/** @relates Glib::QueryQuark */
inline bool operator!=(const QueryQuark& a, const QueryQuark& b)
{ return a.id() != b.id(); }
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// TODO: Put this somewhere else.
// (internal) The quark for C++ wrappers.
extern GLIBMM_API GQuark quark_;
extern GLIBMM_API GQuark quark_cpp_wrapper_deleted_;
#endif
} /* namespace Glib */
#endif /* _GLIBMM_QUARK_H */

View file

@ -1,76 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* random.cc
*
* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/random.h>
#include <glib/grand.h>
namespace Glib
{
Rand::Rand()
:
gobject_ (g_rand_new())
{}
Rand::Rand(guint32 seed)
:
gobject_ (g_rand_new_with_seed(seed))
{}
Rand::~Rand()
{
g_rand_free(gobject_);
}
void Rand::set_seed(guint32 seed)
{
g_rand_set_seed(gobject_, seed);
}
bool Rand::get_bool()
{
return g_rand_boolean(gobject_);
}
guint32 Rand::get_int()
{
return g_rand_int(gobject_);
}
gint32 Rand::get_int_range(gint32 begin, gint32 end)
{
return g_rand_int_range(gobject_, begin, end);
}
double Rand::get_double()
{
return g_rand_double(gobject_);
}
double Rand::get_double_range(double begin, double end)
{
return g_rand_double_range(gobject_, begin, end);
}
} // namespace Glib

View file

@ -1,73 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_RANDOM_H
#define _GLIBMM_RANDOM_H
/* $Id$ */
/* random.h
*
* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gtypes.h>
extern "C" { typedef struct _GRand GRand; }
namespace Glib
{
/** @defgroup Random Random Numbers
* Pseudo random number generator.
* @{
*/
class Rand
{
public:
Rand();
explicit Rand(guint32 seed);
~Rand();
void set_seed(guint32 seed);
bool get_bool();
guint32 get_int();
gint32 get_int_range(gint32 begin, gint32 end);
double get_double();
double get_double_range(double begin, double end);
GRand* gobj() { return gobject_; }
const GRand* gobj() const { return gobject_; }
private:
GRand* gobject_;
// noncopyable
Rand(const Rand&);
Rand& operator=(const Rand&);
};
/** @} group Random */
} // namespace Glib
#endif /* _GLIBMM_RANDOM_H */

View file

@ -1,318 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_REFPTR_H
#define _GLIBMM_REFPTR_H
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
namespace Glib
{
/** RefPtr<> is a reference-counting shared smartpointer.
*
* Some objects in gtkmm are obtained from a shared
* store. Consequently you cannot instantiate them yourself. Instead they
* return a RefPtr which behaves much like an ordinary pointer in that members
* can be reached with the usual <code>object_ptr->member</code> notation.
* Unlike most other smart pointers, RefPtr doesn't support dereferencing
* through <code>*object_ptr</code>.
*
* Reference counting means that a shared reference count is incremented each
* time a RefPtr is copied, and decremented each time a RefPtr is destroyed,
* for instance when it leaves its scope. When the reference count reaches
* zero, the contained object is deleted, meaning you don't need to remember
* to delete the object.
*
* RefPtr<> can store any class that has reference() and unreference() methods.
* In gtkmm, that is anything derived from Glib::ObjectBase, such as
* Gdk::Pixmap.
*
* See the "Memory Management" section in the "Programming with gtkmm"
* book for further information.
*/
template <class T_CppObject>
class RefPtr
{
public:
/** Default constructor
*
* Afterwards it will be null and use of -> will cause a segmentation fault.
*/
inline RefPtr();
/// Destructor - decrements reference count.
inline ~RefPtr();
/// For use only by the ::create() methods.
explicit inline RefPtr(T_CppObject* pCppObject);
/** Copy constructor
*
* This increments the shared reference count.
*/
inline RefPtr(const RefPtr<T_CppObject>& src);
/** Copy constructor (from different, but castable type).
*
* Increments the reference count.
*/
template <class T_CastFrom>
inline RefPtr(const RefPtr<T_CastFrom>& src);
/** Swap the contents of two RefPtr<>.
* This method swaps the internal pointers to T_CppObject. This can be
* done safely without involving a reference/unreference cycle and is
* therefore highly efficient.
*/
inline void swap(RefPtr<T_CppObject>& other);
/// Copy from another RefPtr:
inline RefPtr<T_CppObject>& operator=(const RefPtr<T_CppObject>& src);
/** Copy from different, but castable type).
*
* Increments the reference count.
*/
template <class T_CastFrom>
inline RefPtr<T_CppObject>& operator=(const RefPtr<T_CastFrom>& src);
/// Tests whether the RefPtr<> point to the same underlying instance.
inline bool operator==(const RefPtr<T_CppObject>& src) const;
/// See operator==().
inline bool operator!=(const RefPtr<T_CppObject>& src) const;
/** Dereferencing.
*
* Use the methods of the underlying instance like so:
* <code>refptr->memberfun()</code>.
*/
inline T_CppObject* operator->() const;
/** Test whether the RefPtr<> points to any underlying instance.
*
* Mimics usage of ordinary pointers:
* @code
* if (ptr)
* do_something();
* @endcode
*/
inline operator bool() const;
/// Set underlying instance to 0, decrementing reference count of existing instance appropriately.
inline void clear();
/** Dynamic cast to derived class.
*
* The RefPtr can't be cast with the usual notation so instead you can use
* @code
* ptr_derived = RefPtr<Derived>::cast_dynamic(ptr_base);
* @endcode
*/
template <class T_CastFrom>
static inline RefPtr<T_CppObject> cast_dynamic(const RefPtr<T_CastFrom>& src);
/** Static cast to derived class.
*
* Like the dynamic cast; the notation is
* @code
* ptr_derived = RefPtr<Derived>::cast_static(ptr_base);
* @endcode
*/
template <class T_CastFrom>
static inline RefPtr<T_CppObject> cast_static(const RefPtr<T_CastFrom>& src);
private:
T_CppObject* pCppObject_;
};
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// RefPtr<>::operator->() comes first here since it's used by other methods.
// If it would come after them it wouldn't be inlined.
template <class T_CppObject> inline
T_CppObject* RefPtr<T_CppObject>::operator->() const
{
return pCppObject_;
}
template <class T_CppObject> inline
RefPtr<T_CppObject>::RefPtr()
:
pCppObject_ (0)
{}
template <class T_CppObject> inline
RefPtr<T_CppObject>::~RefPtr()
{
if(pCppObject_)
pCppObject_->unreference(); // This could cause pCppObject to be deleted.
}
template <class T_CppObject> inline
RefPtr<T_CppObject>::RefPtr(T_CppObject* pCppObject)
:
pCppObject_ (pCppObject)
{}
template <class T_CppObject> inline
RefPtr<T_CppObject>::RefPtr(const RefPtr<T_CppObject>& src)
:
pCppObject_ (src.pCppObject_)
{
if(pCppObject_)
pCppObject_->reference();
}
// The templated ctor allows copy construction from any object that's
// castable. Thus, it does downcasts:
// base_ref = derived_ref
template <class T_CppObject>
template <class T_CastFrom>
inline
RefPtr<T_CppObject>::RefPtr(const RefPtr<T_CastFrom>& src)
:
// A different RefPtr<> will not allow us access to pCppObject_. We need
// to add a get_underlying() for this, but that would encourage incorrect
// use, so we use the less well-known operator->() accessor:
pCppObject_ (src.operator->())
{
if(pCppObject_)
pCppObject_->reference();
}
template <class T_CppObject> inline
void RefPtr<T_CppObject>::swap(RefPtr<T_CppObject>& other)
{
T_CppObject *const temp = pCppObject_;
pCppObject_ = other.pCppObject_;
other.pCppObject_ = temp;
}
template <class T_CppObject> inline
RefPtr<T_CppObject>& RefPtr<T_CppObject>::operator=(const RefPtr<T_CppObject>& src)
{
// In case you haven't seen the swap() technique to implement copy
// assignment before, here's what it does:
//
// 1) Create a temporary RefPtr<> instance via the copy ctor, thereby
// increasing the reference count of the source object.
//
// 2) Swap the internal object pointers of *this and the temporary
// RefPtr<>. After this step, *this already contains the new pointer,
// and the old pointer is now managed by temp.
//
// 3) The destructor of temp is executed, thereby unreferencing the
// old object pointer.
//
// This technique is described in Herb Sutter's "Exceptional C++", and
// has a number of advantages over conventional approaches:
//
// - Code reuse by calling the copy ctor.
// - Strong exception safety for free.
// - Self assignment is handled implicitely.
// - Simplicity.
// - It just works and is hard to get wrong; i.e. you can use it without
// even thinking about it to implement copy assignment whereever the
// object data is managed indirectly via a pointer, which is very common.
RefPtr<T_CppObject> temp (src);
this->swap(temp);
return *this;
}
template <class T_CppObject>
template <class T_CastFrom>
inline
RefPtr<T_CppObject>& RefPtr<T_CppObject>::operator=(const RefPtr<T_CastFrom>& src)
{
RefPtr<T_CppObject> temp (src);
this->swap(temp);
return *this;
}
template <class T_CppObject> inline
bool RefPtr<T_CppObject>::operator==(const RefPtr<T_CppObject>& src) const
{
return (pCppObject_ == src.pCppObject_);
}
template <class T_CppObject> inline
bool RefPtr<T_CppObject>::operator!=(const RefPtr<T_CppObject>& src) const
{
return (pCppObject_ != src.pCppObject_);
}
template <class T_CppObject> inline
RefPtr<T_CppObject>::operator bool() const
{
return (pCppObject_ != 0);
}
template <class T_CppObject> inline
void RefPtr<T_CppObject>::clear()
{
RefPtr<T_CppObject> temp; // swap with an empty RefPtr<> to clear *this
this->swap(temp);
}
template <class T_CppObject>
template <class T_CastFrom>
inline
RefPtr<T_CppObject> RefPtr<T_CppObject>::cast_dynamic(const RefPtr<T_CastFrom>& src)
{
T_CppObject *const pCppObject = dynamic_cast<T_CppObject*>(src.operator->());
if(pCppObject)
pCppObject->reference();
return RefPtr<T_CppObject>(pCppObject);
}
template <class T_CppObject>
template <class T_CastFrom>
inline
RefPtr<T_CppObject> RefPtr<T_CppObject>::cast_static(const RefPtr<T_CastFrom>& src)
{
T_CppObject *const pCppObject = static_cast<T_CppObject*>(src.operator->());
if(pCppObject)
pCppObject->reference();
return RefPtr<T_CppObject>(pCppObject);
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
/** @relates Glib::RefPtr */
template <class T_CppObject> inline
void swap(RefPtr<T_CppObject>& lhs, RefPtr<T_CppObject>& rhs)
{
lhs.swap(rhs);
}
} // namespace Glib
#endif /* _GLIBMM_REFPTR_H */

View file

@ -1,108 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_SARRAY_H
#define _GLIBMM_SARRAY_H
/* $Id$ */
/* array.h
*
* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/arrayhandle.h>
#include <glibmm/ustring.h>
namespace Glib { typedef Glib::ArrayHandle<Glib::ustring> SArray; }
#if 0
namespace Glib
{
template <>
inline void cpp_type_to_c_type(const ustring& cpp_value, type_constpch& ref_c_value)
{
ref_c_value = cpp_value.c_str();
}
template <>
inline void cpp_type_to_c_type(const std::string& cpp_value, type_constpch& ref_c_value)
{
ref_c_value = cpp_value.c_str();
}
typedef Array<Glib::ustring, const char*> SArray;
/*
class SArray: public Array<nstring, const char*>
{
public:
typedef const char* T_c;
typedef Array<nstring, const char*> type_base;
SArray(const SArray& src);
// copy other containers
template <typename T_container>
SArray(const T_container& t)
{
owned_ = Array_Helpers::Traits<T_container, pointer>::get_owned();
size_ = Array_Helpers::Traits<T_container, pointer>::get_size(t);
pData_ = Array_Helpers::Traits<T_container, pointer>::get_data(t);
}
SArray(const T_c* pValues, size_type size);
// copy a sequence
template <typename Iterator>
SArray(Iterator b, Iterator e);
operator std::vector<nstring>() const;
operator std::vector<ustring>() const;
operator std::vector<std::string>() const;
operator std::deque<nstring>() const;
operator std::deque<ustring>() const;
operator std::deque<std::string>() const;
operator std::list<nstring>() const;
operator std::list<ustring>() const;
operator std::list<std::string>() const;
};
//template <typename T_container>
//SArray::SArray(const T_container& t)
//: type_base(t)
//{
//}
template <typename Iterator>
SArray::SArray(Iterator b, Iterator e)
: type_base(b, e)
{
}
*/
} // namespace Glib
#endif /* #if 0 */
#endif // _GLIBMM_SARRAY_H

View file

@ -1,93 +0,0 @@
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <glibmm/shell.h>
#include <glibmm/private/shell_p.h>
// -*- c++ -*-
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/utility.h>
namespace Glib
{
/**** shell utility functions **********************************************/
Glib::ArrayHandle<std::string> shell_parse_argv(const std::string& command_line)
{
char** argv = 0;
int argc = 0;
GError* error = 0;
g_shell_parse_argv(command_line.c_str(), &argc, &argv, &error);
if(error)
Glib::Error::throw_exception(error);
return Glib::ArrayHandle<std::string>(argv, argc, Glib::OWNERSHIP_DEEP);
}
std::string shell_quote(const std::string& unquoted_string)
{
const ScopedPtr<char> buf (g_shell_quote(unquoted_string.c_str()));
return std::string(buf.get());
}
std::string shell_unquote(const std::string& quoted_string)
{
GError* error = 0;
char *const buf = g_shell_unquote(quoted_string.c_str(), &error);
if(error)
Glib::Error::throw_exception(error);
return std::string(ScopedPtr<char>(buf).get());
}
} // namespace Glib
namespace
{
} // anonymous namespace
Glib::ShellError::ShellError(Glib::ShellError::Code error_code, const Glib::ustring& error_message)
:
Glib::Error (G_SHELL_ERROR, error_code, error_message)
{}
Glib::ShellError::ShellError(GError* gobject)
:
Glib::Error (gobject)
{}
Glib::ShellError::Code Glib::ShellError::code() const
{
return static_cast<Code>(Glib::Error::code());
}
void Glib::ShellError::throw_func(GError* gobject)
{
throw Glib::ShellError(gobject);
}

View file

@ -1,123 +0,0 @@
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GLIBMM_SHELL_H
#define _GLIBMM_SHELL_H
/* $Id$ */
/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib/gshell.h>
#include <string>
#include <glibmm/arrayhandle.h>
#include <glibmm/error.h>
#include <glibmmconfig.h>
GLIBMM_USING_STD(string)
namespace Glib
{
/** @defgroup ShellUtils Shell-related Utilities
* Shell-like command line handling.
* @{
*/
/** Exception class for shell utility errors.
*/
class ShellError : public Glib::Error
{
public:
enum Code
{
BAD_QUOTING,
EMPTY_STRING,
FAILED
};
ShellError(Code error_code, const Glib::ustring& error_message);
explicit ShellError(GError* gobject);
Code code() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
private:
static void throw_func(GError* gobject);
friend void wrap_init(); // uses throw_func()
#endif
};
/** Parses a command line into an argument vector, in much the same way the
* shell would, but without many of the expansions the shell would perform
* (variable expansion, globs, operators, filename expansion, etc.\ are not
* supported). The results are defined to be the same as those you would
* get from a UNIX98 /bin/sh, as long as the input contains none of the
* unsupported shell expansions. If the input does contain such expansions,
* they are passed through literally.
* @param command_line Command line to parse.
* @return Array of args (The generic ArrayHandle will be implicitly
* converted to any STL compatible container type).
* @throw Glib::ShellError
*/
Glib::ArrayHandle<std::string> shell_parse_argv(const std::string& command_line);
/** Quotes a string so that the shell (/bin/sh) will interpret the quoted
* string to mean @a unquoted_string. If you pass a filename to the shell,
* for example, you should first quote it with this function. The quoting
* style used is undefined (single or double quotes may be used).
* @param unquoted_string A literal string.
* @return A quoted string.
*/
std::string shell_quote(const std::string& unquoted_string);
/** Unquotes a string as the shell (/bin/sh) would. Only handles quotes; if
* a string contains file globs, arithmetic operators, variables, backticks,
* redirections, or other special-to-the-shell features, the result will be
* different from the result a real shell would produce (the variables,
* backticks, etc. will be passed through literally instead of being expanded).
* This function is guaranteed to succeed if applied to the result of
* shell_quote(). If it fails, it throws a Glib::ShellError exception. The
* @a quoted_string need not actually contain quoted or escaped text;
* shell_unquote() simply goes through the string and unquotes/unescapes
* anything that the shell would. Both single and double quotes are handled,
* as are escapes including escaped newlines.
*
* Shell quoting rules are a bit strange. Single quotes preserve the literal
* string exactly. Escape sequences are not allowed; not even <tt>\\'</tt> --
* if you want a <tt>'</tt> in the quoted text, you have to do something like
* <tt>'foo'\\''bar'</tt>. Double quotes allow <tt>$</tt>, <tt>`</tt>,
* <tt>"</tt>, <tt>\\</tt>, and newline to be escaped with backslash.
* Otherwise double quotes preserve things literally.
*
* @param quoted_string Shell-quoted string.
* @return An unquoted string.
* @throw Glib::ShellError
*/
std::string shell_unquote(const std::string& quoted_string);
/** @} group ShellUtils */
} // namespace Glib
#endif /* _GLIBMM_SHELL_H */

View file

@ -1,105 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* signalproxy.cc
*
* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glib-object.h>
#include <glibmm/exceptionhandler.h>
#include <glibmm/object.h>
#include <glibmm/signalproxy.h>
namespace Glib
{
// SignalProxyBase implementation:
SignalProxyBase::SignalProxyBase(Glib::ObjectBase* obj)
:
obj_ (obj)
{}
// SignalProxyNormal implementation:
SignalProxyNormal::SignalProxyNormal(Glib::ObjectBase* obj, const SignalProxyInfo* info)
:
SignalProxyBase (obj),
info_ (info)
{}
SignalProxyNormal::~SignalProxyNormal()
{}
sigc::slot_base&
SignalProxyNormal::connect_(const sigc::slot_base& slot, bool after)
{
return connect_impl_(info_->callback, slot, after);
}
sigc::slot_base&
SignalProxyNormal::connect_notify_(const sigc::slot_base& slot, bool after)
{
return connect_impl_(info_->notify_callback, slot, after);
}
sigc::slot_base&
SignalProxyNormal::connect_impl_(GCallback callback, const sigc::slot_base& slot, bool after)
{
// create a proxy to hold our connection info
SignalProxyConnectionNode *const pConnectionNode =
new SignalProxyConnectionNode(slot, obj_->gobj());
// connect it to glib
// pConnectionNode will be passed in the data argument to the callback.
pConnectionNode->connection_id_ = g_signal_connect_data(
obj_->gobj(), info_->signal_name, callback, pConnectionNode,
&SignalProxyConnectionNode::destroy_notify_handler,
static_cast<GConnectFlags>((after) ? G_CONNECT_AFTER : 0));
return pConnectionNode->slot_;
}
void SignalProxyNormal::emission_stop()
{
g_signal_stop_emission_by_name(obj_->gobj(), info_->signal_name);
}
// static
void SignalProxyNormal::slot0_void_callback(GObject* self, void* data)
{
// Do not try to call a signal on a disassociated wrapper.
if(Glib::ObjectBase::_get_current_wrapper(self))
{
try
{
if(sigc::slot_base *const slot = data_to_slot(data))
(*static_cast<sigc::slot<void>*>(slot))();
}
catch(...)
{
Glib::exception_handlers_invoke();
}
}
}
} // namespace Glib

View file

@ -1,394 +0,0 @@
// -*- c++ -*-
/* This is a generated file, do not edit. Generated from signalproxy.h.m4 */
#ifndef _GLIBMM_SIGNALPROXY_H
#define _GLIBMM_SIGNALPROXY_H
extern "C"
{
typedef void (*GCallback) (void);
typedef struct _GObject GObject;
}
#include <sigc++/sigc++.h>
#include <glibmm/signalproxy_connectionnode.h>
namespace Glib
{
// Forward declarations
class ObjectBase;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
struct SignalProxyInfo
{
const char* signal_name;
GCallback callback;
GCallback notify_callback;
};
#endif //DOXYGEN_SHOULD_SKIP_THIS
// This base class is used by SignalProxyNormal and SignalProxyProperty.
class SignalProxyBase
{
public:
SignalProxyBase(Glib::ObjectBase* obj);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
static inline sigc::slot_base* data_to_slot(void* data)
{
SignalProxyConnectionNode *const pConnectionNode = static_cast<SignalProxyConnectionNode*>(data);
// Return 0 if the connection is blocked.
return (!pConnectionNode->slot_.blocked()) ? &pConnectionNode->slot_ : 0;
}
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
protected:
ObjectBase* obj_;
private:
SignalProxyBase& operator=(const SignalProxyBase&); // not implemented
};
// shared portion of a Signal
/** The SignalProxy provides an API similar to sigc::signal that can be used to
* connect sigc::slots to glib signals.
*
* This holds the name of the glib signal and the object
* which might emit it. Actually, proxies are controlled by
* the template derivatives, which serve as gatekeepers for the
* types allowed on a particular signal.
*
*/
class SignalProxyNormal : public SignalProxyBase
{
public:
~SignalProxyNormal();
/// stops the current signal emmision (not in libsigc++)
void emission_stop();
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// This callback for SignalProxy0<void>
// is defined here to avoid code duplication.
static void slot0_void_callback(GObject*, void* data);
#endif
protected:
/** Create a proxy for a signal that can be emitted by @a obj.
* @param obj The object that can emit the signal.
* @param info Information about the signal, including its name, and the C callbacks that should be called by glib.
*/
SignalProxyNormal(Glib::ObjectBase* obj, const SignalProxyInfo* info);
/** Connects a signal to a generic signal handler. This is called by connect() in derived SignalProxy classes.
*
* @param slot The signal handler, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::slot_base& connect_(const sigc::slot_base& slot, bool after);
/** Connects a signal to a signal handler without a return value.
* This is called by connect() in derived SignalProxy classes.
*
* By default, the signal handler will be called before the default signal handler,
* in which case any return value would be replaced anyway by that of the later signal handler.
*
* @param slot The signal handler, which should have a void return type, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::slot_base& connect_notify_(const sigc::slot_base& slot, bool after);
private:
const SignalProxyInfo* info_;
//TODO: We could maybe replace both connect_ and connect_notify_ with this in future, because they don't do anything extra.
/** This is called by connect_ and connect_impl_.
*/
sigc::slot_base& connect_impl_(GCallback callback, const sigc::slot_base& slot, bool after);
// no copy assignment
SignalProxyNormal& operator=(const SignalProxyNormal&);
};
/**** Glib::SignalProxy0 ***************************************************/
/** Proxy for signals with 0 arguments.
* Use the connect() method, with sigc::mem_fun() or sigc::ptr_fun() to connect signals to signal handlers.
*/
template <class R>
class SignalProxy0 : public SignalProxyNormal
{
public:
typedef sigc::slot<R> SlotType;
typedef sigc::slot<void> VoidSlotType;
SignalProxy0(ObjectBase* obj, const SignalProxyInfo* info)
: SignalProxyNormal(obj, info) {}
/** Connects a signal to a signal handler.
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect(const SlotType& slot, bool after = true)
{ return sigc::connection(connect_(slot, after)); }
/** Connects a signal to a signal handler without a return value.
* By default, the signal handler will be called before the default signal handler,
* in which case any return value would be replaced anyway by that of the later signal handler.
*
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, which should have a void return type, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect_notify(const VoidSlotType& slot, bool after = false)
{ return sigc::connection(connect_notify_(slot, after)); }
};
/**** Glib::SignalProxy1 ***************************************************/
/** Proxy for signals with 1 arguments.
* Use the connect() method, with sigc::mem_fun() or sigc::ptr_fun() to connect signals to signal handlers.
*/
template <class R,class P1>
class SignalProxy1 : public SignalProxyNormal
{
public:
typedef sigc::slot<R,P1> SlotType;
typedef sigc::slot<void,P1> VoidSlotType;
SignalProxy1(ObjectBase* obj, const SignalProxyInfo* info)
: SignalProxyNormal(obj, info) {}
/** Connects a signal to a signal handler.
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect(const SlotType& slot, bool after = true)
{ return sigc::connection(connect_(slot, after)); }
/** Connects a signal to a signal handler without a return value.
* By default, the signal handler will be called before the default signal handler,
* in which case any return value would be replaced anyway by that of the later signal handler.
*
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, which should have a void return type, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect_notify(const VoidSlotType& slot, bool after = false)
{ return sigc::connection(connect_notify_(slot, after)); }
};
/**** Glib::SignalProxy2 ***************************************************/
/** Proxy for signals with 2 arguments.
* Use the connect() method, with sigc::mem_fun() or sigc::ptr_fun() to connect signals to signal handlers.
*/
template <class R,class P1,class P2>
class SignalProxy2 : public SignalProxyNormal
{
public:
typedef sigc::slot<R,P1,P2> SlotType;
typedef sigc::slot<void,P1,P2> VoidSlotType;
SignalProxy2(ObjectBase* obj, const SignalProxyInfo* info)
: SignalProxyNormal(obj, info) {}
/** Connects a signal to a signal handler.
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect(const SlotType& slot, bool after = true)
{ return sigc::connection(connect_(slot, after)); }
/** Connects a signal to a signal handler without a return value.
* By default, the signal handler will be called before the default signal handler,
* in which case any return value would be replaced anyway by that of the later signal handler.
*
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, which should have a void return type, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect_notify(const VoidSlotType& slot, bool after = false)
{ return sigc::connection(connect_notify_(slot, after)); }
};
/**** Glib::SignalProxy3 ***************************************************/
/** Proxy for signals with 3 arguments.
* Use the connect() method, with sigc::mem_fun() or sigc::ptr_fun() to connect signals to signal handlers.
*/
template <class R,class P1,class P2,class P3>
class SignalProxy3 : public SignalProxyNormal
{
public:
typedef sigc::slot<R,P1,P2,P3> SlotType;
typedef sigc::slot<void,P1,P2,P3> VoidSlotType;
SignalProxy3(ObjectBase* obj, const SignalProxyInfo* info)
: SignalProxyNormal(obj, info) {}
/** Connects a signal to a signal handler.
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect(const SlotType& slot, bool after = true)
{ return sigc::connection(connect_(slot, after)); }
/** Connects a signal to a signal handler without a return value.
* By default, the signal handler will be called before the default signal handler,
* in which case any return value would be replaced anyway by that of the later signal handler.
*
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, which should have a void return type, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect_notify(const VoidSlotType& slot, bool after = false)
{ return sigc::connection(connect_notify_(slot, after)); }
};
/**** Glib::SignalProxy4 ***************************************************/
/** Proxy for signals with 4 arguments.
* Use the connect() method, with sigc::mem_fun() or sigc::ptr_fun() to connect signals to signal handlers.
*/
template <class R,class P1,class P2,class P3,class P4>
class SignalProxy4 : public SignalProxyNormal
{
public:
typedef sigc::slot<R,P1,P2,P3,P4> SlotType;
typedef sigc::slot<void,P1,P2,P3,P4> VoidSlotType;
SignalProxy4(ObjectBase* obj, const SignalProxyInfo* info)
: SignalProxyNormal(obj, info) {}
/** Connects a signal to a signal handler.
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect(const SlotType& slot, bool after = true)
{ return sigc::connection(connect_(slot, after)); }
/** Connects a signal to a signal handler without a return value.
* By default, the signal handler will be called before the default signal handler,
* in which case any return value would be replaced anyway by that of the later signal handler.
*
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, which should have a void return type, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect_notify(const VoidSlotType& slot, bool after = false)
{ return sigc::connection(connect_notify_(slot, after)); }
};
/**** Glib::SignalProxy5 ***************************************************/
/** Proxy for signals with 5 arguments.
* Use the connect() method, with sigc::mem_fun() or sigc::ptr_fun() to connect signals to signal handlers.
*/
template <class R,class P1,class P2,class P3,class P4,class P5>
class SignalProxy5 : public SignalProxyNormal
{
public:
typedef sigc::slot<R,P1,P2,P3,P4,P5> SlotType;
typedef sigc::slot<void,P1,P2,P3,P4,P5> VoidSlotType;
SignalProxy5(ObjectBase* obj, const SignalProxyInfo* info)
: SignalProxyNormal(obj, info) {}
/** Connects a signal to a signal handler.
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect(const SlotType& slot, bool after = true)
{ return sigc::connection(connect_(slot, after)); }
/** Connects a signal to a signal handler without a return value.
* By default, the signal handler will be called before the default signal handler,
* in which case any return value would be replaced anyway by that of the later signal handler.
*
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, which should have a void return type, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect_notify(const VoidSlotType& slot, bool after = false)
{ return sigc::connection(connect_notify_(slot, after)); }
};
/**** Glib::SignalProxy6 ***************************************************/
/** Proxy for signals with 6 arguments.
* Use the connect() method, with sigc::mem_fun() or sigc::ptr_fun() to connect signals to signal handlers.
*/
template <class R,class P1,class P2,class P3,class P4,class P5,class P6>
class SignalProxy6 : public SignalProxyNormal
{
public:
typedef sigc::slot<R,P1,P2,P3,P4,P5,P6> SlotType;
typedef sigc::slot<void,P1,P2,P3,P4,P5,P6> VoidSlotType;
SignalProxy6(ObjectBase* obj, const SignalProxyInfo* info)
: SignalProxyNormal(obj, info) {}
/** Connects a signal to a signal handler.
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect(const SlotType& slot, bool after = true)
{ return sigc::connection(connect_(slot, after)); }
/** Connects a signal to a signal handler without a return value.
* By default, the signal handler will be called before the default signal handler,
* in which case any return value would be replaced anyway by that of the later signal handler.
*
* For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
*
* @param slot The signal handler, which should have a void return type, usually created with sigc::mem_fun(), or sigc::ptr_fun().
* @param after Whether this signal handler should be called before or after the default signal handler.
*/
sigc::connection connect_notify(const VoidSlotType& slot, bool after = false)
{ return sigc::connection(connect_notify_(slot, after)); }
};
} // namespace Glib
#endif /* _GLIBMM_SIGNALPROXY_H */

View file

@ -1,94 +0,0 @@
// -*- c++ -*-
/* $Id$ */
/* signalproxy_connectionnode.cc
*
* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <glibmm/signalproxy_connectionnode.h>
#include <glibmm/object.h>
namespace Glib
{
SignalProxyConnectionNode::SignalProxyConnectionNode(const sigc::slot_base& slot, GObject* gobject)
:
connection_id_ (0),
slot_ (slot),
object_ (gobject)
{
//The cleanup callback will be called when the connection is disconnected.
slot_.set_parent(this, &SignalProxyConnectionNode::notify /* cleanup callback */);
}
// notify is a message coming up from the slot to be passed back to Gtk+
// disconnect is a message coming up from the Gtk+ to be passed down to SigC++
//static
void* SignalProxyConnectionNode::notify(void* data)
{
// notification from libsigc++.
SignalProxyConnectionNode* conn = static_cast<SignalProxyConnectionNode*>(data);
// If there is no object, this call was triggered from destroy_notify_handler(),
// because we set conn->object to 0 there:
if(conn && conn->object_)
{
GObject* o = conn->object_;
conn->object_ = 0;
if(g_signal_handler_is_connected(o, conn->connection_id_)) //We check first, because during destruction, GTK+ sometimes seems to disconnect them for us, before we expect it to. See bug #87912
{
// Disconnecting triggers execution of destroy_notify_handler(), eiter immediately or later:
// When the signal handler is currently running. (for instance, if the callback disconnects its own connection)
// In that case, destroy_notify_handler() will be called after this whole function has returned.
// Anyway. destroy_notify_handler() will always be called, so we leave that to do the deletion.
//Forget the connection:
gulong connection_id = conn->connection_id_;
conn->connection_id_ = 0;
g_signal_handler_disconnect(o, connection_id);
}
}
return 0; // apparently unused in libsigc++
}
//static
void SignalProxyConnectionNode::destroy_notify_handler(gpointer data, GClosure*)
{
//glib calls this when it has finished with a glib signal connection,
//either when the emitting object dies, or when the connection has been disconnected.
// notification from gtk+.
SignalProxyConnectionNode* conn = static_cast<SignalProxyConnectionNode*>(data);
if(conn)
{
// the object has already lost track of this object.
conn->object_ = 0;
delete conn; // if there are connection objects referring to slot_ they are notified during destruction of slot_
}
}
} /* namespace Glib */

View file

@ -1,70 +0,0 @@
// -*- c++ -*-
#ifndef _GLIBMM_SIGNALPROXY_CONNECTIONNODE_H
#define _GLIBMM_SIGNALPROXY_CONNECTIONNODE_H
/* $Id$ */
/* signalproxy_connectionnode.h
*
* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <sigc++/sigc++.h>
#include <glibmm/wrap.h>
typedef struct _GObject GObject;
namespace Glib
{
/** SignalProxyConnectionNode is a connection node for use with SignalProxy.
* It lives between the layer of Gtk+ and libsigc++.
* It is very much an internal class.
*/
class SignalProxyConnectionNode
{
public:
/** @param slot The signal handler for the glib signal.
* @param gobject The GObject that might emit this glib signal
*/
SignalProxyConnectionNode(const sigc::slot_base& slot, GObject* gobject);
/** Callback that is executed when the slot becomes invalid.
* This callback is registered in the slot.
* @param data The SignalProxyConnectionNode object (@p this).
*/
static void* notify(void* data);
/** Callback that is executed when the glib closure is destroyed.
* @param data The SignalProxyConnectionNode object (@p this).
* @param closure The glib closure object.
*/
static void destroy_notify_handler(gpointer data, GClosure* closure);
gulong connection_id_;
sigc::slot_base slot_;
protected:
GObject* object_;
};
} /* namespace Glib */
#endif /* _GLIBMM_SIGNALPROXY_CONNECTIONNODE_H */

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