rollback to 3428, before the mysterious removal of libs/* at 3431/3432

git-svn-id: svn://localhost/ardour2/branches/3.0@3435 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2008-06-02 21:41:35 +00:00
parent 9c0d7d72d7
commit 449aab3c46
2869 changed files with 1026749 additions and 0 deletions

View file

@ -0,0 +1,21 @@
## Copyright (c) 2002
## The gtkmm development team.
sublib_name = glibmm
sublib_namespace = Glib
files_defs = glib.defs glib_enums.defs glib_functions.defs gobject.defs gobject_enums.defs gobject_functions.defs gmodule_enums.defs gmodule_functions.defs glib_docs.xml glib_docs_override.xml
include $(top_srcdir)/build_shared/Makefile_gensrc.am_fragment
glibmm_files_m4 = signalproxy.h.m4 value_basictypes.cc.m4 value_basictypes.h.m4
files_stamp += $(glibmm_files_m4:%.m4=$(gensrc_destdir)/%)
EXTRA_DIST += $(glibmm_files_m4) template.macros.m4
$(gensrc_destdir)/%.cc: %.cc.m4 template.macros.m4
$(M4) -I$(srcdir) $< >$@
$(gensrc_destdir)/%.h: %.h.m4 template.macros.m4
$(M4) -I$(srcdir) $< >$@

View file

@ -0,0 +1,416 @@
# Makefile.in generated by automake 1.10 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/Makefile_list_of_hg.am_fragment \
$(top_srcdir)/build_shared/Makefile_gensrc.am_fragment \
$(top_srcdir)/build_shared/Makefile_gensrc_platform.am_fragment \
$(top_srcdir)/tools/Makefile_list_of_sources.am_fragment \
$(top_srcdir)/tools/m4/Makefile_list_of_sources.am_fragment \
$(top_srcdir)/tools/pm/Makefile_list_of_sources.am_fragment
subdir = glib/src
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h \
$(top_builddir)/glib/glibmmconfig.h \
$(top_builddir)/gio/giommconfig.h
CONFIG_CLEAN_FILES =
SOURCES =
DIST_SOURCES =
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DISABLE_DEPRECATED_CFLAGS = @DISABLE_DEPRECATED_CFLAGS@
DLLTOOL = @DLLTOOL@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
GIOMM_CFLAGS = @GIOMM_CFLAGS@
GIOMM_LIBS = @GIOMM_LIBS@
GLIBMM_CFLAGS = @GLIBMM_CFLAGS@
GLIBMM_LIBS = @GLIBMM_LIBS@
GLIBMM_MAJOR_VERSION = @GLIBMM_MAJOR_VERSION@
GLIBMM_MICRO_VERSION = @GLIBMM_MICRO_VERSION@
GLIBMM_MINOR_VERSION = @GLIBMM_MINOR_VERSION@
GLIBMM_RELEASE = @GLIBMM_RELEASE@
GLIBMM_VERSION = @GLIBMM_VERSION@
GMMPROC_DIR = @GMMPROC_DIR@
GREP = @GREP@
GTHREAD_CFLAGS = @GTHREAD_CFLAGS@
GTHREAD_LIBS = @GTHREAD_LIBS@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBGLIBMM_SO_VERSION = @LIBGLIBMM_SO_VERSION@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
sublib_name = glibmm
sublib_namespace = Glib
files_defs = glib.defs glib_enums.defs glib_functions.defs gobject.defs gobject_enums.defs gobject_functions.defs gmodule_enums.defs gmodule_functions.defs glib_docs.xml glib_docs_override.xml
tools_dir_m4 = $(top_srcdir)/tools/m4
tools_dir_pm = $(top_srcdir)/tools/pm
gensrc_destdir = $(srcdir)/../$(sublib_name)
stamp_dir = $(srcdir)/.stamps
files_tools_m4 = base.m4 class_shared.m4 class_boxedtype.m4 class_boxedtype_static.m4 \
class_generic.m4 class_gobject.m4 class_gtkobject.m4 \
class_interface.m4 class_opaque_refcounted.m4 class_opaque_copyable.m4 \
gerror.m4 \
compare.m4 convert.m4 convert_base.m4 convert_gtkmm.m4 convert_atk.m4 convert_gdk.m4 \
convert_glib.m4 convert_gtk.m4 convert_pango.m4 ctor.m4 doc.m4 enum.m4 list.m4 member.m4 \
method.m4 property.m4 signal.m4 vfunc.m4
files_tools_pm = DocsParser.pm GtkDefs.pm Enum.pm Function.pm FunctionBase.pm Object.pm Output.pm Property.pm Util.pm WrapParser.pm
files_tools_genwrap = generate_wrap_init.pl
files_tools_perl = $(files_tools_genwrap) gmmproc.in
tools_m4 = $(files_tools_m4:%.m4=$(tools_dir_m4)/%.m4)
tools_pm = $(files_tools_pm:%.pm=$(tools_dir_pm)/%.pm)
files_posix_hg =
files_win32_hg =
files_general_hg = convert.hg date.hg fileutils.hg iochannel.hg keyfile.hg markup.hg module.hg optioncontext.hg optionentry.hg optiongroup.hg regex.hg shell.hg spawn.hg thread.hg unicode.hg
files_all_hg = $(files_general_hg) $(files_posix_hg) $(files_win32_hg)
@OS_WIN32_FALSE@files_hg = $(files_general_hg) $(files_posix_hg)
@OS_WIN32_TRUE@files_hg = $(files_general_hg) $(files_win32_hg)
files_all_ccg = $(files_all_hg:%.hg=%.ccg)
files_h = $(files_all_hg:%.hg=$(gensrc_destdir)/%.h)
files_cc = $(files_all_hg:%.hg=$(gensrc_destdir)/%.cc)
files_stamp = $(files_all_hg:%.hg=$(stamp_dir)/stamp-%) \
$(glibmm_files_m4:%.m4=$(gensrc_destdir)/%)
gmmproc_in = $(top_srcdir)/tools/gmmproc.in
gmmproc_path = $(top_builddir)/tools/gmmproc
gmmproc_args = -I $(tools_dir_m4) --defs $(srcdir)
run_gmmproc = $(PERL_PATH) -I$(tools_dir_pm) $(gmmproc_path) $(gmmproc_args)
gen_wrap_init_in = $(top_srcdir)/tools/generate_wrap_init.pl.in
gen_wrap_init_path = $(top_builddir)/tools/generate_wrap_init.pl
gen_wrap_init_args = --namespace=$(sublib_namespace)
run_gen_wrap_init = $(PERL_PATH) $(gen_wrap_init_path) $(gen_wrap_init_args)
EXTRA_DIST = Makefile_list_of_hg.am_fragment $(files_defs) \
$(files_all_hg) $(files_all_ccg) $(glibmm_files_m4) \
template.macros.m4
glibmm_files_m4 = signalproxy.h.m4 value_basictypes.cc.m4 value_basictypes.h.m4
all: all-am
.SUFFIXES:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/build_shared/Makefile_gensrc.am_fragment $(top_srcdir)/tools/Makefile_list_of_sources.am_fragment $(top_srcdir)/tools/m4/Makefile_list_of_sources.am_fragment $(top_srcdir)/tools/pm/Makefile_list_of_sources.am_fragment $(srcdir)/Makefile_list_of_hg.am_fragment $(top_srcdir)/build_shared/Makefile_gensrc_platform.am_fragment $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu glib/src/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu glib/src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
tags: TAGS
TAGS:
ctags: CTAGS
CTAGS:
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
@MAINTAINER_MODE_FALSE@all-local:
all-am: Makefile all-local
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-generic
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-exec-am:
install-html: install-html-am
install-info: install-info-am
install-man:
install-pdf: install-pdf-am
install-ps: install-ps-am
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic \
maintainer-clean-local
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am:
.MAKE: install-am install-strip
.PHONY: all all-am all-local check check-am clean clean-generic \
clean-libtool distclean distclean-generic distclean-libtool \
distdir dvi dvi-am html html-am info info-am install \
install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am install-man \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic \
maintainer-clean-local mostlyclean mostlyclean-generic \
mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am
$(stamp_dir)/stamp-%: %.hg %.ccg $(gmmproc_in) $(tools_m4) $(tools_pm) $(files_defs)
$(run_gmmproc) $(notdir $*) $(srcdir) $(gensrc_destdir)
@echo 'timestamp' >$@
$(gensrc_destdir)/wrap_init.cc: $(gen_wrap_init_in) $(files_all_hg)
$(run_gen_wrap_init) $(files_all_hg:%.hg=$(srcdir)/%.hg) >$@
create-stamp-dir:
@(test -d $(stamp_dir) || mkdir $(stamp_dir))
@MAINTAINER_MODE_TRUE@all-local: create-stamp-dir $(files_stamp) $(gensrc_destdir)/wrap_init.cc
maintainer-clean-local:
rm -rf $(stamp_dir)
.PHONY: create-stamp-dir
$(gensrc_destdir)/%.cc: %.cc.m4 template.macros.m4
$(M4) -I$(srcdir) $< >$@
$(gensrc_destdir)/%.h: %.h.m4 template.macros.m4
$(M4) -I$(srcdir) $< >$@
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View file

@ -0,0 +1,8 @@
## This file is include by other Makefile.am files, using the automake
## include feature. The include happens in Makefile.am, not Makefile.in
## or Makefile, so it's like copy-and-pasting this into each of those
## Makefile.am files.
files_posix_hg =
files_win32_hg =
files_general_hg = convert.hg date.hg fileutils.hg iochannel.hg keyfile.hg markup.hg module.hg optioncontext.hg optionentry.hg optiongroup.hg regex.hg shell.hg spawn.hg thread.hg unicode.hg

View file

@ -0,0 +1,395 @@
// -*- c++ -*-
/* $Id: convert.ccg,v 1.4 2006/06/05 17:32:14 murrayc Exp $ */
/* 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.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* gerror = 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, &gerror);
// If this should ever fail we're fucked.
g_assert(gerror != 0);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
}
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);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string IConv::convert(const std::string& str)
#else
std::string IConv::convert(const std::string& str, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
gsize bytes_written = 0;
GError* gerror = 0;
char *const buf = g_convert_with_iconv(
str.data(), str.size(), gobject_, 0, &bytes_written, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
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;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string convert(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset)
#else
std::string convert(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
gsize bytes_written = 0;
GError* gerror = 0;
char *const buf = g_convert(
str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(),
0, &bytes_written, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset)
#else
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
gsize bytes_written = 0;
GError* gerror = 0;
char *const buf = g_convert_with_fallback(
str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(), 0,
0, &bytes_written, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset,
const Glib::ustring& fallback)
#else
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset,
const Glib::ustring& fallback, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
gsize bytes_written = 0;
GError* gerror = 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, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring locale_to_utf8(const std::string& opsys_string)
#else
Glib::ustring locale_to_utf8(const std::string& opsys_string, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
gsize bytes_written = 0;
GError* gerror = 0;
char *const buf = g_locale_to_utf8(
opsys_string.data(), opsys_string.size(), 0, &bytes_written, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
const ScopedPtr<char> scoped_buf (buf);
return Glib::ustring(scoped_buf.get(), scoped_buf.get() + bytes_written);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string locale_from_utf8(const Glib::ustring& utf8_string)
#else
std::string locale_from_utf8(const Glib::ustring& utf8_string, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
gsize bytes_written = 0;
GError* gerror = 0;
char *const buf = g_locale_from_utf8(
utf8_string.data(), utf8_string.bytes(), 0, &bytes_written, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring filename_to_utf8(const std::string& opsys_string)
#else
Glib::ustring filename_to_utf8(const std::string& opsys_string, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
gsize bytes_written = 0;
GError* gerror = 0;
char *const buf = g_filename_to_utf8(
opsys_string.data(), opsys_string.size(), 0, &bytes_written, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
const ScopedPtr<char> scoped_buf (buf);
return Glib::ustring(scoped_buf.get(), scoped_buf.get() + bytes_written);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string filename_from_utf8(const Glib::ustring& utf8_string)
#else
std::string filename_from_utf8(const Glib::ustring& utf8_string, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
gsize bytes_written = 0;
GError* gerror = 0;
char *const buf = g_filename_from_utf8(
utf8_string.data(), utf8_string.bytes(), 0, &bytes_written, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return std::string(ScopedPtr<char>(buf).get(), bytes_written);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname)
#else
std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
char* hostname_buf = 0;
GError* gerror = 0;
char *const buf = g_filename_from_uri(uri.c_str(), &hostname_buf, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
// 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());
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string filename_from_uri(const Glib::ustring& uri)
#else
std::string filename_from_uri(const Glib::ustring& uri, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
char *const buf = g_filename_from_uri(uri.c_str(), 0, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return std::string(ScopedPtr<char>(buf).get());
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname)
#else
Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
char *const buf = g_filename_to_uri(filename.c_str(), hostname.c_str(), &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return Glib::ustring(ScopedPtr<char>(buf).get());
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring filename_to_uri(const std::string& filename)
#else
Glib::ustring filename_to_uri(const std::string& filename, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
char *const buf = g_filename_to_uri(filename.c_str(), 0, &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror) ::Glib::Error::throw_exception(gerror);
#else
if(gerror) error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
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

View file

@ -0,0 +1,324 @@
/* $Id: convert.hg,v 1.5 2006/05/12 08:08:44 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#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.
*/
_WRAP_GERROR(ConvertError, GConvertError, G_CONVERT_ERROR, NO_GTYPE)
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string convert(const std::string& str);
#else
std::string convert(const std::string& str, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string convert(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset);
#else
std::string convert(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset);
#else
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset,
const Glib::ustring& fallback);
#else
std::string convert_with_fallback(const std::string& str,
const std::string& to_codeset,
const std::string& from_codeset,
const Glib::ustring& fallback, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring locale_to_utf8(const std::string& opsys_string);
#else
Glib::ustring locale_to_utf8(const std::string& opsys_string, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string locale_from_utf8(const Glib::ustring& utf8_string);
#else
std::string locale_from_utf8(const Glib::ustring& utf8_string, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring filename_to_utf8(const std::string& opsys_string);
#else
Glib::ustring filename_to_utf8(const std::string& opsys_string, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string filename_from_utf8(const Glib::ustring& utf8_string);
#else
std::string filename_from_utf8(const Glib::ustring& utf8_string, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname);
#else
std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
std::string filename_from_uri(const Glib::ustring& uri);
#else
std::string filename_from_uri(const Glib::ustring& uri, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname);
#else
Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring filename_to_uri(const std::string& filename);
#else
Glib::ustring filename_to_uri(const std::string& filename, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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 std::string& filename);
/** @} group CharsetConv */
} // namespace Glib

View file

@ -0,0 +1,375 @@
// -*- c++ -*-
/* $Id: date.ccg,v 1.7 2006/07/16 13:54:02 jjongsma Exp $ */
/* 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.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());
}
_DEPRECATE_IFDEF_START
//Avoid a build problem in the case that time_t is equivalent to guint32 (GTime is also guint32)
//That would make the set_time() method overload impossible.
#ifdef GLIBMM_HAVE_C_STD_TIME_T_IS_NOT_INT32
void Date::set_time(GTime time)
{
//This method, and the C function that it wraps, are deprecated.
g_date_set_time(&gobject_, time);
}
#endif //GLIBMM_HAVE_C_STD_TIME_T_IS_NOT_INT32
_DEPRECATE_IFDEF_END
void Date::set_time(time_t timet)
{
g_date_set_time_t(&gobject_, timet);
}
void Date::set_time_current()
{
//As suggested in the C documentation:
g_date_set_time_t(&gobject_, time(NULL));
}
void Date::set_time(const GTimeVal& timeval)
{
g_date_set_time_val(&gobject_, const_cast<GTimeVal*>(&timeval));
}
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);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
const std::string locale_format = locale_from_utf8(format);
#else
std::auto_ptr<Glib::Error> error; //TODO: Check it?
const std::string locale_format = locale_from_utf8(format, error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
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);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
return locale_to_utf8(std::string(buf.get(), len));
#else
std::auto_ptr<Glib::Error> error; //TODO: Check it?
return locale_to_utf8(std::string(buf.get(), len), error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
}
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

View file

@ -0,0 +1,408 @@
/* $Id: date.hg,v 1.6 2005/11/29 15:53:27 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#m4 _PUSH(SECTION_HEADER1)
#m4 #undef G_DISABLE_DEPRECATED //So we can use deprecated functions in our deprecated methods.
#m4 _POP()
#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;
_WRAP_ENUM(Month, GDateMonth, s#^DATE_##, NO_GTYPE, get_type_func=)
_WRAP_ENUM(Weekday, GDateWeekday, s#^DATE_##, NO_GTYPE)
_WRAP_ENUM(DMY, GDateDMY, s#^DATE_##, NO_GTYPE)
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);
_DEPRECATE_IFDEF_START
//Avoid a build problem in the case that time_t is equivalent to guint32 (GTime is also guint32)
//That would make the set_time() method overload impossible.
#ifdef GLIBMM_HAVE_C_STD_TIME_T_IS_NOT_INT32
/** Sets the value of a date from a GTime (time_t) value.
*
* @param time GTime value to set.
*
* @deprecated Please use set_time(time_t) or set_time(const GTimeVal&).
*/
void set_time(GTime time);
#endif //GLIBMM_HAVE_C_STD_TIME_T_IS_NOT_INT32
_DEPRECATE_IFDEF_END
/** Sets the value of a date from a <type>time_t</type> value.
*
* @param timet time_t value to set
*
* @see set_time_current()
*
* Since: 2.10
*/
void set_time(time_t timet);
/** Sets the value of a date from a GTimeVal value. Note that the
* tv_usec member is ignored, because Glib::Date can't make use of the
* additional precision.
*
* @see set_time_current()
*
* @param timeval GTimeVal value to set
*
* Since: 2.10
*/
void set_time(const GTimeVal& timeval);
void set_time_current();
/** 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

View file

@ -0,0 +1,185 @@
// -*- c++ -*-
/* $Id: fileutils.ccg,v 1.1 2003/01/07 16:58:25 murrayc Exp $ */
/* 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

View file

@ -0,0 +1,400 @@
/* $Id: fileutils.hg,v 1.3 2004/01/22 18:38:12 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#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
{
_WRAP_ENUM(FileTest, GFileTest, NO_GTYPE)
/** @defgroup FileUtils File Utilities
* Various file-related classes and functions.
*/
/** Exception class for file-related errors.
* @ingroup FileUtils
*/
_WRAP_GERROR(FileError, GFileError, G_FILE_ERROR, NO_GTYPE,
s#^EXIST$#EXISTS#,
s#^ISDIR$#IS_DIRECTORY#,
s#^ACCES$#ACCESS_DENIED#,
s#^NAMETOOLONG$#NAME_TOO_LONG#,
s#^NOENT$#NO_SUCH_ENTITY#,
s#^NOTDIR$#NOT_DIRECTORY#,
s#^NXIO$#NO_SUCH_DEVICE#,
s#^NODEV$#NOT_DEVICE#,
s#^ROFS$#READONLY_FILESYSTEM#,
s#^TXTBSY$#TEXT_FILE_BUSY#,
s#^FAULT$#FAULTY_ADDRESS#,
s#^LOOP$#SYMLINK_LOOP#,
s#^NOSPC$#NO_SPACE_LEFT#,
s#^NOMEM$#NOT_ENOUGH_MEMORY#,
s#^MFILE$#TOO_MANY_OPEN_FILES#,
s#^NFILE$#FILE_TABLE_OVERFLOW#,
s#^BADF$#BAD_FILE_DESCRIPTOR#,
s#^INVAL$#INVALID_ARGUMENT#,
s#^PIPE$#BROKEN_PIPE#,
s#^AGAIN$#TRYAGAIN#,
s#^INTR$#INTERRUPTED#,
s#^IO$#IO_ERROR#,
s#^PERM$#NOT_OWNER#
)
/** @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

View file

@ -0,0 +1,5 @@
(include glib_functions.defs)
(include glib_enums.defs)
(include gobject_functions.defs)
(include gmodule_functions.defs)
(include gmodule_enums.defs)

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,151 @@
<root>
<function name="g_option_context_set_summary">
<description>
Adds a string to be displayed in --help output before the list of options. This
is typically a summary of the program functionality.
Note that the summary is translated (see set_translate_func(),
set_translation_domain()).
Since: 2.14
</description>
<parameters>
<parameter name="summary">
<parameter_description> a string to be shown in --help output before the list of
options
</parameter_description>
</parameter>
</parameters>
<return></return>
</function>
<function name="g_option_context_get_summary">
<description>
Returns: the summary
See set_summary() for more information
</description>
<parameters>
</parameters>
<return> the summary
Since: 2.14
</return>
</function>
<function name="g_option_context_set_description">
<description>
Adds a string to be displayed in --help output after the list of
options. This text often includes a bug reporting address.
Note that the summary is translated (see set_translate_func()).
Since: 2.14
</description>
<parameters>
<parameter name="description">
<parameter_description> a string to be shown in --help output
after the list of options
</parameter_description>
</parameter>
</parameters>
<return></return>
</function>
<function name="g_option_context_get_description">
<description>
Returns: the description
See set_description() for more information
</description>
<parameters>
</parameters>
<return> the description
Since: 2.14
</return>
</function>
<function name="g_option_context_set_translation_domain">
<description>
A convenience function to use gettext() for translating
user-visible strings.
Since: 2.14
</description>
<parameters>
<parameter name="domain">
<parameter_description> the domain to use
</parameter_description>
</parameter>
</parameters>
<return></return>
</function>
<function name="g_key_file_get_double">
<description>
Return value: the value associated with the key as a double, or
</description>
<parameters>
<parameter name="key_file">
<parameter_description> a #GKeyFile
</parameter_description>
</parameter>
<parameter name="group_name">
<parameter_description> a group name
</parameter_description>
</parameter>
<parameter name="key">
<parameter_description> a key
</parameter_description>
</parameter>
<parameter name="error">
<parameter_description> return location for a #GError
</parameter_description>
</parameter>
</parameters>
<return> the value associated with the key as a double, or
0.0 if the key was not found or could not be parsed.
Since: 2.14
</return>
</function>
<function name="g_key_file_set_double">
<description>
Associates a new double value with @key under @group_name.
If @key cannot be found then it is created.
Since: 2.14
</description>
<parameters>
<parameter name="key_file">
<parameter_description> a #GKeyFile
</parameter_description>
</parameter>
<parameter name="group_name">
<parameter_description> a group name
</parameter_description>
</parameter>
<parameter name="key">
<parameter_description> a key
</parameter_description>
</parameter>
<parameter name="value">
<parameter_description> an double value
</parameter_description>
</parameter>
</parameters>
<return></return>
</function>
</root>

View file

@ -0,0 +1,720 @@
;; From /opt/gnome218/include/glib-2.0/glib/gbookmarkfile.h
(define-enum-extended BookmarkFileError
(in-module "G")
(c-name "GBookmarkFileError")
(values
'("invalid-uri" "G_BOOKMARK_FILE_ERROR_INVALID_URI" "0")
'("invalid-value" "G_BOOKMARK_FILE_ERROR_INVALID_VALUE" "1")
'("app-not-registered" "G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED" "2")
'("uri-not-found" "G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND" "3")
'("read" "G_BOOKMARK_FILE_ERROR_READ" "4")
'("unknown-encoding" "G_BOOKMARK_FILE_ERROR_UNKNOWN_ENCODING" "5")
'("write" "G_BOOKMARK_FILE_ERROR_WRITE" "6")
'("file-not-found" "G_BOOKMARK_FILE_ERROR_FILE_NOT_FOUND" "7")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gconvert.h
(define-enum-extended ConvertError
(in-module "G")
(c-name "GConvertError")
(values
'("no-conversion" "G_CONVERT_ERROR_NO_CONVERSION" "0")
'("illegal-sequence" "G_CONVERT_ERROR_ILLEGAL_SEQUENCE" "1")
'("failed" "G_CONVERT_ERROR_FAILED" "2")
'("partial-input" "G_CONVERT_ERROR_PARTIAL_INPUT" "3")
'("bad-uri" "G_CONVERT_ERROR_BAD_URI" "4")
'("not-absolute-path" "G_CONVERT_ERROR_NOT_ABSOLUTE_PATH" "5")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gdate.h
(define-enum-extended DateDMY
(in-module "G")
(c-name "GDateDMY")
(values
'("day" "G_DATE_DAY" "0")
'("month" "G_DATE_MONTH" "1")
'("year" "G_DATE_YEAR" "2")
)
)
(define-enum-extended DateWeekday
(in-module "G")
(c-name "GDateWeekday")
(values
'("bad-weekday" "G_DATE_BAD_WEEKDAY" "0")
'("monday" "G_DATE_MONDAY" "1")
'("tuesday" "G_DATE_TUESDAY" "2")
'("wednesday" "G_DATE_WEDNESDAY" "3")
'("thursday" "G_DATE_THURSDAY" "4")
'("friday" "G_DATE_FRIDAY" "5")
'("saturday" "G_DATE_SATURDAY" "6")
'("sunday" "G_DATE_SUNDAY" "7")
)
)
(define-enum-extended DateMonth
(in-module "G")
(c-name "GDateMonth")
(values
'("bad-month" "G_DATE_BAD_MONTH" "0")
'("january" "G_DATE_JANUARY" "1")
'("february" "G_DATE_FEBRUARY" "2")
'("march" "G_DATE_MARCH" "3")
'("april" "G_DATE_APRIL" "4")
'("may" "G_DATE_MAY" "5")
'("june" "G_DATE_JUNE" "6")
'("july" "G_DATE_JULY" "7")
'("august" "G_DATE_AUGUST" "8")
'("september" "G_DATE_SEPTEMBER" "9")
'("october" "G_DATE_OCTOBER" "10")
'("november" "G_DATE_NOVEMBER" "11")
'("december" "G_DATE_DECEMBER" "12")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gfileutils.h
(define-enum-extended FileError
(in-module "G")
(c-name "GFileError")
(values
'("exist" "G_FILE_ERROR_EXIST" "0")
'("isdir" "G_FILE_ERROR_ISDIR" "1")
'("acces" "G_FILE_ERROR_ACCES" "2")
'("nametoolong" "G_FILE_ERROR_NAMETOOLONG" "3")
'("noent" "G_FILE_ERROR_NOENT" "4")
'("notdir" "G_FILE_ERROR_NOTDIR" "5")
'("nxio" "G_FILE_ERROR_NXIO" "6")
'("nodev" "G_FILE_ERROR_NODEV" "7")
'("rofs" "G_FILE_ERROR_ROFS" "8")
'("txtbsy" "G_FILE_ERROR_TXTBSY" "9")
'("fault" "G_FILE_ERROR_FAULT" "10")
'("loop" "G_FILE_ERROR_LOOP" "11")
'("nospc" "G_FILE_ERROR_NOSPC" "12")
'("nomem" "G_FILE_ERROR_NOMEM" "13")
'("mfile" "G_FILE_ERROR_MFILE" "14")
'("nfile" "G_FILE_ERROR_NFILE" "15")
'("badf" "G_FILE_ERROR_BADF" "16")
'("inval" "G_FILE_ERROR_INVAL" "17")
'("pipe" "G_FILE_ERROR_PIPE" "18")
'("again" "G_FILE_ERROR_AGAIN" "19")
'("intr" "G_FILE_ERROR_INTR" "20")
'("io" "G_FILE_ERROR_IO" "21")
'("perm" "G_FILE_ERROR_PERM" "22")
'("nosys" "G_FILE_ERROR_NOSYS" "23")
'("failed" "G_FILE_ERROR_FAILED" "24")
)
)
(define-flags-extended FileTest
(in-module "G")
(c-name "GFileTest")
(values
'("is-regular" "G_FILE_TEST_IS_REGULAR" "1 << 0")
'("is-symlink" "G_FILE_TEST_IS_SYMLINK" "1 << 1")
'("is-dir" "G_FILE_TEST_IS_DIR" "1 << 2")
'("is-executable" "G_FILE_TEST_IS_EXECUTABLE" "1 << 3")
'("exists" "G_FILE_TEST_EXISTS" "1 << 4")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/ghook.h
(define-flags-extended HookFlagMask
(in-module "G")
(c-name "GHookFlagMask")
(values
'("active" "G_HOOK_FLAG_ACTIVE" "1 << 0")
'("in-call" "G_HOOK_FLAG_IN_CALL" "1 << 1")
'("mask" "G_HOOK_FLAG_MASK" "0x0f")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/giochannel.h
(define-enum-extended IOError
(in-module "G")
(c-name "GIOError")
(values
'("none" "G_IO_ERROR_NONE" "0")
'("again" "G_IO_ERROR_AGAIN" "1")
'("inval" "G_IO_ERROR_INVAL" "2")
'("unknown" "G_IO_ERROR_UNKNOWN" "3")
)
)
(define-enum-extended IOChannelError
(in-module "G")
(c-name "GIOChannelError")
(values
'("fbig" "G_IO_CHANNEL_ERROR_FBIG" "0")
'("inval" "G_IO_CHANNEL_ERROR_INVAL" "1")
'("io" "G_IO_CHANNEL_ERROR_IO" "2")
'("isdir" "G_IO_CHANNEL_ERROR_ISDIR" "3")
'("nospc" "G_IO_CHANNEL_ERROR_NOSPC" "4")
'("nxio" "G_IO_CHANNEL_ERROR_NXIO" "5")
'("overflow" "G_IO_CHANNEL_ERROR_OVERFLOW" "6")
'("pipe" "G_IO_CHANNEL_ERROR_PIPE" "7")
'("failed" "G_IO_CHANNEL_ERROR_FAILED" "8")
)
)
(define-enum-extended IOStatus
(in-module "G")
(c-name "GIOStatus")
(values
'("error" "G_IO_STATUS_ERROR" "0")
'("normal" "G_IO_STATUS_NORMAL" "1")
'("eof" "G_IO_STATUS_EOF" "2")
'("again" "G_IO_STATUS_AGAIN" "3")
)
)
(define-enum-extended SeekType
(in-module "G")
(c-name "GSeekType")
(values
'("cur" "G_SEEK_CUR" "0")
'("set" "G_SEEK_SET" "1")
'("end" "G_SEEK_END" "2")
)
)
(define-enum-extended IOCondition
(in-module "G")
(c-name "GIOCondition")
(values
)
)
(define-flags-extended IOFlags
(in-module "G")
(c-name "GIOFlags")
(values
'("append" "G_IO_FLAG_APPEND" "1 << 0")
'("nonblock" "G_IO_FLAG_NONBLOCK" "1 << 1")
'("is-readable" "G_IO_FLAG_IS_READABLE" "1 << 2")
'("is-writeable" "G_IO_FLAG_IS_WRITEABLE" "1 << 3")
'("is-seekable" "G_IO_FLAG_IS_SEEKABLE" "1 << 4")
'("get-mask" "G_IO_FLAG_GET_MASK" "0x0")
'("set-mask" "G_IO_FLAG_SET_MASK" "0x1")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gkeyfile.h
(define-enum-extended KeyFileError
(in-module "G")
(c-name "GKeyFileError")
(values
'("unknown-encoding" "G_KEY_FILE_ERROR_UNKNOWN_ENCODING" "0")
'("parse" "G_KEY_FILE_ERROR_PARSE" "1")
'("not-found" "G_KEY_FILE_ERROR_NOT_FOUND" "2")
'("key-not-found" "G_KEY_FILE_ERROR_KEY_NOT_FOUND" "3")
'("group-not-found" "G_KEY_FILE_ERROR_GROUP_NOT_FOUND" "4")
'("invalid-value" "G_KEY_FILE_ERROR_INVALID_VALUE" "5")
)
)
(define-flags-extended KeyFileFlags
(in-module "G")
(c-name "GKeyFileFlags")
(values
'("none" "G_KEY_FILE_NONE" "0")
'("keep-comments" "G_KEY_FILE_KEEP_COMMENTS" "1 << 0")
'("keep-translations" "G_KEY_FILE_KEEP_TRANSLATIONS" "1 << 1")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gmarkup.h
(define-enum-extended MarkupError
(in-module "G")
(c-name "GMarkupError")
(values
'("bad-utf8" "G_MARKUP_ERROR_BAD_UTF8" "0")
'("empty" "G_MARKUP_ERROR_EMPTY" "1")
'("parse" "G_MARKUP_ERROR_PARSE" "2")
'("unknown-element" "G_MARKUP_ERROR_UNKNOWN_ELEMENT" "3")
'("unknown-attribute" "G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE" "4")
'("invalid-content" "G_MARKUP_ERROR_INVALID_CONTENT" "5")
)
)
(define-flags-extended MarkupParseFlags
(in-module "G")
(c-name "GMarkupParseFlags")
(values
'("do-not-use-this-unsupported-flag" "G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG" "1 << 0")
'("treat-cdata-as-text" "G_MARKUP_TREAT_CDATA_AS_TEXT" "1 << 1")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gmessages.h
(define-flags-extended LogLevelFlags
(in-module "G")
(c-name "GLogLevelFlags")
(values
'("flag-recursion" "G_LOG_FLAG_RECURSION" "1 << 0")
'("flag-fatal" "G_LOG_FLAG_FATAL" "1 << 1")
'("level-error" "G_LOG_LEVEL_ERROR" "1 << 2")
'("level-critical" "G_LOG_LEVEL_CRITICAL" "1 << 3")
'("level-warning" "G_LOG_LEVEL_WARNING" "1 << 4")
'("level-message" "G_LOG_LEVEL_MESSAGE" "1 << 5")
'("level-info" "G_LOG_LEVEL_INFO" "1 << 6")
'("level-debug" "G_LOG_LEVEL_DEBUG" "1 << 7")
'("level-mask" "G_LOG_LEVEL_MASK" "0xFFFFFFFE")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gnode.h
(define-flags-extended TraverseFlags
(in-module "G")
(c-name "GTraverseFlags")
(values
'("leaves" "G_TRAVERSE_LEAVES" "1 << 0")
'("non-leaves" "G_TRAVERSE_NON_LEAVES" "1 << 1")
'("all" "G_TRAVERSE_ALL" "0x1")
'("mask" "G_TRAVERSE_MASK" "0x03")
'("leafs" "G_TRAVERSE_LEAFS" "0x1")
'("non-leafs" "G_TRAVERSE_NON_LEAFS" "0x2")
)
)
(define-enum-extended TraverseType
(in-module "G")
(c-name "GTraverseType")
(values
'("in-order" "G_IN_ORDER" "0")
'("pre-order" "G_PRE_ORDER" "1")
'("post-order" "G_POST_ORDER" "2")
'("level-order" "G_LEVEL_ORDER" "3")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/goption.h
(define-flags-extended OptionFlags
(in-module "G")
(c-name "GOptionFlags")
(values
'("hidden" "G_OPTION_FLAG_HIDDEN" "1 << 0")
'("in-main" "G_OPTION_FLAG_IN_MAIN" "1 << 1")
'("reverse" "G_OPTION_FLAG_REVERSE" "1 << 2")
'("no-arg" "G_OPTION_FLAG_NO_ARG" "1 << 3")
'("filename" "G_OPTION_FLAG_FILENAME" "1 << 4")
'("optional-arg" "G_OPTION_FLAG_OPTIONAL_ARG" "1 << 5")
'("noalias" "G_OPTION_FLAG_NOALIAS" "1 << 6")
)
)
(define-enum-extended OptionArg
(in-module "G")
(c-name "GOptionArg")
(values
'("none" "G_OPTION_ARG_NONE" "0")
'("string" "G_OPTION_ARG_STRING" "1")
'("int" "G_OPTION_ARG_INT" "2")
'("callback" "G_OPTION_ARG_CALLBACK" "3")
'("filename" "G_OPTION_ARG_FILENAME" "4")
'("string-array" "G_OPTION_ARG_STRING_ARRAY" "5")
'("filename-array" "G_OPTION_ARG_FILENAME_ARRAY" "6")
'("double" "G_OPTION_ARG_DOUBLE" "7")
'("int64" "G_OPTION_ARG_INT64" "8")
)
)
(define-enum-extended OptionError
(in-module "G")
(c-name "GOptionError")
(values
'("unknown-option" "G_OPTION_ERROR_UNKNOWN_OPTION" "0")
'("bad-value" "G_OPTION_ERROR_BAD_VALUE" "1")
'("failed" "G_OPTION_ERROR_FAILED" "2")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gregex.h
(define-enum-extended RegexError
(in-module "G")
(c-name "GRegexError")
(values
'("compile" "G_REGEX_ERROR_COMPILE" "0")
'("optimize" "G_REGEX_ERROR_OPTIMIZE" "1")
'("replace" "G_REGEX_ERROR_REPLACE" "2")
'("match" "G_REGEX_ERROR_MATCH" "3")
)
)
(define-flags-extended RegexCompileFlags
(in-module "G")
(c-name "GRegexCompileFlags")
(values
'("caseless" "G_REGEX_CASELESS" "1 << 0")
'("multiline" "G_REGEX_MULTILINE" "1 << 1")
'("dotall" "G_REGEX_DOTALL" "1 << 2")
'("extended" "G_REGEX_EXTENDED" "1 << 3")
'("anchored" "G_REGEX_ANCHORED" "1 << 4")
'("dollar-endonly" "G_REGEX_DOLLAR_ENDONLY" "1 << 5")
'("ungreedy" "G_REGEX_UNGREEDY" "1 << 9")
'("raw" "G_REGEX_RAW" "1 << 11")
'("no-auto-capture" "G_REGEX_NO_AUTO_CAPTURE" "1 << 12")
'("optimize" "G_REGEX_OPTIMIZE" "1 << 13")
'("dupnames" "G_REGEX_DUPNAMES" "1 << 19")
'("newline-cr" "G_REGEX_NEWLINE_CR" "1 << 20")
'("newline-lf" "G_REGEX_NEWLINE_LF" "1 << 21")
'("newline-crlf" "G_REGEX_NEWLINE_CRLF" "0x100000")
)
)
(define-flags-extended RegexMatchFlags
(in-module "G")
(c-name "GRegexMatchFlags")
(values
'("anchored" "G_REGEX_MATCH_ANCHORED" "1 << 4")
'("notbol" "G_REGEX_MATCH_NOTBOL" "1 << 7")
'("noteol" "G_REGEX_MATCH_NOTEOL" "1 << 8")
'("notempty" "G_REGEX_MATCH_NOTEMPTY" "1 << 10")
'("partial" "G_REGEX_MATCH_PARTIAL" "1 << 15")
'("newline-cr" "G_REGEX_MATCH_NEWLINE_CR" "1 << 20")
'("newline-lf" "G_REGEX_MATCH_NEWLINE_LF" "1 << 21")
'("newline-crlf" "G_REGEX_MATCH_NEWLINE_CRLF" "0x100000")
'("newline-any" "G_REGEX_MATCH_NEWLINE_ANY" "1 << 22")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gscanner.h
(define-enum-extended ErrorType
(in-module "G")
(c-name "GErrorType")
(values
'("unknown" "G_ERR_UNKNOWN" "0")
'("unexp-eof" "G_ERR_UNEXP_EOF" "1")
'("unexp-eof-in-string" "G_ERR_UNEXP_EOF_IN_STRING" "2")
'("unexp-eof-in-comment" "G_ERR_UNEXP_EOF_IN_COMMENT" "3")
'("non-digit-in-const" "G_ERR_NON_DIGIT_IN_CONST" "4")
'("digit-radix" "G_ERR_DIGIT_RADIX" "5")
'("float-radix" "G_ERR_FLOAT_RADIX" "6")
'("float-malformed" "G_ERR_FLOAT_MALFORMED" "7")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gshell.h
(define-enum-extended ShellError
(in-module "G")
(c-name "GShellError")
(values
'("bad-quoting" "G_SHELL_ERROR_BAD_QUOTING" "0")
'("empty-string" "G_SHELL_ERROR_EMPTY_STRING" "1")
'("failed" "G_SHELL_ERROR_FAILED" "2")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gslice.h
(define-enum-extended SliceConfig
(in-module "G")
(c-name "GSliceConfig")
(values
'("always-malloc" "G_SLICE_CONFIG_ALWAYS_MALLOC" "1")
'("bypass-magazines" "G_SLICE_CONFIG_BYPASS_MAGAZINES" "2")
'("working-set-msecs" "G_SLICE_CONFIG_WORKING_SET_MSECS" "3")
'("color-increment" "G_SLICE_CONFIG_COLOR_INCREMENT" "4")
'("chunk-sizes" "G_SLICE_CONFIG_CHUNK_SIZES" "5")
'("contention-counter" "G_SLICE_CONFIG_CONTENTION_COUNTER" "6")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gspawn.h
(define-enum-extended SpawnError
(in-module "G")
(c-name "GSpawnError")
(values
'("fork" "G_SPAWN_ERROR_FORK" "0")
'("read" "G_SPAWN_ERROR_READ" "1")
'("chdir" "G_SPAWN_ERROR_CHDIR" "2")
'("acces" "G_SPAWN_ERROR_ACCES" "3")
'("perm" "G_SPAWN_ERROR_PERM" "4")
'("2big" "G_SPAWN_ERROR_2BIG" "5")
'("noexec" "G_SPAWN_ERROR_NOEXEC" "6")
'("nametoolong" "G_SPAWN_ERROR_NAMETOOLONG" "7")
'("noent" "G_SPAWN_ERROR_NOENT" "8")
'("nomem" "G_SPAWN_ERROR_NOMEM" "9")
'("notdir" "G_SPAWN_ERROR_NOTDIR" "10")
'("loop" "G_SPAWN_ERROR_LOOP" "11")
'("txtbusy" "G_SPAWN_ERROR_TXTBUSY" "12")
'("io" "G_SPAWN_ERROR_IO" "13")
'("nfile" "G_SPAWN_ERROR_NFILE" "14")
'("mfile" "G_SPAWN_ERROR_MFILE" "15")
'("inval" "G_SPAWN_ERROR_INVAL" "16")
'("isdir" "G_SPAWN_ERROR_ISDIR" "17")
'("libbad" "G_SPAWN_ERROR_LIBBAD" "18")
)
)
(define-flags-extended SpawnFlags
(in-module "G")
(c-name "GSpawnFlags")
(values
'("leave-descriptors-open" "G_SPAWN_LEAVE_DESCRIPTORS_OPEN" "1 << 0")
'("do-not-reap-child" "G_SPAWN_DO_NOT_REAP_CHILD" "1 << 1")
'("search-path" "G_SPAWN_SEARCH_PATH" "1 << 2")
'("stdout-to-dev-null" "G_SPAWN_STDOUT_TO_DEV_NULL" "1 << 3")
'("stderr-to-dev-null" "G_SPAWN_STDERR_TO_DEV_NULL" "1 << 4")
'("child-inherits-stdin" "G_SPAWN_CHILD_INHERITS_STDIN" "1 << 5")
'("file-and-argv-zero" "G_SPAWN_FILE_AND_ARGV_ZERO" "1 << 6")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gstrfuncs.h
(define-flags-extended AsciiType
(in-module "G")
(c-name "GAsciiType")
(values
'("alnum" "G_ASCII_ALNUM" "1 << 0")
'("alpha" "G_ASCII_ALPHA" "1 << 1")
'("cntrl" "G_ASCII_CNTRL" "1 << 2")
'("digit" "G_ASCII_DIGIT" "1 << 3")
'("graph" "G_ASCII_GRAPH" "1 << 4")
'("lower" "G_ASCII_LOWER" "1 << 5")
'("print" "G_ASCII_PRINT" "1 << 6")
'("punct" "G_ASCII_PUNCT" "1 << 7")
'("space" "G_ASCII_SPACE" "1 << 8")
'("upper" "G_ASCII_UPPER" "1 << 9")
'("xdigit" "G_ASCII_XDIGIT" "1 << 10")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gthread.h
(define-enum-extended ThreadError
(in-module "G")
(c-name "GThreadError")
(values
'("n" "G_THREAD_ERROR_AGAIN" "0")
)
)
(define-enum-extended ThreadPriority
(in-module "G")
(c-name "GThreadPriority")
(values
'("low" "G_THREAD_PRIORITY_LOW" "0")
'("normal" "G_THREAD_PRIORITY_NORMAL" "1")
'("high" "G_THREAD_PRIORITY_HIGH" "2")
'("urgent" "G_THREAD_PRIORITY_URGENT" "3")
)
)
(define-enum-extended OnceStatus
(in-module "G")
(c-name "GOnceStatus")
(values
'("notcalled" "G_ONCE_STATUS_NOTCALLED" "0")
'("progress" "G_ONCE_STATUS_PROGRESS" "1")
'("ready" "G_ONCE_STATUS_READY" "2")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gunicode.h
(define-enum-extended UnicodeType
(in-module "G")
(c-name "GUnicodeType")
(values
'("control" "G_UNICODE_CONTROL" "0")
'("format" "G_UNICODE_FORMAT" "1")
'("unassigned" "G_UNICODE_UNASSIGNED" "2")
'("private-use" "G_UNICODE_PRIVATE_USE" "3")
'("surrogate" "G_UNICODE_SURROGATE" "4")
'("lowercase-letter" "G_UNICODE_LOWERCASE_LETTER" "5")
'("modifier-letter" "G_UNICODE_MODIFIER_LETTER" "6")
'("other-letter" "G_UNICODE_OTHER_LETTER" "7")
'("titlecase-letter" "G_UNICODE_TITLECASE_LETTER" "8")
'("uppercase-letter" "G_UNICODE_UPPERCASE_LETTER" "9")
'("combining-mark" "G_UNICODE_COMBINING_MARK" "10")
'("enclosing-mark" "G_UNICODE_ENCLOSING_MARK" "11")
'("non-spacing-mark" "G_UNICODE_NON_SPACING_MARK" "12")
'("decimal-number" "G_UNICODE_DECIMAL_NUMBER" "13")
'("letter-number" "G_UNICODE_LETTER_NUMBER" "14")
'("other-number" "G_UNICODE_OTHER_NUMBER" "15")
'("connect-punctuation" "G_UNICODE_CONNECT_PUNCTUATION" "16")
'("dash-punctuation" "G_UNICODE_DASH_PUNCTUATION" "17")
'("close-punctuation" "G_UNICODE_CLOSE_PUNCTUATION" "18")
'("final-punctuation" "G_UNICODE_FINAL_PUNCTUATION" "19")
'("initial-punctuation" "G_UNICODE_INITIAL_PUNCTUATION" "20")
'("other-punctuation" "G_UNICODE_OTHER_PUNCTUATION" "21")
'("open-punctuation" "G_UNICODE_OPEN_PUNCTUATION" "22")
'("currency-symbol" "G_UNICODE_CURRENCY_SYMBOL" "23")
'("modifier-symbol" "G_UNICODE_MODIFIER_SYMBOL" "24")
'("math-symbol" "G_UNICODE_MATH_SYMBOL" "25")
'("other-symbol" "G_UNICODE_OTHER_SYMBOL" "26")
'("line-separator" "G_UNICODE_LINE_SEPARATOR" "27")
'("paragraph-separator" "G_UNICODE_PARAGRAPH_SEPARATOR" "28")
'("space-separator" "G_UNICODE_SPACE_SEPARATOR" "29")
)
)
(define-enum-extended UnicodeBreakType
(in-module "G")
(c-name "GUnicodeBreakType")
(values
'("mandatory" "G_UNICODE_BREAK_MANDATORY" "0")
'("carriage-return" "G_UNICODE_BREAK_CARRIAGE_RETURN" "1")
'("line-feed" "G_UNICODE_BREAK_LINE_FEED" "2")
'("combining-mark" "G_UNICODE_BREAK_COMBINING_MARK" "3")
'("surrogate" "G_UNICODE_BREAK_SURROGATE" "4")
'("zero-width-space" "G_UNICODE_BREAK_ZERO_WIDTH_SPACE" "5")
'("inseparable" "G_UNICODE_BREAK_INSEPARABLE" "6")
'("non-breaking-glue" "G_UNICODE_BREAK_NON_BREAKING_GLUE" "7")
'("contingent" "G_UNICODE_BREAK_CONTINGENT" "8")
'("space" "G_UNICODE_BREAK_SPACE" "9")
'("after" "G_UNICODE_BREAK_AFTER" "10")
'("before" "G_UNICODE_BREAK_BEFORE" "11")
'("before-and-after" "G_UNICODE_BREAK_BEFORE_AND_AFTER" "12")
'("hyphen" "G_UNICODE_BREAK_HYPHEN" "13")
'("non-starter" "G_UNICODE_BREAK_NON_STARTER" "14")
'("open-punctuation" "G_UNICODE_BREAK_OPEN_PUNCTUATION" "15")
'("close-punctuation" "G_UNICODE_BREAK_CLOSE_PUNCTUATION" "16")
'("quotation" "G_UNICODE_BREAK_QUOTATION" "17")
'("exclamation" "G_UNICODE_BREAK_EXCLAMATION" "18")
'("ideographic" "G_UNICODE_BREAK_IDEOGRAPHIC" "19")
'("numeric" "G_UNICODE_BREAK_NUMERIC" "20")
'("infix-separator" "G_UNICODE_BREAK_INFIX_SEPARATOR" "21")
'("symbol" "G_UNICODE_BREAK_SYMBOL" "22")
'("alphabetic" "G_UNICODE_BREAK_ALPHABETIC" "23")
'("prefix" "G_UNICODE_BREAK_PREFIX" "24")
'("postfix" "G_UNICODE_BREAK_POSTFIX" "25")
'("complex-context" "G_UNICODE_BREAK_COMPLEX_CONTEXT" "26")
'("ambiguous" "G_UNICODE_BREAK_AMBIGUOUS" "27")
'("unknown" "G_UNICODE_BREAK_UNKNOWN" "28")
'("next-line" "G_UNICODE_BREAK_NEXT_LINE" "29")
'("word-joiner" "G_UNICODE_BREAK_WORD_JOINER" "30")
'("hangul-l-jamo" "G_UNICODE_BREAK_HANGUL_L_JAMO" "31")
'("hangul-v-jamo" "G_UNICODE_BREAK_HANGUL_V_JAMO" "32")
'("hangul-t-jamo" "G_UNICODE_BREAK_HANGUL_T_JAMO" "33")
'("hangul-lv-syllable" "G_UNICODE_BREAK_HANGUL_LV_SYLLABLE" "34")
'("hangul-lvt-syllable" "G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE" "35")
)
)
(define-enum-extended UnicodeScript
(in-module "G")
(c-name "GUnicodeScript")
(values
'("invalid-code" "G_UNICODE_SCRIPT_INVALID_CODE" "-1")
'("common" "G_UNICODE_SCRIPT_COMMON" "0")
'("inherited" "G_UNICODE_SCRIPT_INHERITED" "1")
'("arabic" "G_UNICODE_SCRIPT_ARABIC" "2")
'("armenian" "G_UNICODE_SCRIPT_ARMENIAN" "3")
'("bengali" "G_UNICODE_SCRIPT_BENGALI" "4")
'("bopomofo" "G_UNICODE_SCRIPT_BOPOMOFO" "5")
'("cherokee" "G_UNICODE_SCRIPT_CHEROKEE" "6")
'("coptic" "G_UNICODE_SCRIPT_COPTIC" "7")
'("cyrillic" "G_UNICODE_SCRIPT_CYRILLIC" "8")
'("deseret" "G_UNICODE_SCRIPT_DESERET" "9")
'("devanagari" "G_UNICODE_SCRIPT_DEVANAGARI" "10")
'("ethiopic" "G_UNICODE_SCRIPT_ETHIOPIC" "11")
'("georgian" "G_UNICODE_SCRIPT_GEORGIAN" "12")
'("gothic" "G_UNICODE_SCRIPT_GOTHIC" "13")
'("greek" "G_UNICODE_SCRIPT_GREEK" "14")
'("gujarati" "G_UNICODE_SCRIPT_GUJARATI" "15")
'("gurmukhi" "G_UNICODE_SCRIPT_GURMUKHI" "16")
'("han" "G_UNICODE_SCRIPT_HAN" "17")
'("hangul" "G_UNICODE_SCRIPT_HANGUL" "18")
'("hebrew" "G_UNICODE_SCRIPT_HEBREW" "19")
'("hiragana" "G_UNICODE_SCRIPT_HIRAGANA" "20")
'("kannada" "G_UNICODE_SCRIPT_KANNADA" "21")
'("katakana" "G_UNICODE_SCRIPT_KATAKANA" "22")
'("khmer" "G_UNICODE_SCRIPT_KHMER" "23")
'("lao" "G_UNICODE_SCRIPT_LAO" "24")
'("latin" "G_UNICODE_SCRIPT_LATIN" "25")
'("malayalam" "G_UNICODE_SCRIPT_MALAYALAM" "26")
'("mongolian" "G_UNICODE_SCRIPT_MONGOLIAN" "27")
'("myanmar" "G_UNICODE_SCRIPT_MYANMAR" "28")
'("ogham" "G_UNICODE_SCRIPT_OGHAM" "29")
'("old-italic" "G_UNICODE_SCRIPT_OLD_ITALIC" "30")
'("oriya" "G_UNICODE_SCRIPT_ORIYA" "31")
'("runic" "G_UNICODE_SCRIPT_RUNIC" "32")
'("sinhala" "G_UNICODE_SCRIPT_SINHALA" "33")
'("syriac" "G_UNICODE_SCRIPT_SYRIAC" "34")
'("tamil" "G_UNICODE_SCRIPT_TAMIL" "35")
'("telugu" "G_UNICODE_SCRIPT_TELUGU" "36")
'("thaana" "G_UNICODE_SCRIPT_THAANA" "37")
'("thai" "G_UNICODE_SCRIPT_THAI" "38")
'("tibetan" "G_UNICODE_SCRIPT_TIBETAN" "39")
'("canadian-aboriginal" "G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL" "40")
'("yi" "G_UNICODE_SCRIPT_YI" "41")
'("tagalog" "G_UNICODE_SCRIPT_TAGALOG" "42")
'("hanunoo" "G_UNICODE_SCRIPT_HANUNOO" "43")
'("buhid" "G_UNICODE_SCRIPT_BUHID" "44")
'("tagbanwa" "G_UNICODE_SCRIPT_TAGBANWA" "45")
'("braille" "G_UNICODE_SCRIPT_BRAILLE" "46")
'("cypriot" "G_UNICODE_SCRIPT_CYPRIOT" "47")
'("limbu" "G_UNICODE_SCRIPT_LIMBU" "48")
'("osmanya" "G_UNICODE_SCRIPT_OSMANYA" "49")
'("shavian" "G_UNICODE_SCRIPT_SHAVIAN" "50")
'("linear-b" "G_UNICODE_SCRIPT_LINEAR_B" "51")
'("tai-le" "G_UNICODE_SCRIPT_TAI_LE" "52")
'("ugaritic" "G_UNICODE_SCRIPT_UGARITIC" "53")
'("new-tai-lue" "G_UNICODE_SCRIPT_NEW_TAI_LUE" "54")
'("buginese" "G_UNICODE_SCRIPT_BUGINESE" "55")
'("glagolitic" "G_UNICODE_SCRIPT_GLAGOLITIC" "56")
'("tifinagh" "G_UNICODE_SCRIPT_TIFINAGH" "57")
'("syloti-nagri" "G_UNICODE_SCRIPT_SYLOTI_NAGRI" "58")
'("old-persian" "G_UNICODE_SCRIPT_OLD_PERSIAN" "59")
'("kharoshthi" "G_UNICODE_SCRIPT_KHAROSHTHI" "60")
'("unknown" "G_UNICODE_SCRIPT_UNKNOWN" "61")
'("balinese" "G_UNICODE_SCRIPT_BALINESE" "62")
'("cuneiform" "G_UNICODE_SCRIPT_CUNEIFORM" "63")
'("phoenician" "G_UNICODE_SCRIPT_PHOENICIAN" "64")
'("phags-pa" "G_UNICODE_SCRIPT_PHAGS_PA" "65")
'("nko" "G_UNICODE_SCRIPT_NKO" "66")
)
)
(define-enum-extended NormalizeMode
(in-module "G")
(c-name "GNormalizeMode")
(values
'("default" "G_NORMALIZE_DEFAULT" "0")
'("nfd" "G_NORMALIZE_NFD" "#error")
'("default-compose" "G_NORMALIZE_DEFAULT_COMPOSE" "1")
'("nfc" "G_NORMALIZE_NFC" "1")
'("all" "G_NORMALIZE_ALL" "2")
'("nfkd" "G_NORMALIZE_NFKD" "2")
'("all-compose" "G_NORMALIZE_ALL_COMPOSE" "3")
'("nfkc" "G_NORMALIZE_NFKC" "3")
)
)
;; From /opt/gnome218/include/glib-2.0/glib/gutils.h
(define-enum-extended UserDirectory
(in-module "G")
(c-name "GUserDirectory")
(values
'("directory-desktop" "G_USER_DIRECTORY_DESKTOP" "0")
'("directory-documents" "G_USER_DIRECTORY_DOCUMENTS" "1")
'("directory-download" "G_USER_DIRECTORY_DOWNLOAD" "2")
'("directory-music" "G_USER_DIRECTORY_MUSIC" "3")
'("directory-pictures" "G_USER_DIRECTORY_PICTURES" "4")
'("directory-public-share" "G_USER_DIRECTORY_PUBLIC_SHARE" "5")
'("directory-templates" "G_USER_DIRECTORY_TEMPLATES" "6")
'("directory-videos" "G_USER_DIRECTORY_VIDEOS" "7")
'("n-directories" "G_USER_N_DIRECTORIES" "8")
)
)

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,12 @@
;; From /home/murrayc/cvs/gnome212/glib/gmodule/gmodule.h
(define-flags-extended ModuleFlags
(in-module "G")
(c-name "GModuleFlags")
(values
'("lazy" "G_MODULE_BIND_LAZY" "1 << 0")
'("local" "G_MODULE_BIND_LOCAL" "1 << 1")
'("mask" "G_MODULE_BIND_MASK" "0x03")
)
)

View file

@ -0,0 +1,79 @@
;; -*- scheme -*-
; object definitions ...
;; Enumerations and flags ...
(define-flags Flags
(in-module "GModule")
(c-name "GModuleFlags")
(gtype-id "G_TYPE_MODULE_FLAGS")
(values
'("lazy" "G_MODULE_BIND_LAZY")
'("local" "G_MODULE_BIND_LOCAL")
'("mask" "G_MODULE_BIND_MASK")
)
)
;; From /home/murrayc/cvs/gnome212/glib/gmodule/gmoduleconf.h
;; From /home/murrayc/cvs/gnome212/glib/gmodule/gmodule.h
(define-function g_module_supported
(c-name "g_module_supported")
(return-type "gboolean")
)
(define-function g_module_open
(c-name "g_module_open")
(return-type "GModule*")
(parameters
'("const-gchar*" "file_name")
'("GModuleFlags" "flags")
)
)
(define-method close
(of-object "GModule")
(c-name "g_module_close")
(return-type "gboolean")
)
(define-method make_resident
(of-object "GModule")
(c-name "g_module_make_resident")
(return-type "none")
)
(define-function g_module_error
(c-name "g_module_error")
(return-type "const-gchar*")
)
(define-method symbol
(of-object "GModule")
(c-name "g_module_symbol")
(return-type "gboolean")
(parameters
'("const-gchar*" "symbol_name")
'("gpointer*" "symbol")
)
)
(define-method name
(of-object "GModule")
(c-name "g_module_name")
(return-type "const-gchar*")
)
(define-function g_module_build_path
(c-name "g_module_build_path")
(return-type "gchar*")
(parameters
'("const-gchar*" "directory")
'("const-gchar*" "module_name")
)
)

View file

@ -0,0 +1,3 @@
(include gobject_functions.defs)
(include gobject_enums.defs)

View file

@ -0,0 +1,80 @@
;; From gobject/gparam.h
(define-flags-extended ParamFlags
(in-module "G")
(c-name "GParamFlags")
(values
'("readable" "G_PARAM_READABLE" "1 << 0")
'("writable" "G_PARAM_WRITABLE" "1 << 1")
'("construct" "G_PARAM_CONSTRUCT" "1 << 2")
'("construct-only" "G_PARAM_CONSTRUCT_ONLY" "1 << 3")
'("lax-validation" "G_PARAM_LAX_VALIDATION" "1 << 4")
'("private" "G_PARAM_PRIVATE" "1 << 5")
)
)
;; From gobject/gsignal.h
(define-flags-extended SignalFlags
(in-module "G")
(c-name "GSignalFlags")
(values
'("run-first" "G_SIGNAL_RUN_FIRST" "1 << 0")
'("run-last" "G_SIGNAL_RUN_LAST" "1 << 1")
'("run-cleanup" "G_SIGNAL_RUN_CLEANUP" "1 << 2")
'("no-recurse" "G_SIGNAL_NO_RECURSE" "1 << 3")
'("detailed" "G_SIGNAL_DETAILED" "1 << 4")
'("action" "G_SIGNAL_ACTION" "1 << 5")
'("no-hooks" "G_SIGNAL_NO_HOOKS" "1 << 6")
)
)
(define-flags-extended ConnectFlags
(in-module "G")
(c-name "GConnectFlags")
(values
'("after" "G_CONNECT_AFTER" "1 << 0")
'("swapped" "G_CONNECT_SWAPPED" "1 << 1")
)
)
(define-flags-extended SignalMatchType
(in-module "G")
(c-name "GSignalMatchType")
(values
'("id" "G_SIGNAL_MATCH_ID" "1 << 0")
'("detail" "G_SIGNAL_MATCH_DETAIL" "1 << 1")
'("closure" "G_SIGNAL_MATCH_CLOSURE" "1 << 2")
'("func" "G_SIGNAL_MATCH_FUNC" "1 << 3")
'("data" "G_SIGNAL_MATCH_DATA" "1 << 4")
'("unblocked" "G_SIGNAL_MATCH_UNBLOCKED" "1 << 5")
)
)
;; From gobject/gtype.h
(define-flags-extended TypeDebugFlags
(in-module "G")
(c-name "GTypeDebugFlags")
(values
'("none" "G_TYPE_DEBUG_NONE" "0")
'("objects" "G_TYPE_DEBUG_OBJECTS" "1 << 0")
'("signals" "G_TYPE_DEBUG_SIGNALS" "1 << 1")
'("mask" "G_TYPE_DEBUG_MASK" "0x03")
)
)
(define-enum-extended TypeFundamentalFlags
(in-module "G")
(c-name "GTypeFundamentalFlags")
(values
)
)
(define-enum-extended TypeFlags
(in-module "G")
(c-name "GTypeFlags")
(values
)
)

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,640 @@
// -*- c++ -*-
/* $Id: iochannel.ccg,v 1.6 2006/10/04 12:04:09 murrayc Exp $ */
/* 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);
}
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::RefPtr<IOChannel> IOChannel::create_from_file(const std::string& filename, const std::string& mode)
#else
Glib::RefPtr<IOChannel> IOChannel::create_from_file(const std::string& filename, const std::string& mode, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
GIOChannel *const channel = g_io_channel_new_file(filename.c_str(), mode.c_str(), &gerror);
if(gerror)
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::Error::throw_exception(gerror);
#else
error = Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
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 */
#ifdef GLIBMM_EXCEPTIONS_ENABLED
IOStatus IOChannel::write(const Glib::ustring& str)
#else
IOStatus IOChannel::write(const Glib::ustring& str, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
gsize bytes_written = 0;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
return write(str.data(), str.bytes(), bytes_written);
#else
return write(str.data(), str.bytes(), bytes_written, error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
IOStatus IOChannel::read_line(Glib::ustring& line)
#else
IOStatus IOChannel::read_line(Glib::ustring& line, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
Glib::ScopedPtr<char> buf;
GError* gerror = 0;
gsize bytes = 0;
const GIOStatus status = g_io_channel_read_line(gobj(), buf.addr(), &bytes, 0, &gerror);
if(gerror)
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::Error::throw_exception(gerror);
#else
error = Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
if(buf.get())
line.assign(buf.get(), buf.get() + bytes);
else
line.erase();
return (IOStatus) status;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
IOStatus IOChannel::read_to_end(Glib::ustring& str)
#else
IOStatus IOChannel::read_to_end(Glib::ustring& str, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
Glib::ScopedPtr<char> buf;
GError* gerror = 0;
gsize bytes = 0;
const GIOStatus status = g_io_channel_read_to_end(gobj(), buf.addr(), &bytes, &gerror);
if(gerror)
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::Error::throw_exception(gerror);
#else
error = Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
if(buf.get())
str.assign(buf.get(), buf.get() + bytes);
else
str.erase();
return (IOStatus) status;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
IOStatus IOChannel::read(Glib::ustring& str, gsize count)
#else
IOStatus IOChannel::read(Glib::ustring& str, gsize count, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
Glib::ScopedPtr<char> buf (g_new(char, count));
GError* gerror = 0;
gsize bytes = 0;
const GIOStatus status = g_io_channel_read_chars(gobj(), buf.get(), count, &bytes, &gerror);
if(gerror)
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::Error::throw_exception(gerror);
#else
error = Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
if(buf.get())
str.assign(buf.get(), buf.get() + bytes);
else
str.erase();
return (IOStatus) status;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
IOStatus IOChannel::set_encoding(const std::string& encoding)
#else
IOStatus IOChannel::set_encoding(const std::string& encoding, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
const GIOStatus status = g_io_channel_set_encoding(
gobj(), (encoding.empty()) ? 0 : encoding.c_str(), &gerror);
if(gerror)
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::Error::throw_exception(gerror);
#else
error = Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
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)
{
if(!&err) err = err; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
return (GIOStatus) wrapper->read_vfunc(buf, count, *bytes_read);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(Glib::Error& error)
{
error.propagate(err);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
return G_IO_STATUS_ERROR;
}
// static
GIOStatus GlibmmIOChannel::io_write(GIOChannel* channel, const char* buf, gsize count,
gsize* bytes_written, GError** err)
{
if(!&err) err = err; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
return (GIOStatus) wrapper->write_vfunc(buf, count, *bytes_written);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(Glib::Error& error)
{
error.propagate(err);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
return G_IO_STATUS_ERROR;
}
// static
GIOStatus GlibmmIOChannel::io_seek(GIOChannel* channel, gint64 offset, GSeekType type, GError** err)
{
if(!&err) err = err; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
return (GIOStatus) wrapper->seek_vfunc(offset, (SeekType) type);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(Glib::Error& error)
{
error.propagate(err);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
return G_IO_STATUS_ERROR;
}
// static
GIOStatus GlibmmIOChannel::io_close(GIOChannel* channel, GError** err)
{
if(!&err) err = err; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
return (GIOStatus) wrapper->close_vfunc();
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(Glib::Error& error)
{
error.propagate(err);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
return G_IO_STATUS_ERROR;
}
// static
GSource* GlibmmIOChannel::io_create_watch(GIOChannel* channel, GIOCondition condition)
{
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
const Glib::RefPtr<Source> source = wrapper->create_watch_vfunc((IOCondition) condition);
return (source) ? source->gobj_copy() : 0;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
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)
{
if(!&err) err = err; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
return (GIOStatus) wrapper->set_flags_vfunc((IOFlags) flags);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(Glib::Error& error)
{
error.propagate(err);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
return G_IO_STATUS_ERROR;
}
// static
GIOFlags GlibmmIOChannel::io_get_flags(GIOChannel* channel)
{
IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
return (GIOFlags) wrapper->get_flags_vfunc();
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
return GIOFlags(0);
}
} // namespace Glib

View file

@ -0,0 +1,476 @@
// -*- c++ -*-
/* $Id: iochannel.hg,v 1.8 2006/05/12 08:08:44 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#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;
_WRAP_ENUM(SeekType, GSeekType, NO_GTYPE, s#^SEEK_#SEEK_TYPE_#)
_WRAP_ENUM(IOStatus, GIOStatus, NO_GTYPE)
_WRAP_ENUM(IOFlags, GIOFlags, NO_GTYPE)
/** Exception class for IOChannel errors.
*/
_WRAP_GERROR(IOChannelError, GIOChannelError, G_IO_CHANNEL_ERROR, NO_GTYPE,
s#^INVAL$#INVALID_ARGUMENT#,
s#^ISDIR$#IS_DIRECTORY#,
s#^PIPE$#BROKEN_PIPE#,
s#^NOSPC$#NO_SPACE_LEFT#,
s#^NXIO$#NO_SUCH_DEVICE#,
s#^ACCES$#ACCESS_DENIED#,
s#^FBIG$#FILE_TOO_BIG#,
s#^IO$#IO_ERROR#,
s#^OVERFLOW$#OVERFLOWN#)
#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
{
_CLASS_GENERIC(IOChannel, GIOChannel)
dnl // We can't support get_fd() properly because it is impossible
dnl // to detect the specific GIOChannel type at runtime.
_IGNORE(g_io_channel_unix_get_fd, g_io_channel_win32_get_fd)
dnl // deprecated or internal
_IGNORE(g_io_channel_seek, g_io_channel_close, g_io_channel_read,
g_io_channel_write, g_io_channel_win32_make_pollfd)
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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
static Glib::RefPtr<IOChannel> create_from_file(const std::string& filename, const std::string& mode);
#else
static Glib::RefPtr<IOChannel> create_from_file(const std::string& filename, const std::string& mode, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
_IGNORE(g_io_channel_new_file)
/** 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);
_IGNORE(g_io_channel_unix_new)
/* 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);
_IGNORE(g_io_channel_win32_new_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);
_IGNORE(g_io_channel_win32_new_socket)
#endif /* defined(G_OS_WIN32) || defined(DOXYGEN_SHOULD_SKIP_THIS) */
/** Read a single UCS-4 character.
* @retval thechar The Unicode character.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
_WRAP_METHOD(IOStatus read(gunichar& thechar), g_io_channel_read_unichar, errthrow)
/** 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
*/
_WRAP_METHOD(IOStatus read(char* buf, gsize count, gsize& bytes_read),
g_io_channel_read_chars, errthrow)
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
IOStatus read(Glib::ustring& str, gsize count);
#else
IOStatus read(Glib::ustring& str, gsize count, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
IOStatus read_line(Glib::ustring& line);
#else
IOStatus read_line(Glib::ustring& line, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
_IGNORE(g_io_channel_read_line, g_io_channel_read_line_string)
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
IOStatus read_to_end(Glib::ustring& str);
#else
IOStatus read_to_end(Glib::ustring& str, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
_IGNORE(g_io_channel_read_to_end)
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
IOStatus write(const Glib::ustring& str);
#else
IOStatus write(const Glib::ustring& str, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** 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
*/
_WRAP_METHOD(IOStatus write(const char* buf, gssize count, gsize& bytes_written),
g_io_channel_write_chars, errthrow)
/** 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
*/
_WRAP_METHOD(IOStatus write(gunichar unichar), g_io_channel_write_unichar, errthrow)
/** 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
*/
_WRAP_METHOD(IOStatus seek(gint64 offset, SeekType type = SEEK_TYPE_SET),
g_io_channel_seek_position, errthrow)
/** Flush the buffers of the I/O channel.
* @return The status of the operation.
* @throw Glib::IOChannelError
* @throw Glib::ConvertError
*/
_WRAP_METHOD(IOStatus flush(), g_io_channel_flush, errthrow)
/** 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
*/
_WRAP_METHOD(IOStatus close(bool flush = true), g_io_channel_shutdown, errthrow)
/** Get the IOChannel internal buffer size.
* @return The buffer size.
*/
_WRAP_METHOD(gsize get_buffer_size() const, g_io_channel_get_buffer_size)
/** Set the internal IOChannel buffer size.
* @param size The buffer size the IOChannel should use.
*/
_WRAP_METHOD(void set_buffer_size(gsize size), g_io_channel_set_buffer_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.
*/
_WRAP_METHOD(IOFlags get_flags() const, g_io_channel_get_flags)
/** Set flags on the IOChannel.
* @param flags Bitwise combination of the flags to set.
* @return The operation result code.
* @throw Glib::IOChannelError
*/
_WRAP_METHOD(IOStatus set_flags(IOFlags flags), g_io_channel_set_flags, errthrow)
/** 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.
*/
_WRAP_METHOD(void set_buffered(bool buffered), g_io_channel_set_buffered)
/** Get the buffering status of the I/O channel.
* @return The buffering status of the channel.
*/
_WRAP_METHOD(bool get_buffered() const, g_io_channel_get_buffered)
/** 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.
*/
_WRAP_METHOD(IOCondition get_buffer_condition() const, g_io_channel_get_buffer_condition)
/** 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.
*/
_WRAP_METHOD(bool get_close_on_unref() const, g_io_channel_get_close_on_unref)
/** 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.
*/
_WRAP_METHOD(void set_close_on_unref(bool do_close), g_io_channel_set_close_on_unref)
/** 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
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
IOStatus set_encoding(const std::string& encoding = std::string());
#else
IOStatus set_encoding(const std::string& encoding, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
_IGNORE(g_io_channel_set_encoding)
/** Get the encoding of the I/O channel.
* @return The current encoding of the channel.
*/
std::string get_encoding() const;
_IGNORE(g_io_channel_get_encoding)
void set_line_term(const std::string& term = std::string());
_IGNORE(g_io_channel_set_line_term)
std::string get_line_term() const;
_IGNORE(g_io_channel_get_line_term)
/** 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);
_IGNORE(g_io_channel_create_watch)
virtual void reference() const;
virtual void unreference() const;
_IGNORE(g_io_channel_ref, g_io_channel_unref)
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();
_IGNORE(g_io_channel_init)
#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

View file

@ -0,0 +1,255 @@
/* Copyright 2006 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
{
/**** Glib::KeyFile ********************************************************/
KeyFile::KeyFile()
{
gobject_ = g_key_file_new();
owns_gobject_ = true;
}
KeyFile::KeyFile(GKeyFile* castitem, bool takes_ownership)
{
gobject_ = castitem;
owns_gobject_ = takes_ownership;
}
KeyFile::~KeyFile()
{
if (owns_gobject_)
g_key_file_free(gobject_);
}
bool KeyFile::load_from_data(const Glib::ustring& data, KeyFileFlags flags)
{
GError *error = 0;
bool retvalue = g_key_file_load_from_data(gobj(), data.c_str(), data.bytes(), ((GKeyFileFlags)(flags)), &(error));
if(error) :: Glib::Error::throw_exception(error);
return retvalue;
}
bool KeyFile::load_from_data_dirs(const std::string& file, std::string& full_path, KeyFileFlags flags)
{
GError *error = 0;
char *full_path_c;
bool retvalue = g_key_file_load_from_data_dirs(gobj(), file.c_str(), &full_path_c, ((GKeyFileFlags)(flags)), &(error));
full_path = Glib::convert_return_gchar_ptr_to_ustring(full_path_c);
if(error) :: Glib::Error::throw_exception(error);
return retvalue;
}
Glib::ustring KeyFile::to_data()
{
GError *error = 0;
gsize size;
Glib::ustring retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_key_file_to_data(gobj(), &size, &error));
if(error) :: Glib::Error::throw_exception(error);
return retvalue;
}
Glib::ArrayHandle<Glib::ustring> KeyFile::get_groups() const
{
gchar** group_names = 0;
gsize number_of_groups = 0;
group_names = g_key_file_get_groups(const_cast<GKeyFile*>(gobj()), &number_of_groups);
return Glib::ArrayHandle<Glib::ustring>(group_names, number_of_groups, Glib::OWNERSHIP_DEEP);
}
Glib::ArrayHandle<Glib::ustring> KeyFile::get_keys(const Glib::ustring& group_name) const
{
gchar** key_names = 0;
gsize number_of_keys = 0;
GError* error = 0;
key_names = g_key_file_get_keys(const_cast<GKeyFile*>(gobj()), group_name.c_str(), &number_of_keys, &error);
if(error)
Glib::Error::throw_exception(error);
return Glib::ArrayHandle<Glib::ustring>(key_names, number_of_keys, Glib::OWNERSHIP_DEEP);
}
Glib::ustring KeyFile::get_locale_string(const Glib::ustring& group_name, const Glib::ustring& key) const
{
GError *error = 0;
Glib::ustring retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_key_file_get_locale_string(const_cast<GKeyFile*>(gobj()), group_name.c_str(), key.c_str(), 0, &(error)));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
int KeyFile::get_integer(const Glib::ustring& key) const
#else
int KeyFile::get_integer(const Glib::ustring& key, std::auto_ptr<Glib::Error>& error) const
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
int retvalue = g_key_file_get_integer(const_cast<GKeyFile*>(gobj()), NULL, key.c_str(), &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
#else
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return retvalue;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
double KeyFile::get_double(const Glib::ustring& key) const
#else
double KeyFile::get_double(const Glib::ustring& key, std::auto_ptr<Glib::Error>& error) const
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
double retvalue = g_key_file_get_double(const_cast<GKeyFile*>(gobj()), NULL, key.c_str(), &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
#else
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return retvalue;
}
void KeyFile::set_double(const Glib::ustring& key, double value)
{
g_key_file_set_double(gobj(), 0, key.c_str(), value);
}
Glib::ArrayHandle<Glib::ustring> KeyFile::get_string_list(const Glib::ustring& group_name, const Glib::ustring& key) const
{
gchar** string_list = 0;
gsize length_of_list = 0;
GError* error = 0;
string_list = g_key_file_get_string_list(const_cast<GKeyFile*>(gobj()), group_name.c_str(), key.c_str(), &length_of_list, &error);
if(error)
Glib::Error::throw_exception(error);
return Glib::ArrayHandle<Glib::ustring>(string_list, length_of_list, Glib::OWNERSHIP_DEEP);
}
Glib::ArrayHandle<Glib::ustring> KeyFile::get_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale) const
{
gchar** string_list = 0;
gsize length_of_list = 0;
GError* error = 0;
string_list = g_key_file_get_locale_string_list(const_cast<GKeyFile*>(gobj()), group_name.c_str(), key.c_str(), locale.c_str(), &length_of_list, &error);
if(error)
Glib::Error::throw_exception(error);
return Glib::ArrayHandle<Glib::ustring>(string_list, length_of_list, Glib::OWNERSHIP_DEEP);
}
Glib::ArrayHandle<bool> KeyFile::get_boolean_list(const Glib::ustring& group_name, const Glib::ustring& key) const
{
gboolean* bool_list = 0;
gsize length_of_list = 0;
GError* error = 0;
bool_list = g_key_file_get_boolean_list(const_cast<GKeyFile*>(gobj()), group_name.c_str(), key.c_str(), &length_of_list, &error);
if(error)
Glib::Error::throw_exception(error);
return Glib::ArrayHandle<bool>(&bool_list, length_of_list, Glib::OWNERSHIP_DEEP);
}
Glib::ArrayHandle<int> KeyFile::get_integer_list(const Glib::ustring& group_name, const Glib::ustring& key) const
{
gint* integer_list = 0;
gsize length_of_list = 0;
GError* error = 0;
integer_list = g_key_file_get_integer_list(const_cast<GKeyFile*>(gobj()), group_name.c_str(), key.c_str(), &length_of_list, &error);
if(error)
Glib::Error::throw_exception(error);
return Glib::ArrayHandle<int>(integer_list, length_of_list, Glib::OWNERSHIP_DEEP);
}
Glib::ArrayHandle<double> KeyFile::get_double_list(const Glib::ustring& group_name, const Glib::ustring& key) const
{
gdouble* integer_list = 0;
gsize length_of_list = 0;
GError* error = 0;
integer_list = g_key_file_get_double_list(const_cast<GKeyFile*>(gobj()), group_name.c_str(), key.c_str(), &length_of_list, &error);
if(error)
Glib::Error::throw_exception(error);
return Glib::ArrayHandle<double>(integer_list, length_of_list, Glib::OWNERSHIP_DEEP);
}
void KeyFile::set_string_list(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ArrayHandle<Glib::ustring>& list)
{
gsize length_of_list = list.size();
g_key_file_set_string_list(gobj(), group_name.c_str(), key.c_str(), list.data(), length_of_list);
}
void KeyFile::set_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale, const Glib::ArrayHandle<Glib::ustring>& list)
{
gsize length_of_list = list.size();
g_key_file_set_locale_string_list(gobj(), group_name.c_str(), key.c_str(), locale.c_str(), list.data(), length_of_list);
}
void KeyFile::set_integer_list(const Glib::ustring& group_name, const Glib::ustring& key, Glib::ArrayHandle<int>& list)
{
gsize length_of_list = list.size();
g_key_file_set_integer_list(gobj(), group_name.c_str(), key.c_str(), const_cast<int*>(list.data()), length_of_list);
}
void KeyFile::set_double_list(const Glib::ustring& group_name, const Glib::ustring& key, Glib::ArrayHandle<double>& list)
{
gsize length_of_list = list.size();
g_key_file_set_double_list(gobj(), group_name.c_str(), key.c_str(), const_cast<double*>(list.data()), length_of_list);
}
void KeyFile::set_boolean_list(const Glib::ustring& group_name, const Glib::ustring& key, Glib::ArrayHandle<bool>& list)
{
gsize length_of_list = list.size();
g_key_file_set_boolean_list(gobj(), group_name.c_str(), key.c_str(), *(list.data()), length_of_list);
}
Glib::ustring KeyFile::get_comment() const
{
GError *error = 0;
Glib::ustring retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_key_file_get_comment(const_cast<GKeyFile*>(gobj()), 0, 0, &(error)));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
Glib::ustring KeyFile::get_comment(const Glib::ustring& group_name) const
{
GError *error = 0;
Glib::ustring retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_key_file_get_comment(const_cast<GKeyFile*>(gobj()), group_name.c_str(), 0, &(error)));
if(error) ::Glib::Error::throw_exception(error);
return retvalue;
}
void KeyFile::set_comment(const Glib::ustring& comment)
{
GError *error = 0;
g_key_file_set_comment(gobj(), 0, 0, comment.c_str(), &(error));
if(error) ::Glib::Error::throw_exception(error);
}
void KeyFile::set_comment(const Glib::ustring& group_name, const Glib::ustring& comment)
{
GError *error = 0;
g_key_file_set_comment(gobj(), group_name.c_str(), 0, comment.c_str(), &(error));
if(error) ::Glib::Error::throw_exception(error);
}
}

View file

@ -0,0 +1,387 @@
/* Copyright(C) 2006 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.
*/
_DEFS(glibmm,glib)
#include <glibmm/ustring.h>
#include <glibmm/arrayhandle.h>
#include <glibmm/error.h>
#include <glibmm/utility.h>
#include <glib/gkeyfile.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GKeyFile GKeyFile; }
#endif
namespace Glib
{
_WRAP_ENUM(KeyFileFlags, GKeyFileFlags, NO_GTYPE)
/** Exception class for KeyFile errors.
*/
_WRAP_GERROR(KeyFileError, GKeyFileError, G_KEY_FILE_ERROR, NO_GTYPE)
/** This class lets you parse, edit or create files containing groups of key-value pairs, which we call key files
* for lack of a better name. Several freedesktop.org specifications use key files now, e.g the Desktop Entry
* Specification and the Icon Theme Specification.
*
* The syntax of key files is described in detail in the Desktop Entry Specification, here is a quick summary: Key
* files consists of groups of key-value pairs, interspersed with comments.
*
* @code
* # this is just an example
* # there can be comments before the first group
*
* [First Group]
*
* Name=Key File Example\tthis value shows\nescaping
*
* # localized strings are stored in multiple key-value pairs
* Welcome=Hello
* Welcome[de]=Hallo
* Welcome[fr]=Bonjour
* Welcome[it]=Ciao
*
* [Another Group]
*
* Numbers=2;20;-200;0
*
* Booleans=true;false;true;true
* @endcode
*
* Lines beginning with a '#' and blank lines are considered comments.
*
* Groups are started by a header line containing the group name enclosed in '[' and ']', and ended implicitly by
* the start of the next group or the end of the file. Each key-value pair must be contained in a group.
*
* Key-value pairs generally have the form key=value, with the exception of localized strings, which have the form
* key[locale]=value. Space before and after the '=' character are ignored. Newline, tab, carriage return and
* backslash characters in value are escaped as \n, \t, \r, and \\, respectively. To preserve leading spaces in
* values, these can also be escaped as \s.
*
* Key files can store strings (possibly with localized variants), integers, booleans and lists of these. Lists are
* separated by a separator character, typically ';' or ','. To use the list separator character in a value in a
* list, it has to be escaped by prefixing it with a backslash.
*
* This syntax is obviously inspired by the .ini files commonly met on Windows, but there are some important
* differences:
* - .ini files use the ';' character to begin comments, key files use the '#' character.
* - Key files allow only comments before the first group.
* - Key files are always encoded in UTF-8.
* - Key and Group names are case-sensitive, for example a group called [GROUP] is a different group from [group].
*
* Note that in contrast to the Desktop Entry Specification, groups in key files may contain the same key multiple
* times; the last entry wins. Key files may also contain multiple groups with the same name; they are merged
* together. Another difference is that keys and group names in key files are not restricted to ASCII characters.
*
* @newin2p14
*/
class KeyFile
{
_CLASS_GENERIC(KeyFile, GKeyFile)
public:
/** Creates a new, empty KeyFile object.
*/
KeyFile();
/** Destructor
*/
~KeyFile();
_IGNORE(g_key_file_free)
/** Creates a glibmm KeyFile wrapper for a GKeyFile object.
* Note, when using this that when the wrapper is deleted,
* it will not automatically deleted the GKeyFile unless you
* set the delete_c_instance boolean to true.
* @param castitem The C instance to wrap
* @param delete_c_instance If the C instance should be deleted when
* the wrapper is deleted.
*/
KeyFile(GKeyFile* castitem, bool takes_ownership = false);
public:
_WRAP_METHOD(bool load_from_file(const std::string& filename, KeyFileFlags flags = Glib::KEY_FILE_NONE), g_key_file_load_from_file, errthrow)
/** Loads a KeyFile from memory
* @param data The data to use as a KeyFile
* @param flags Bitwise combination of the flags to use for the KeyFile
* @return true if the KeyFile was successfully loaded, false otherwise
* @throw Glib::KeyFileError
*/
bool load_from_data(const Glib::ustring& data, KeyFileFlags flags = Glib::KEY_FILE_NONE);
_IGNORE(g_key_file_load_from_data)
//TODO:
/*
gboolean g_key_file_load_from_dirs (GKeyFile *key_file,
const gchar *file,
const gchar **search_dirs,
gchar **full_path,
GKeyFileFlags flags,
GError **error);
*/
/** Looks for a KeyFile named @a file in the paths returned from
* g_get_user_data_dir() and g_get_system_data_dirs() and loads them
* into the keyfile object, placing the full path to the file in
* @a full_path.
* @param file The file to search for
* @param full_path Return location for a string containing the full path of the file
* @param flags Bitwise combination of the flags to use for the KeyFile
* @return true if the KeyFile was successfully loaded, false otherwise
* @throw Glib::KeyFileError
* @throw Glib::FileError
*/
bool load_from_data_dirs(const std::string& file, std::string& full_path, KeyFileFlags flags = Glib::KEY_FILE_NONE);
_IGNORE(g_key_file_load_from_data_dirs)
/** Outputs the KeyFile as a string
* @return A string object holding the contents of KeyFile
*/
Glib::ustring to_data();
_IGNORE(g_key_file_to_data)
_WRAP_METHOD(Glib::ustring get_start_group() const, g_key_file_get_start_group)
/** Gets a list of all groups in the KeyFile
* @returns A list containing the names of the groups
*/
Glib::ArrayHandle<Glib::ustring> get_groups() const;
_IGNORE(g_key_file_get_groups)
/** Gets a list of all keys from the group @a group_name.
* @param group_name The name of a group
* @returns A list containing the names of the keys in @a group_name
*/
Glib::ArrayHandle<Glib::ustring> get_keys(const Glib::ustring& group_name) const;
_IGNORE(g_key_file_get_keys)
_WRAP_METHOD(bool has_group(const Glib::ustring& group_name) const, g_key_file_has_group)
_WRAP_METHOD(bool has_key(const Glib::ustring& group_name, const Glib::ustring& key) const, g_key_file_has_key, errthrow)
_WRAP_METHOD(Glib::ustring get_value(const Glib::ustring& group_name, const Glib::ustring& key) const, g_key_file_get_value, errthrow)
_WRAP_METHOD(Glib::ustring get_string(const Glib::ustring& group_name, const Glib::ustring& key) const, g_key_file_get_string, errthrow)
/** Gets the value associated with @a key under @a group_name translated
* into the current locale.
*/
Glib::ustring get_locale_string(const Glib::ustring& group_name, const Glib::ustring& key) const;
_WRAP_METHOD(Glib::ustring get_locale_string(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale) const, g_key_file_get_locale_string, errthrow)
_WRAP_METHOD(bool get_boolean(const Glib::ustring& group_name, const Glib::ustring& key) const, g_key_file_get_boolean, errthrow)
/** Gets the value in the first group, under @a key, interpreting it as
* an integer.
* @param key The name of the key
* @return The value of @a key as an integer
* @throws Glib::KeyFileError
*/
int get_integer(const Glib::ustring& key) const;
_WRAP_METHOD(int get_integer(const Glib::ustring& group_name, const Glib::ustring& key) const, g_key_file_get_integer, errthrow)
/** Gets the value in the first group, under @a key, interpreting it as
* a double.
* @param key The name of the key
* @return The value of @a key as an double
* @throws Glib::KeyFileError
*
* @newin2p14
*/
double get_double(const Glib::ustring& key) const;
_WRAP_METHOD(double get_double(const Glib::ustring& group_name, const Glib::ustring& key) const, g_key_file_get_double, errthrow)
_WRAP_METHOD(void set_double(const Glib::ustring& group_name, const Glib::ustring& key, double value), g_key_file_set_double)
/** Associates a new double value with @a key under the start group.
* If @a key cannot be found then it is created.
*
* @newin2p12
* @param key A key.
* @param value An double value.
*/
void set_double(const Glib::ustring& key, double value);
/** Returns the values associated with @a key under @a group_name
* @param group_name The name of a group
* @param key The name of a key
* @return A list containing the values requested
* @throws Glib::KeyFileError
*/
Glib::ArrayHandle<Glib::ustring> get_string_list(const Glib::ustring& group_name, const Glib::ustring& key) const;
_IGNORE(g_key_file_get_string_list)
/** Returns the values associated with @a key under @a group_name
* translated into the current locale, if available.
* @param group_name The name of a group
* @param key The name of a key
* @return A list containing the values requested
* @throws Glib::KeyFileError
*/
Glib::ArrayHandle<Glib::ustring> get_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key) const;
/** Returns the values associated with @a key under @a group_name
* translated into @a locale, if available.
* @param group_name The name of a group
* @param key The name of a key
* @param locale The name of a locale
* @return A list containing the values requested
* @throws Glib::KeyFileError
*/
Glib::ArrayHandle<Glib::ustring> get_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale) const;
_IGNORE(g_key_file_get_locale_string_list)
/** Returns the values associated with @a key under @a group_name
* @param group_name The name of a group
* @param key The name of a key
* @return A list of booleans
* @throws Glib::KeyFileError
*/
Glib::ArrayHandle<bool> get_boolean_list(const Glib::ustring& group_name, const Glib::ustring& key) const;
_IGNORE(g_key_file_get_boolean_list)
/** Returns the values associated with @a key under @a group_name
* @param group_name The name of a group
* @param key The name of a key
* @return A list of integers
* @throws Glib::KeyFileError
*/
Glib::ArrayHandle<int> get_integer_list(const Glib::ustring& group_name, const Glib::ustring& key) const;
_IGNORE(g_key_file_get_integer_list)
/** Returns the values associated with @a key under @a group_name
* @param group_name The name of a group
* @param key The name of a key
* @return A list of doubles
* @throws Glib::KeyFileError
*/
Glib::ArrayHandle<double> get_double_list(const Glib::ustring& group_name, const Glib::ustring& key) const;
_IGNORE(g_key_file_get_double_list)
/** Get comment from top of file
* @return The comment
*/
Glib::ustring get_comment() const;
/** Get comment from above a group
* @param group_name The group
* @return The comment
*/
Glib::ustring get_comment(const Glib::ustring& group_name) const;
_WRAP_METHOD(Glib::ustring get_comment(const Glib::ustring& group_name, const Glib::ustring& key) const, g_key_file_get_comment, errthrow)
_WRAP_METHOD(void set_list_separator(gchar separator), g_key_file_set_list_separator)
_WRAP_METHOD(void set_value(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& value), g_key_file_set_value)
_WRAP_METHOD(void set_string(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& string), g_key_file_set_string)
_WRAP_METHOD(void set_locale_string(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale, const Glib::ustring& string), g_key_file_set_locale_string)
_WRAP_METHOD(void set_boolean(const Glib::ustring& group_name, const Glib::ustring& key, bool value), g_key_file_set_boolean)
_WRAP_METHOD(void set_integer(const Glib::ustring& group_name, const Glib::ustring& key, int value), g_key_file_set_integer)
/** Sets a list of string values for @a key under @a group_name. If
* key cannot be found it is created. If @a group_name cannot be found
* it is created.
* @param group_name The name of a group
* @param key The name of a key
* @param list A list holding objects of type Glib::ustring
*/
void set_string_list(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ArrayHandle<Glib::ustring>& list);
_IGNORE(g_key_file_set_string_list)
/** Sets a list of string values for the @a key under @a group_name and marks
* them as being for @a locale. If the @a key or @a group_name cannot be
* found, they are created.
* @param group_name The name of a group
* @param key The name of a key
* @param locale A locale
* @param list A list holding objects of type Glib::ustring
*/
void set_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale, const Glib::ArrayHandle<Glib::ustring>& list);
_IGNORE(g_key_file_set_locale_string_list)
/** Sets a list of booleans for the @a key under @a group_name.
* If either the @a key or @a group_name cannot be found they are created.
* @param group_name The name of a group
* @param key The name of a key
* @param list A list holding object of type bool
*/
void set_boolean_list(const Glib::ustring& group_name, const Glib::ustring& key, Glib::ArrayHandle<bool>& list);
_IGNORE(g_key_file_set_boolean_list)
/** Sets a list of integers for the @a key under @a group_name.
* If either the @a key or @a group_name cannot be found they are created.
* @param group_name The name of a group
* @param key The name of a key
* @param list A list holding object of type int
*/
void set_integer_list(const Glib::ustring& group_name, const Glib::ustring& key, Glib::ArrayHandle<int>& list);
_IGNORE(g_key_file_set_integer_list)
/** Sets a list of doubles for the @a key under @a group_name.
* If either the @a key or @a group_name cannot be found they are created.
* @param group_name The name of a group
* @param key The name of a key
* @param list A list holding object of type int
*
* @newin2p14
*/
void set_double_list(const Glib::ustring& group_name, const Glib::ustring& key, Glib::ArrayHandle<double>& list);
_IGNORE(g_key_file_set_double_list)
/** Places @a comment at the start of the file, before the first group.
* @param comment The Comment
*/
void set_comment(const Glib::ustring& comment);
/** Places @a comment above @a group_name.
* @param group_name The Group the comment should be above
* @param comment The comment
*/
void set_comment(const Glib::ustring& group_name, const Glib::ustring& comment);
/** Places a comment above @a key from @a group_name.
* @param key Key comment should be above
* @param group_name Group comment is in
* @param comment The comment
*/
_WRAP_METHOD(void set_comment(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& comment), g_key_file_set_comment, errthrow)
_WRAP_METHOD(void remove_comment(const Glib::ustring& group_name, const Glib::ustring& key), g_key_file_remove_comment, errthrow)
_WRAP_METHOD(void remove_key(const Glib::ustring& group_name, const Glib::ustring& key), g_key_file_remove_key, errthrow)
_WRAP_METHOD(void remove_group(const Glib::ustring& group_name), g_key_file_remove_group, errthrow)
GKeyFile* gobj() { return gobject_; }
const GKeyFile* gobj() const { return gobject_; }
protected:
GKeyFile* gobject_;
bool owns_gobject_;
private:
// noncopyable
KeyFile(const KeyFile&);
KeyFile& operator=(const KeyFile&);
};
} // namespace Glib

View file

@ -0,0 +1,346 @@
// -*- c++ -*-
/* $Id: markup.ccg,v 1.5 2006/10/04 12:04:09 murrayc Exp $ */
/* 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)
{
if(!&error) error = error; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
g_return_if_fail(context == cpp_context.gobj());
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
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);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(MarkupError& err)
{
err.propagate(error);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
void ParserCallbacks::end_element(GMarkupParseContext* context,
const char* element_name,
void* user_data,
GError** error)
{
if(!&error) error = error; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
g_return_if_fail(context == cpp_context.gobj());
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
cpp_context.get_parser()->on_end_element(cpp_context, element_name);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(MarkupError& err)
{
err.propagate(error);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
void ParserCallbacks::text(GMarkupParseContext* context,
const char* text,
gsize text_len,
void* user_data,
GError** error)
{
if(!&error) error = error; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
g_return_if_fail(context == cpp_context.gobj());
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
cpp_context.get_parser()->on_text(cpp_context, Glib::ustring(text, text + text_len));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(MarkupError& err)
{
err.propagate(error);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
void ParserCallbacks::passthrough(GMarkupParseContext* context,
const char* passthrough_text,
gsize text_len,
void* user_data,
GError** error)
{
if(!&error) error = error; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
g_return_if_fail(context == cpp_context.gobj());
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
cpp_context.get_parser()->on_passthrough(
cpp_context, Glib::ustring(passthrough_text, passthrough_text + text_len));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(MarkupError& err)
{
err.propagate(error);
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
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);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
cpp_context.get_parser()->on_error(cpp_context, MarkupError(g_error_copy(error)));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
/**** 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

View file

@ -0,0 +1,346 @@
/* $Id: markup.hg,v 1.5 2005/01/21 12:48:05 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#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.
*/
_WRAP_GERROR(MarkupError, GMarkupError, G_MARKUP_ERROR, NO_GTYPE)
/*! @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);
/** 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).
*/
_WRAP_ENUM(ParseFlags, GMarkupParseFlags, NO_GTYPE, s#^MARKUP_##)
/*! @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

View file

@ -0,0 +1,44 @@
// -*- c++ -*-
/* $Id: module.ccg,v 1.2 2004/04/09 14:49:44 murrayc Exp $ */
/* 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

View file

@ -0,0 +1,153 @@
/* $Id: module.hg,v 1.5 2004/04/09 14:49:44 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#include <glibmmconfig.h>
#include <string>
GLIBMM_USING_STD(string)
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GModule GModule; }
#endif
namespace Glib
{
_WRAP_ENUM(ModuleFlags, GModuleFlags, NO_GTYPE)
//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
{
_CLASS_GENERIC(Module, GModule)
_IGNORE(g_module_open, g_module_close)
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
*/
_WRAP_METHOD(static bool get_supported(), g_module_supported)
/** Ensures that a module will never be unloaded. Any calls to the
* Glib::Module destructor will not unload the module.
*/
_WRAP_METHOD(void make_resident(), g_module_make_resident)
/** Gets a string describing the last module error.
* @returns The error string
*/
_WRAP_METHOD(static std::string get_last_error(), g_module_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.
*/
_WRAP_METHOD(bool get_symbol(const std::string& symbol_name, void*& symbol) const, g_module_symbol)
/** Get the name of the module.
* @returns The name of the module
*/
_WRAP_METHOD(std::string get_name() const, g_module_name)
/** 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 ""
_WRAP_METHOD(static std::string build_path(const std::string& directory, const std::string& module_name), g_module_build_path)
GModule* gobj() { return gobject_; }
const GModule* gobj() const { return gobject_; }
protected:
GModule* gobject_;
private:
// noncopyable
Module(const Module&);
Module& operator=(const Module&);
};
} // namespace Glib

View file

@ -0,0 +1,112 @@
// -*- c++ -*-
/* $Id: optioncontext.ccg,v 1.4 2004/10/30 14:25:45 murrayc Exp $ */
/* 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 <glibmm/exceptionhandler.h>
#include <glib/goption.h>
namespace Glib
{
namespace Private
{
static const gchar* SignalProxy_translate_gtk_callback (const gchar* str, gpointer data)
{
Glib::ustring translated_str;
Glib::OptionContext::SlotTranslate* the_slot =
static_cast<Glib::OptionContext::SlotTranslate*>(data);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
translated_str = (*the_slot)(str);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
return translated_str.c_str ();
}
static void SignalProxy_translate_gtk_callback_destroy (gpointer data)
{
delete static_cast<Glib::OptionContext::SlotTranslate*>(data);
}
} //namespace Private
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;
}
*/
void OptionContext::set_translate_func (const SlotTranslate& slot)
{
//Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
//It will be deleted when SignalProxy_translate_gtk_callback_destroy() is called.
SlotTranslate* slot_copy = new SlotTranslate(slot);
g_option_context_set_translate_func(
gobj(), &Private::SignalProxy_translate_gtk_callback, slot_copy,
&Private::SignalProxy_translate_gtk_callback_destroy);
}
} // namespace Glib

View file

@ -0,0 +1,127 @@
/* $Id: optioncontext.hg,v 1.6 2005/01/10 17:42:17 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#include <glibmm/optionentry.h>
#include <glibmm/optiongroup.h>
#include <glibmm/error.h>
#include <sigc++/signal.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GOptionContext GOptionContext; }
#endif
namespace Glib
{
/** Exception class for options.
*/
_WRAP_GERROR(OptionError, GOptionError, G_OPTION_ERROR, NO_GTYPE)
/** An OptionContext defines which options are accepted by the commandline option parser.
*/
class OptionContext
{
_CLASS_GENERIC(OptionContext, GOptionContext)
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();
_WRAP_METHOD(void set_help_enabled(bool help_enabled = true), g_option_context_set_help_enabled)
_WRAP_METHOD(bool get_help_enabled() const, g_option_context_get_help_enabled)
_WRAP_METHOD(void set_ignore_unknown_options(bool ignore_unknown = true), g_option_context_set_ignore_unknown_options)
_WRAP_METHOD(bool get_ignore_unknown_options() const, g_option_context_get_ignore_unknown_options)
#m4 _CONVERSION(`char**&',`gchar***',`&($3)')
_WRAP_METHOD(bool parse(int& argc, char**& argv), g_option_context_parse, errthrow)
//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.
_IGNORE(g_option_context_add_main_entries)
/** 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);
_IGNORE(g_option_context_add_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);
_IGNORE(g_option_context_set_main_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;
_IGNORE(g_option_context_get_main_group)
GOptionContext* gobj() { return gobject_; }
const GOptionContext* gobj() const { return gobject_; }
_WRAP_METHOD(void set_summary(const Glib::ustring& summary), g_option_context_set_summary)
_WRAP_METHOD(Glib::ustring get_summary() const, g_option_context_get_summary)
_WRAP_METHOD(void set_description(const Glib::ustring& description), g_option_context_set_description)
_WRAP_METHOD(Glib::ustring get_description() const, g_option_context_get_description)
_WRAP_METHOD(void set_translation_domain(const Glib::ustring& domain), g_option_context_set_translation_domain)
/**
* This function is used to translate user-visible strings, for --help output.
* The function takes an untranslated string and returns a translated string
*/
typedef sigc::slot<Glib::ustring, const Glib::ustring&> SlotTranslate;
/**
* Sets the function which is used to translate user-visible
* strings, for --help output. Different groups can use different functions.
*
* If you are using gettext(), you only need to set the translation domain,
* see set_translation_domain().
*
* @newin2p14
*/
void set_translate_func (const SlotTranslate& slot);
_IGNORE(g_option_context_set_translate_func)
protected:
GOptionContext* gobject_;
bool has_ownership_;
};
} // namespace Glib

View file

@ -0,0 +1,79 @@
// -*- c++ -*-
/* $Id: optionentry.ccg,v 1.8 2006/03/08 12:23:03 murrayc Exp $ */
/* 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_ = 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

View file

@ -0,0 +1,96 @@
/* $Id: optionentry.hg,v 1.11 2005/07/31 13:11:05 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#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
{
_CLASS_GENERIC(OptionEntry, GOptionEntry)
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,
FLAG_NO_ARG = 1 << 3,
FLAG_FILENAME = 1 << 4,
FLAG_OPTIONAL_ARG = 1 << 5,
FLAG_NOALIAS = 1 << 6
} GOptionFlags;
OptionEntry();
OptionEntry(const OptionEntry& src);
virtual ~OptionEntry();
OptionEntry& operator=(const OptionEntry& src);
#m4 _CONVERSION(`Glib::ustring',`const gchar*',`g_strdup(($3).c_str())')
_MEMBER_GET(long_name, long_name, Glib::ustring, const char*)
_MEMBER_SET(long_name, long_name, Glib::ustring, const char*)
_MEMBER_GET(short_name, short_name, gchar, gchar)
_MEMBER_SET(short_name, short_name, gchar, gchar)
_MEMBER_GET(flags, flags, int, int)
_MEMBER_SET(flags, flags, int, int)
//TODO: G_OPTION_ARG_CALLBACK,
_MEMBER_GET(description, description, Glib::ustring, const char*)
_MEMBER_SET(description, description, Glib::ustring, const char*)
_MEMBER_GET(arg_description, arg_description, Glib::ustring, const char*)
_MEMBER_SET(arg_description, arg_description, Glib::ustring, const char*)
GOptionEntry* gobj() { return gobject_; }
const GOptionEntry* gobj() const { return gobject_; }
protected:
GOptionEntry* gobject_;
};
} // namespace Glib

View file

@ -0,0 +1,518 @@
// -*- c++ -*-
/* $Id: optiongroup.ccg,v 1.15.4.3 2006/03/30 12:19:58 murrayc Exp $ */
/* 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/gmem.h> // g_malloc
#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.set_c_arg_default(cpp_arg);
cppEntry.cpparg_ = cpp_arg;
//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_ is deleted in release_c_arg(), via the destructor.
cppEntry.entry_->gobj()->arg = arg_type;
cppEntry.entry_->gobj()->arg_data = cppEntry.carg_;
//Remember the C++/C mapping so that we can use it later:
map_entries_[name] = cppEntry;
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.
//
//We must also call set_c_arg_default() to give these C types the specified defaults based on the C++-typed arguments.
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*;
//The C code will allocate a char* and put it here, for us to g_free() later.
//Alternatively, set_c_arg_default() might allocate a char*, and the C code might or might not free and replace that.
*typed_arg = 0;
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::set_c_arg_default(void* cpp_arg)
{
switch(carg_type_)
{
case G_OPTION_ARG_INT:
{
*static_cast<int*>(carg_) = *static_cast<int*>(cpp_arg);
break;
}
case G_OPTION_ARG_NONE:
{
*static_cast<gboolean*>(carg_) = *static_cast<bool*>(cpp_arg);
break;
}
case G_OPTION_ARG_STRING:
{
Glib::ustring* typed_cpp_arg = static_cast<Glib::ustring*>(cpp_arg);
if(typed_cpp_arg && !typed_cpp_arg->empty())
{
const char** typed_c_arg = static_cast<const char**>(carg_);
*typed_c_arg = g_strdup(typed_cpp_arg->c_str()); //Freed in release_c_arg().
}
break;
}
case G_OPTION_ARG_FILENAME:
{
std::string* typed_cpp_arg = static_cast<std::string*>(cpp_arg);
if(typed_cpp_arg && !typed_cpp_arg->empty())
{
const char** typed_c_arg = static_cast<const char**>(carg_);
*typed_c_arg = g_strdup(typed_cpp_arg->c_str()); //Freed in release_c_arg().
}
break;
}
case G_OPTION_ARG_STRING_ARRAY:
{
std::vector<Glib::ustring>* typed_cpp_arg = static_cast<std::vector<Glib::ustring>*>(cpp_arg);
if(typed_cpp_arg)
{
std::vector<Glib::ustring>& vec = *typed_cpp_arg;
const char** array = static_cast<const char**>( g_malloc(sizeof(gchar*) * (vec.size() + 1)) );
for(std::vector<Glib::ustring>::size_type i = 0; i < vec.size(); ++i)
{
array[i] = g_strdup( vec[i].c_str() );
}
array[vec.size()] = 0;
const char*** typed_c_arg = static_cast<const char***>(carg_);
*typed_c_arg = array;
}
break;
}
case G_OPTION_ARG_FILENAME_ARRAY:
{
std::vector<std::string>* typed_cpp_arg = static_cast<std::vector<std::string>*>(cpp_arg);
if(typed_cpp_arg)
{
std::vector<std::string>& vec = *typed_cpp_arg;
const char** array = static_cast<const char**>( g_malloc(sizeof(gchar*) * (vec.size() + 1)) );
for(std::vector<Glib::ustring>::size_type i = 0; i < vec.size(); ++i)
{
array[i] = g_strdup( vec[i].c_str() );
}
array[vec.size()] = 0;
const char*** typed_c_arg = static_cast<const char***>(carg_);
*typed_c_arg = array;
}
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 = static_cast<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 = static_cast<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 = static_cast<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 = static_cast<char**>(carg_);
Glib::ustring* typed_cpp_arg = static_cast<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 = static_cast<char**>(carg_);
std::string* typed_cpp_arg = static_cast<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_) = *(static_cast<int*>(carg_));
break;
}
case G_OPTION_ARG_STRING_ARRAY:
{
char*** typed_arg = static_cast<char***>(carg_);
vecustrings* typed_cpp_arg = static_cast<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 = static_cast<char***>(carg_);
vecustrings* typed_cpp_arg = static_cast<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. */
{
*(static_cast<bool*>(cpparg_)) = *(static_cast<gboolean*>(carg_));
break;
}
default:
{
/* TODO:
G_OPTION_ARG_CALLBACK,
*/
break;
}
}
}
GOptionGroup* OptionGroup::gobj_give_ownership()
{
has_ownership_ = false;
return gobj();
}
} // namespace Glib

View file

@ -0,0 +1,124 @@
/* $Id: optiongroup.hg,v 1.10.4.1 2006/03/30 12:19:58 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#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
{
_CLASS_GENERIC(OptionGroup, GOptionGroup)
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);
_IGNORE(g_option_group_new)
virtual ~OptionGroup();
_IGNORE(g_option_group_free)
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);
_IGNORE(g_option_group_set_parse_hooks, g_option_group_set_error_hook)
void add_entry(const OptionEntry& entry);
_IGNORE(g_option_group_add_entries)
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);
*/
_WRAP_METHOD(void set_translation_domain(const Glib::ustring& domain), g_option_group_set_translation_domain)
GOptionGroup* gobj() { return gobject_; }
const GOptionGroup* gobj() const { return gobject_; }
GOptionGroup* gobj_give_ownership();
protected:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/** This is not public API. It is an implementation detail.
*/
class CppOptionEntry
{
public:
CppOptionEntry();
void allocate_c_arg();
void set_c_arg_default(void* cpp_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.
#endif //DOXYGEN_SHOULD_SKIP_THIS
};
} // namespace Glib

View file

@ -0,0 +1,204 @@
/* Copyright (C) 2007 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/utility.h>
namespace Glib
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::RefPtr<Glib::Regex> Regex::create(const Glib::ustring& pattern,
RegexCompileFlags compile_options,
RegexMatchFlags match_options)
#else
Glib::RefPtr<Glib::Regex> Regex::create(const Glib::ustring& pattern,
RegexCompileFlags compile_options,
RegexMatchFlags match_options,
std::auto_ptr<Glib::Error>& error)
#endif /* GLIBMM_EXCEPTIONS_ENABLED */
{
GError* gerror = 0;
GRegex* regex = g_regex_new(pattern.c_str(), (GRegexCompileFlags)compile_options,
(GRegexMatchFlags)match_options, &gerror);
if(gerror)
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::Error::throw_exception(gerror);
#else
error = Glib::Error::throw_exception(gerror);
#endif
return Glib::wrap(regex);
}
// static
Glib::ustring Regex::escape_string(const Glib::ustring& string)
{
const Glib::ScopedPtr<char> buf (g_regex_escape_string(string.raw().c_str(),
string.raw().size()));
return Glib::ustring(buf.get());
}
bool Regex::match(const Glib::ustring& string, RegexMatchFlags match_options)
{
return g_regex_match(gobj(), string.c_str(), (GRegexMatchFlags)(match_options), 0);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool Regex::match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options)
#else
bool Regex::match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
bool retvalue = g_regex_match_full(gobj(), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
#else
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return retvalue;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool Regex::match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options)
#else
bool Regex::match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
bool retvalue = g_regex_match_full(gobj(), string.c_str(), string_len, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
#else
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return retvalue;
}
bool Regex::match_all(const Glib::ustring& string, RegexMatchFlags match_options)
{
return g_regex_match_all(gobj(), string.c_str(), ((GRegexMatchFlags)(match_options)), 0);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool Regex::match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options)
#else
bool Regex::match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
#else
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return retvalue;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool Regex::match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options)
#else
bool Regex::match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), string_len, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
#else
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return retvalue;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring Regex::replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options)
#else
Glib::ustring Regex::replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
Glib::ustring retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_regex_replace(gobj(), string.c_str(), -1, start_position, replacement.c_str(), ((GRegexMatchFlags)(match_options)), &(gerror)));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
#else
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return retvalue;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring Regex::replace_literal(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options)
#else
Glib::ustring Regex::replace_literal(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
Glib::ustring retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_regex_replace_literal(gobj(), string.c_str(), -1, start_position, replacement.c_str(), ((GRegexMatchFlags)(match_options)), &(gerror)));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
#else
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return retvalue;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::StringArrayHandle Regex::split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens) const
#else
Glib::StringArrayHandle Regex::split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens, std::auto_ptr<Glib::Error>& error) const
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
Glib::StringArrayHandle retvalue = Glib::StringArrayHandle(g_regex_split_full(const_cast<GRegex*>(gobj()), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), max_tokens, &(gerror)), Glib::OWNERSHIP_DEEP);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
#else
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
return retvalue;
}
} // namespace Glib

View file

@ -0,0 +1,209 @@
/* Copyright (C) 2007 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.
*/
_DEFS(glibmm,glib)
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <glibmm/error.h>
#include <glibmm/arrayhandle.h>
#include <glib/gregex.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GRegex GRegex;
#endif
namespace Glib
{
_WRAP_ENUM(RegexCompileFlags, GRegexCompileFlags, NO_GTYPE)
_WRAP_ENUM(RegexMatchFlags, GRegexMatchFlags, NO_GTYPE)
/** Exception class for Regex
*/
_WRAP_GERROR(RegexError, GRegexError, G_REGEX_ERROR, NO_GTYPE)
/** Perl-compatible regular expressions - matches strings against regular expressions.
*
* The Glib::Regex functions implement regular expression pattern matching using
* syntax and semantics similar to Perl regular expression.
*
* Some functions accept a start_position argument, setting it differs from just
* passing over a shortened string and setting REGEX_MATCH_NOTBOL in the case
* of a pattern that begins with any kind of lookbehind assertion. For example,
* consider the pattern "\Biss\B" which finds occurrences of "iss" in the middle
* of words. ("\B" matches only if the current position in the subject is not a
* word boundary.) When applied to the string "Mississipi" from the fourth byte,
* namely "issipi", it does not match, because "\B" is always false at the
* start of the subject, which is deemed to be a word boundary. However, if
* the entire string is passed , but with start_position set to 4, it finds the
* second occurrence of "iss" because it is able to look behind the starting point
* to discover that it is preceded by a letter.
*
* Note that, unless you set the REGEX_RAW flag, all the strings passed to these
* functions must be encoded in UTF-8. The lengths and the positions inside the
* strings are in bytes and not in characters, so, for instance,
* "\xc3\xa0" (i.e. "à") is two bytes long but it is treated as a single
* character. If you set REGEX_RAW the strings can be non-valid UTF-8 strings
* and a byte is treated as a character, so "\xc3\xa0" is two bytes and
* two characters long.
*
* When matching a pattern, "\n" matches only against a "\n" character in the
* string, and "\r" matches only a "\r" character. To match any newline sequence
* use "\R". This particular group matches either the two-character sequence
* CR + LF ("\r\n"), or one of the single characters LF (linefeed, U+000A, "\n"),
* VT (vertical tab, U+000B, "\v"), FF (formfeed, U+000C, "\f"), CR (carriage
* return, U+000D, "\r"), NEL (next line, U+0085), LS (line separator, U+2028),
* or PS (paragraph separator, U+2029).
*
* The behaviour of the dot, circumflex, and dollar metacharacters are affected
* by newline characters, the default is to recognize any newline character (the
* same characters recognized by "\R"). This can be changed with REGEX_NEWLINE_CR,
* REGEX_NEWLINE_LF and REGEX_NEWLINE_CRLF compile options, and with
* REGEX_MATCH_NEWLINE_ANY, REGEX_MATCH_NEWLINE_CR, REGEX_MATCH_NEWLINE_LF
* and REGEX_MATCH_NEWLINE_CRLF match options. These settings are also
* relevant when compiling a pattern if REGEX_EXTENDED is set, and an unescaped
* "#" outside a character class is encountered. This indicates a comment that
* lasts until after the next newline.
*
* Creating and manipulating the same Glib::Regex class from different threads is
* not a problem as Glib::Regex does not modify its internal state between creation and
* destruction, on the other hand Glib::MatchInfo is not threadsafe.
*
* The regular expressions low level functionalities are obtained through the
* excellent PCRE library written by Philip Hazel.
*
* @newin2p14
*/
class Regex
{
_CLASS_OPAQUE_REFCOUNTED(Regex, GRegex, NONE, g_regex_ref, g_regex_unref)
_IGNORE(g_regex_ref, g_regex_unref)
public:
#ifdef GLIBMM_EXCEPTIONS_ENABLED
static Glib::RefPtr<Glib::Regex> create(const Glib::ustring& pattern, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
#else
static Glib::RefPtr<Glib::Regex> create(const Glib::ustring& pattern, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0), std::auto_ptr<Glib::Error>& error);
#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
_WRAP_METHOD(Glib::ustring get_pattern() const, g_regex_get_pattern)
_WRAP_METHOD(int get_max_backref() const, g_regex_get_max_backref)
_WRAP_METHOD(int get_capture_count() const, g_regex_get_capture_count)
_WRAP_METHOD(int get_string_number(const Glib::ustring& name) const, g_regex_get_string_number)
static Glib::ustring escape_string(const Glib::ustring& string);
_WRAP_METHOD(static bool match_simple(const Glib::ustring& pattern, const Glib::ustring& string, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)), g_regex_match_simple)
//TODO: _WRAP_METHOD(bool match(const Glib::ustring& string, RegexMatchFlags match_options = (RegexMatchFlags)0, GMatchInfo **match_info = 0), g_regex_match)
bool match(const Glib::ustring& string, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
//TODO: Wrap GMatchInfo as an iterator:
//_WRAP_METHOD(bool match_full(const gchar* string, gssize string_len, int start_position, RegexMatchFlags match_options = (RegexMatchFlags)0, GMatchInfo** match_info = 0), g_regex_match_full, errthrow)
#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options);
#else
bool match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options);
#else
bool match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
//TODO: _WRAP_METHOD(bool match_all(const Glib::ustring& string, RegexMatchFlags match_options = (RegexMatchFlags)0, GMatchInfo ** match_info = 0), g_regex_match_all)
bool match_all(const Glib::ustring& string, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
//TODO: _WRAP_METHOD(bool match_all_full(const gchar* string, gssize string_len, int start_position, RegexMatchFlags match_options = (RegexMatchFlags)0, GMatchInfo** match_info = 0), g_regex_match_all_full, errthrow)
#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options);
#else
bool match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
#ifdef GLIBMM_EXCEPTIONS_ENABLED
bool match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options);
#else
bool match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
#m4 _CONVERSION(`gchar**',`Glib::StringArrayHandle',`Glib::StringArrayHandle($3, Glib::OWNERSHIP_DEEP)')
_WRAP_METHOD(static Glib::StringArrayHandle split_simple(const Glib::ustring& pattern, const Glib::ustring& string, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)), g_regex_split_simple)
_WRAP_METHOD(Glib::StringArrayHandle split(const Glib::ustring& string, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)), g_regex_split)
_WRAP_METHOD(Glib::StringArrayHandle split(const gchar* string, gssize string_len, int start_position, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0), int max_tokens = 0) const, g_regex_split_full, errthrow)
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::StringArrayHandle split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens) const;
#else
Glib::StringArrayHandle split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens, std::auto_ptr<Glib::Error>& error) const;
#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
_WRAP_METHOD(Glib::ustring replace(const gchar* string, gssize string_len, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)), g_regex_replace, errthrow)
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options);
#else
Glib::ustring replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
_WRAP_METHOD(Glib::ustring replace_literal(const gchar *string, gssize string_len, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)), g_regex_replace_literal, errthrow)
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring replace_literal(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options);
#else
Glib::ustring replace_literal(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
_WRAP_METHOD(Glib::ustring replace_eval(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, GRegexEvalCallback eval, gpointer user_data), g_regex_replace_eval, errthrow)
_WRAP_METHOD(static bool check_replacement(const Glib::ustring& replacement, gboolean* has_references), g_regex_check_replacement, errthrow)
/* Match info */
/*
GRegex *g_match_info_get_regex (const GMatchInfo *match_info);
const gchar *g_match_info_get_string (const GMatchInfo *match_info);
void g_match_info_free (GMatchInfo *match_info);
_WRAP_METHOD(bool g_match_info_next (GMatchInfo *match_info,
GError **error);
_WRAP_METHOD(bool g_match_info_matches (const GMatchInfo *match_info);
_WRAP_METHOD(int g_match_info_get_match_count (const GMatchInfo *match_info);
_WRAP_METHOD(bool g_match_info_is_partial_match (const GMatchInfo *match_info);
Glib::ustring g_match_info_expand_references(const GMatchInfo *match_info,
Glib::ustring& string_to_expand,
GError **error);
Glib::ustring g_match_info_fetch (const GMatchInfo *match_info,
int match_num);
_WRAP_METHOD(bool g_match_info_fetch_pos (const GMatchInfo *match_info,
int match_num,
int *start_pos,
int *end_pos);
Glib::ustring g_match_info_fetch_named (const GMatchInfo *match_info,
Glib::ustring& name);
_WRAP_METHOD(bool g_match_info_fetch_named_pos (const GMatchInfo *match_info,
Glib::ustring& name,
int *start_pos,
int *end_pos);
gchar **g_match_info_fetch_all (const GMatchInfo *match_info);
*/
};
} // namespace Glib

View file

@ -0,0 +1,61 @@
// -*- c++ -*-
/* $Id: shell.ccg,v 1.1 2003/01/07 16:58:38 murrayc Exp $ */
/* 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

View file

@ -0,0 +1,96 @@
/* $Id: shell.hg,v 1.2 2003/01/22 21:38:35 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#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.
*/
_WRAP_GERROR(ShellError, GShellError, G_SHELL_ERROR, NO_GTYPE)
/** 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

View file

@ -0,0 +1,200 @@
// -*- c++ -*-
dnl
dnl Glib SignalProxy Templates
dnl
dnl Copyright 2001 Free Software Foundation
dnl Copyright 1999 Karl Nelson <kenelson@ece.ucdavis.edu>
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Library General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Library General Public License for more details.
dnl
dnl You should have received a copy of the GNU Library General Public
dnl License along with this library; if not, write to the Free
dnl Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
dnl
dnl Ignore the next line
/* This is a generated file, do not edit. Generated from __file__ */
include(template.macros.m4)
#ifndef __header__
#define __header__
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&);
};
dnl
dnl GLIB_SIGNAL_PROXY([P1, P2, ...],return type)
dnl
define([GLIB_SIGNAL_PROXY],[dnl
LINE(]__line__[)dnl
/**** Glib::[SignalProxy]NUM($1) ***************************************************/
/** Proxy for signals with NUM($1) arguments.
* Use the connect() method, with sigc::mem_fun() or sigc::ptr_fun() to connect signals to signal handlers.
*/
template <LIST(class R,ARG_CLASS($1))>
class [SignalProxy]NUM($1) : public SignalProxyNormal
{
public:
typedef sigc::slot<LIST(R,ARG_TYPE($1))> SlotType;
typedef sigc::slot<LIST(void,ARG_TYPE($1))> VoidSlotType;
[SignalProxy]NUM($1)(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)); }
};
])dnl
dnl Template forms of SignalProxy
GLIB_SIGNAL_PROXY(ARGS(P,0))
GLIB_SIGNAL_PROXY(ARGS(P,1))
GLIB_SIGNAL_PROXY(ARGS(P,2))
GLIB_SIGNAL_PROXY(ARGS(P,3))
GLIB_SIGNAL_PROXY(ARGS(P,4))
GLIB_SIGNAL_PROXY(ARGS(P,5))
GLIB_SIGNAL_PROXY(ARGS(P,6))
} // namespace Glib
#endif /* __header__ */

View file

@ -0,0 +1,283 @@
// -*- c++ -*-
/* $Id: spawn.ccg,v 1.8 2006/05/12 08:08:44 murrayc Exp $ */
/* 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/gspawn.h>
#include <glibmm/exceptionhandler.h>
#include <glibmm/utility.h>
namespace
{
extern "C"
{
/* Helper callback to invoke the actual sigc++ slot.
* We don't need to worry about (un)referencing, since the
* child process gets its own copy of the parent's memory anyway.
*/
static void child_setup_callback(void* user_data)
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
(*reinterpret_cast<sigc::slot<void>*>(user_data))();
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
}
static void copy_output_buf(std::string* dest, const char* buf)
{
if(dest)
{
if(buf)
*dest = buf;
else
dest->erase();
}
}
} //extern "C"
} //anonymous namespace
namespace Glib
{
/**** process spawning functions *******************************************/
void spawn_async_with_pipes(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
const Glib::ArrayHandle<std::string>& envp,
SpawnFlags flags,
const sigc::slot<void>& child_setup,
Pid* child_pid,
int* standard_input,
int* standard_output,
int* standard_error)
{
const bool setup_slot = !child_setup.empty();
sigc::slot<void> child_setup_ = child_setup;
GError* error = 0;
g_spawn_async_with_pipes(
working_directory.c_str(),
const_cast<char**>(argv.data()),
const_cast<char**>(envp.data()),
static_cast<GSpawnFlags>(unsigned(flags)),
(setup_slot) ? &child_setup_callback : 0,
(setup_slot) ? &child_setup_ : 0,
child_pid,
standard_input, standard_output, standard_error,
&error);
if(error)
Glib::Error::throw_exception(error);
}
void spawn_async_with_pipes(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
SpawnFlags flags,
const sigc::slot<void>& child_setup,
Pid* child_pid,
int* standard_input,
int* standard_output,
int* standard_error)
{
const bool setup_slot = !child_setup.empty();
sigc::slot<void> child_setup_ = child_setup;
GError* error = 0;
g_spawn_async_with_pipes(
working_directory.c_str(),
const_cast<char**>(argv.data()), 0,
static_cast<GSpawnFlags>(unsigned(flags)),
(setup_slot) ? &child_setup_callback : 0,
(setup_slot) ? &child_setup_ : 0,
child_pid,
standard_input, standard_output, standard_error,
&error);
if(error)
Glib::Error::throw_exception(error);
}
void spawn_async(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
const Glib::ArrayHandle<std::string>& envp,
SpawnFlags flags,
const sigc::slot<void>& child_setup,
Pid* child_pid)
{
const bool setup_slot = !child_setup.empty();
sigc::slot<void> child_setup_ = child_setup;
GError* error = 0;
g_spawn_async(
working_directory.c_str(),
const_cast<char**>(argv.data()),
const_cast<char**>(envp.data()),
static_cast<GSpawnFlags>(unsigned(flags)),
(setup_slot) ? &child_setup_callback : 0,
(setup_slot) ? &child_setup_ : 0,
child_pid,
&error);
if(error)
Glib::Error::throw_exception(error);
}
void spawn_async(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
SpawnFlags flags,
const sigc::slot<void>& child_setup,
Pid* child_pid)
{
const bool setup_slot = !child_setup.empty();
sigc::slot<void> child_setup_ = child_setup;
GError* error = 0;
g_spawn_async(
working_directory.c_str(),
const_cast<char**>(argv.data()), 0,
static_cast<GSpawnFlags>(unsigned(flags)),
(setup_slot) ? &child_setup_callback : 0,
(setup_slot) ? &child_setup_ : 0,
child_pid,
&error);
if(error)
Glib::Error::throw_exception(error);
}
void spawn_sync(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
const Glib::ArrayHandle<std::string>& envp,
SpawnFlags flags,
const sigc::slot<void>& child_setup,
std::string* standard_output,
std::string* standard_error,
int* exit_status)
{
const bool setup_slot = !child_setup.empty();
sigc::slot<void> child_setup_ = child_setup;
Glib::ScopedPtr<char> buf_standard_output;
Glib::ScopedPtr<char> buf_standard_error;
GError* error = 0;
g_spawn_sync(
working_directory.c_str(),
const_cast<char**>(argv.data()),
const_cast<char**>(envp.data()),
static_cast<GSpawnFlags>(unsigned(flags)),
(setup_slot) ? &child_setup_callback : 0,
(setup_slot) ? &child_setup_ : 0,
(standard_output) ? buf_standard_output.addr() : 0,
(standard_error) ? buf_standard_error.addr() : 0,
exit_status,
&error);
if(error)
Glib::Error::throw_exception(error);
copy_output_buf(standard_output, buf_standard_output.get());
copy_output_buf(standard_error, buf_standard_error.get());
}
void spawn_sync(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
SpawnFlags flags,
const sigc::slot<void>& child_setup,
std::string* standard_output,
std::string* standard_error,
int* exit_status)
{
const bool setup_slot = !child_setup.empty();
sigc::slot<void> child_setup_ = child_setup;
Glib::ScopedPtr<char> buf_standard_output;
Glib::ScopedPtr<char> buf_standard_error;
GError* error = 0;
g_spawn_sync(
working_directory.c_str(),
const_cast<char**>(argv.data()), 0,
static_cast<GSpawnFlags>(unsigned(flags)),
(setup_slot) ? &child_setup_callback : 0,
(setup_slot) ? &child_setup_ : 0,
(standard_output) ? buf_standard_output.addr() : 0,
(standard_error) ? buf_standard_error.addr() : 0,
exit_status,
&error);
if(error)
Glib::Error::throw_exception(error);
copy_output_buf(standard_output, buf_standard_output.get());
copy_output_buf(standard_error, buf_standard_error.get());
}
void spawn_command_line_async(const std::string& command_line)
{
GError* error = 0;
g_spawn_command_line_async(command_line.c_str(), &error);
if(error)
Glib::Error::throw_exception(error);
}
void spawn_command_line_sync(const std::string& command_line,
std::string* standard_output,
std::string* standard_error,
int* exit_status)
{
Glib::ScopedPtr<char> buf_standard_output;
Glib::ScopedPtr<char> buf_standard_error;
GError* error = 0;
g_spawn_command_line_sync(
command_line.c_str(),
(standard_output) ? buf_standard_output.addr() : 0,
(standard_error) ? buf_standard_error.addr() : 0,
exit_status,
&error);
if(error)
Glib::Error::throw_exception(error);
copy_output_buf(standard_output, buf_standard_output.get());
copy_output_buf(standard_error, buf_standard_error.get());
}
void spawn_close_pid(Pid pid)
{
g_spawn_close_pid(pid);
}
} // namespace Glib

View file

@ -0,0 +1,109 @@
/* $Id: spawn.hg,v 1.4 2004/03/02 23:29:57 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#include <string>
#include <sigc++/sigc++.h>
#include <glibmm/arrayhandle.h>
#include <glibmm/error.h>
#include <glibmmconfig.h>
GLIBMM_USING_STD(string)
namespace Glib
{
typedef GPid Pid;
_WRAP_ENUM(SpawnFlags, GSpawnFlags, NO_GTYPE)
/** @defgroup Spawn Spawning Processes
* Process launching with fork()/exec().
* @{
*/
/** Exception class for errors occuring when spawning processes.
*/
_WRAP_GERROR(SpawnError, GSpawnError, G_SPAWN_ERROR, NO_GTYPE, s#^2BIG$#TOOBIG#)
void spawn_async_with_pipes(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
const Glib::ArrayHandle<std::string>& envp,
SpawnFlags flags = SpawnFlags(0),
const sigc::slot<void>& child_setup = sigc::slot<void>(),
Pid* child_pid = 0,
int* standard_input = 0,
int* standard_output = 0,
int* standard_error = 0);
void spawn_async_with_pipes(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
SpawnFlags flags = SpawnFlags(0),
const sigc::slot<void>& child_setup = sigc::slot<void>(),
Pid* child_pid = 0,
int* standard_input = 0,
int* standard_output = 0,
int* standard_error = 0);
void spawn_async(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
const Glib::ArrayHandle<std::string>& envp,
SpawnFlags flags = SpawnFlags(0),
const sigc::slot<void>& child_setup = sigc::slot<void>(),
Pid* child_pid = 0);
void spawn_async(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
SpawnFlags flags = SpawnFlags(0),
const sigc::slot<void>& child_setup = sigc::slot<void>(),
Pid* child_pid = 0);
void spawn_sync(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
const Glib::ArrayHandle<std::string>& envp,
SpawnFlags flags = SpawnFlags(0),
const sigc::slot<void>& child_setup = sigc::slot<void>(),
std::string* standard_output = 0,
std::string* standard_error = 0,
int* exit_status = 0);
void spawn_sync(const std::string& working_directory,
const Glib::ArrayHandle<std::string>& argv,
SpawnFlags flags = SpawnFlags(0),
const sigc::slot<void>& child_setup = sigc::slot<void>(),
std::string* standard_output = 0,
std::string* standard_error = 0,
int* exit_status = 0);
void spawn_command_line_async(const std::string& command_line);
void spawn_command_line_sync(const std::string& command_line,
std::string* standard_output = 0,
std::string* standard_error = 0,
int* exit_status = 0);
void spawn_close_pid(Pid pid);
/** @} group Spawn */
} // namespace Glib

View file

@ -0,0 +1,229 @@
dnl-----------------------------------------------------------------------
dnl
dnl Karls M4 macros for the signal system used by gtk--
dnl
dnl Copyright (C) 1998-2002 The gtkmm Development Team
dnl
dnl Currently maintained by Tero Pulkkinen. <terop@modeemi.cs.tut.fi>
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Library General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Library General Public License for more details.
dnl
dnl You should have received a copy of the GNU Library General Public
dnl License along with this library; if not, write to the Free
dnl Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
dnl
dnl-----------------------------------------------------------------------
dnl Recursion prevention. (Don't attempt to understand why this works!)
changequote(, )dnl
changequote([, ])dnl
pushdef([DIVERSION],divnum)dnl
divert(-1)dnl
ifdef([__template_macros__],[],[
define(__template_macros__)
dnl-----------------------------------------------------------------------
dnl
dnl M4 macros for general sanity
dnl
dnl M4 Quotas are hard to work with, so use braces like autoconf
dnl (which are matched by vi, emacs)
changequote(, )
changequote([, ])
dnl
dnl M4 comments conflict with compiler directives
changecom(, )
dnl BRACE(text) => [text]
dnl When we want something to appear with braces
define([BRACE],[[[$*]]])
dnl
dnl PROT(macro)
dnl If a macro generates an output with commas we need to protect it
dnl from being broken down and interpreted
define([PROT],[[$*]])
dnl
dnl LOWER(string)
dnl lowercase a string
define([LOWER],[translit([$*],[ABCDEFGHIJKLMNOPQRSTUVWXYZ],[abcdefghijklmnopqrstuvwxyz])])
dnl
dnl UPPER(string)
dnl uppercase a string
define([UPPER],[translit([$*],[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
define([UPPER_SAFE],[translit([$*],[abcdefghijklmnopqrstuvwxyz.-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ__])])
dnl
dnl BASENAME(string)
dnl extract the basename of a string
define([BASENAME],[patsubst([$*],[^.*/],[])])
dnl
dnl M4NAME(string)
dnl extract the basename of a string
define([M4NAME],[patsubst(BASENAME([$*]),[\.m4$],[])])
dnl NUM(arg,arg,...)
dnl M4 defines $# very badly (empty list=1). So we need a better one
define([NUM],[ifelse(len([$*]),0,0,[$#])])
dnl
dnl IF(cond,string1,string2)
dnl places string1 if length (without spaces) of cond is zero,
dnl else string2
define([IF],[ifelse(len(PROT(translit([$1],[ ]))),0,[$3],[$2])])
dnl define([IF],[ifelse(len(PROT(patsubst([$1],[ ]))),0,[$3],[$2])])
dnl
dnl minclude(filename)
dnl This includes only the macros from a file but throws away the output.
dnl Used to take the macros from a file without getting it extra output.
define([minclude],[IF([$1],[dnl
pushdef([CURRENT_DIVERSION],divnum)dnl
divert(-1)
include($1)
divert(CURRENT_DIVERSION)dnl
popdef([CURRENT_DIVERSION])dnl],[[minclude]])])
dnl
dnl makes the current filename into a string approprate for use as
dnl C identified define. (Defaults to this library name)
dnl
dnl example: (filename test.hh.m4)
dnl __header__ => SIGCXX_TEST_H
dnl __header__(MYHEAD) => MYHEAD_TEST_H
dnl define([__header__],[ifelse($1,,[SIGCXX],UPPER($1))[_]UPPER(patsubst(translit(BASENAME(__file__),[.-],[__]),[_m4],[]))])
define([__header__],[ifelse($1,,[_GLIBMM],UPPER($1))[_]UPPER_SAFE(M4NAME(__file__))])
dnl
dnl Set of M4 macros for variable argument template building
dnl
dnl ARGS(name,number)
dnl Builds a comma seperated protected list of numbered names
dnl Use this as short hand to specify arguement names
dnl
dnl ARGS(arg,3) => ARG1,ARG2,ARG3
define([_ARGS],[ifelse(eval($2<$3),0,[$1$2],[$1$2,_ARGS($1,eval($2+1),$3)])])
define([ARGS],[ifelse(eval($2>0),1,[PROT(_ARGS(UPPER([$1]),1,$2))],[PROT])])
dnl
dnl LIST(string1,string2,...)
dnl These are intended for making extended argument lists
dnl parameters are in pairs, the first is output if the
dnl 2nd is nonzero length, the process is then repeated
dnl with the next set of arguments.
dnl
dnl Macro expansions that expand to result in commas must call
dnl PROT to prevent permature expansion. ARG* macros do
dnl this automatically. (If unsure, add braces until it stops
dnl interpreting inter macros, remove one set of braces, if
dnl still not right use PROT)
dnl
dnl (LIST is probably the most useful macro in the set.)
define([LIST],[ifelse($#,0,,$#,1,[$1],[$1],,[LIST(shift($@))],[__LIST($@)])])
define([__LIST],[ifelse($#,0,,$#,1,[$1],[$1[]ifelse([$2],,,[[,]])__LIST(shift($@))])])
dnl
dnl ARG_LOOP(macro_name,seperator,argument_list)
dnl Very powerful macro for construction of list of variables
dnl formated in specify ways. To use define a macro taking
dnl one variable which is called the format. The second argument
dnl is a seperator which will appear between each argument.
dnl The rest is then interpreted as arguments to form the list.
dnl
dnl Example:
dnl define([FOO],[foo([$1])])
dnl ARG_LOOP([FOO],[[, ]],A,B,C)
dnl
dnl Gives: foo(A), foo(B), foo(C)
dnl
define([_ARG_LOOP],[dnl
ifelse(NUM($*),0,,NUM($*),1,[dnl
indir(LOOP_FORMAT,[$1])],[dnl
indir(LOOP_FORMAT,[$1])[]LOOP_SEPERATOR[]_ARG_LOOP(shift($*))])])
define([ARG_LOOP],[dnl
pushdef([LOOP_FORMAT],[[$1]])dnl
pushdef([LOOP_SEPERATOR],[$2])dnl
_ARG_LOOP(shift(shift($*)))[]dnl
popdef([LOOP_FORMAT])dnl
popdef([LOOP_SEPERATOR])dnl
])
dnl
dnl Define some useful formats for use with ARG_LOOP.
define([FORMAT_ARG_CLASS],[class [$1]])
define([FORMAT_ARG_BOTH],[[$1] LOWER([$1])])
define([FORMAT_ARG_REF],[Type<[$1]>::ref LOWER([$1])])
define([FORMAT_ARG_TYPE],[[$1]])
define([FORMAT_ARG_NAME],[LOWER($1)])
define([FORMAT_ARG_CBNAME],[LOWER($1)_])
define([FORMAT_ARG_CBDECL],[[$1] LOWER([$1])_;])
define([FORMAT_ARG_CBINIT],[LOWER([$1])_(LOWER([$1]))])
dnl
dnl The following functions generate various types of parameter lists
dnl For parameter lists
dnl ARG_CLASS([P1,P2]) -> class P1,class P2
dnl ARG_BOTH([P1,P2]) -> P1 p1,P2 p2
dnl ARG_TYPE([P1,P2]) -> P1,P2
dnl ARG_NAME([P1,P2]) -> p1,p2
dnl For callback lists
dnl ARG_CBNAME([C1,C2]) -> c1_,c2_
dnl ARG_CBINIT([C1,C2]) -> c1_(c1),c2_(c2)
dnl ARG_CBDECL([C1,C2]) -> C1 c1_; C2 c2_;
dnl
define([ARG_CLASS],[PROT(ARG_LOOP([FORMAT_ARG_CLASS],[[,]],$*))])
define([ARG_BOTH],[PROT(ARG_LOOP([FORMAT_ARG_BOTH],[[,]],$*))])
define([ARG_REF],[PROT(ARG_LOOP([FORMAT_ARG_REF],[[,]],$*))])
define([ARG_TYPE],[PROT([$*])])
define([ARG_NAME],[PROT(LOWER($*))])
define([ARG_CBNAME],[PROT(ARG_LOOP([FORMAT_ARG_CBNAME],[[,]],$*))])
define([ARG_CBDECL],[PROT(ARG_LOOP([FORMAT_ARG_CBDECL],[ ],$*))])
define([ARG_CBINIT],[PROT(ARG_LOOP([FORMAT_ARG_CBINIT],[[,]],$*))])
dnl
dnl T_DROP(string)
dnl Removes unnecessary <> with empty templates
dnl (occasionally useful)
define([T_DROP],[ifelse([$1],<>,,[$*])])
dnl
dnl DROP(string,drop)
dnl Removes unnecessary strings if they match drop
dnl (occasionally useful)
define([DROP],[ifelse([$1],[$2],,[$*])])
dnl
dnl LINE(linenum)
dnl places a #line statement if __debug__ set
dnl Use this at top of macro template and following
dnl macros that contain newlines.
dnl
dnl example:
dnl LINE(]__line__[)dnl
define([LINE],[ifdef([__debug__],[#line $1 "]__file__["
])])
dnl-----------------------------------------------------------------------
dnl End of recursion protection. Do not put anything below this line.
])
divert(DIVERSION)dnl
popdef([DIVERSION])dnl

View file

@ -0,0 +1,371 @@
// -*- c++ -*-
/* $Id: thread.ccg,v 1.9 2006/05/12 08:08:44 murrayc Exp $ */
/* 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 <glib.h>
namespace
{
extern "C"
{
static void* call_thread_entry_slot(void* data)
{
sigc::slot_base *const slot = reinterpret_cast<sigc::slot_base*>(data);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
#endif //GLIBMM_EXCEPTIONS_ENABLED
// Recreate the specific slot, and drop the reference obtained by create().
(*static_cast<sigc::slot<void>*>(slot))();
#ifdef GLIBMM_EXCEPTIONS_ENABLED
}
catch(Glib::Thread::Exit&)
{
// Just exit from the thread. The Thread::Exit exception
// is our sane C++ replacement of g_thread_exit().
}
catch(...)
{
Glib::exception_handlers_invoke();
}
#endif //GLIBMM_EXCEPTIONS_ENABLED
delete slot;
return 0;
}
} //extern "C"
} // anonymous namespace
namespace Glib
{
// internal
void thread_init_impl()
{
// Make sure the exception map is initialized before creating any thread.
Glib::Error::register_init();
}
/**** Glib::Thread *********************************************************/
// static
Thread* Thread::create(const sigc::slot<void>& slot, bool joinable)
{
// Make a copy of slot on the heap
sigc::slot_base *const slot_copy = new sigc::slot<void>(slot);
GError* error = 0;
GThread *const thread = g_thread_create(
&call_thread_entry_slot, slot_copy, joinable, &error);
if(error)
{
delete slot_copy;
Glib::Error::throw_exception(error);
}
return reinterpret_cast<Thread*>(thread);
}
// static
Thread* Thread::create(const sigc::slot<void>& slot, unsigned long stack_size,
bool joinable, bool bound, ThreadPriority priority)
{
// Make a copy of slot on the heap
sigc::slot_base *const slot_copy = new sigc::slot<void>(slot);
GError* error = 0;
GThread *const thread = g_thread_create_full(
&call_thread_entry_slot, slot_copy, stack_size, joinable,
bound, (GThreadPriority) priority, &error);
if(error)
{
delete slot_copy;
Glib::Error::throw_exception(error);
}
return reinterpret_cast<Thread*>(thread);
}
// static
Thread* Thread::self()
{
return reinterpret_cast<Thread*>(g_thread_self());
}
bool Thread::joinable() const
{
return gobject_.joinable;
}
void Thread::join()
{
g_thread_join(&gobject_);
}
void Thread::set_priority(ThreadPriority priority)
{
g_thread_set_priority(&gobject_, (GThreadPriority) priority);
}
ThreadPriority Thread::get_priority() const
{
return (ThreadPriority) gobject_.priority;
}
// static
void Thread::yield()
{
g_thread_yield();
}
Thread* wrap(GThread* gobject)
{
return reinterpret_cast<Thread*>(gobject);
}
/**** Glib::StaticMutex ****************************************************/
void StaticMutex::lock()
{
g_static_mutex_lock(&gobject_);
}
bool StaticMutex::trylock()
{
return g_static_mutex_trylock(&gobject_);
}
void StaticMutex::unlock()
{
g_static_mutex_unlock(&gobject_);
}
StaticMutex::operator Mutex&()
{
// If GStaticMutex is implemented as struct (e.g. on Linux), its first struct
// member (runtime_mutex) is a GMutex pointer. If the gthread implementation
// is native (i.e. the vtable pointer passed to g_thread_init() was 0), then
// the runtime_mutex pointer is unused, and the rest of the GStaticMutex
// struct resembles the mutex data.
//
// On Win32, GStaticMutex is just a typedef to struct _GMutex*. Either way,
// the first sizeof(GMutex*) bytes of GStaticMutex always resemble a GMutex
// pointer. The gthread implementation relies on that, and we'll also do so.
GMutex*& runtime_mutex = reinterpret_cast<GMutex*&>(gobject_);
// Fortunately, it cannot hurt if we set this to the GMutex pointer returned
// by g_static_mutex_get_mutex(). Either we just overwrite it with the same
// value, or it was unused anyway. Doing that allows casting the pointer
// location to a Glib::Mutex reference (its only data member is a GMutex*).
runtime_mutex = g_static_mutex_get_mutex(&gobject_);
return reinterpret_cast<Mutex&>(runtime_mutex);
}
/**** Glib::Mutex **********************************************************/
Mutex::Mutex()
:
gobject_ (g_mutex_new())
{}
Mutex::~Mutex()
{
g_mutex_free(gobject_);
}
void Mutex::lock()
{
g_mutex_lock(gobject_);
}
bool Mutex::trylock()
{
return g_mutex_trylock(gobject_);
}
void Mutex::unlock()
{
g_mutex_unlock(gobject_);
}
/**** Glib::StaticRecMutex *************************************************/
void StaticRecMutex::lock()
{
g_static_rec_mutex_lock(&gobject_);
}
bool StaticRecMutex::trylock()
{
return g_static_rec_mutex_trylock(&gobject_);
}
void StaticRecMutex::unlock()
{
g_static_rec_mutex_unlock(&gobject_);
}
void StaticRecMutex::lock_full(unsigned int depth)
{
g_static_rec_mutex_lock_full(&gobject_, depth);
}
unsigned int StaticRecMutex::unlock_full()
{
return g_static_rec_mutex_unlock_full(&gobject_);
}
StaticRecMutex::operator RecMutex&()
{
return static_cast<RecMutex&>(*this);
}
/**** Glib::RecMutex *******************************************************/
RecMutex::RecMutex()
{
g_static_rec_mutex_init(&gobject_);
// GLib doesn't have GRecMutex, only GStaticRecMutex. Force initialization
// of the mutex now, to mimic the behaviour of a (hypothetical) GRecMutex.
g_static_mutex_get_mutex(&gobject_.mutex);
}
RecMutex::~RecMutex()
{
g_static_rec_mutex_free(&gobject_);
}
/**** Glib::StaticRWLock ***************************************************/
void StaticRWLock::reader_lock()
{
g_static_rw_lock_reader_lock(&gobject_);
}
bool StaticRWLock::reader_trylock()
{
return g_static_rw_lock_reader_trylock(&gobject_);
}
void StaticRWLock::reader_unlock()
{
g_static_rw_lock_reader_unlock(&gobject_);
}
void StaticRWLock::writer_lock()
{
g_static_rw_lock_writer_lock(&gobject_);
}
bool StaticRWLock::writer_trylock()
{
return g_static_rw_lock_writer_trylock(&gobject_);
}
void StaticRWLock::writer_unlock()
{
g_static_rw_lock_writer_unlock(&gobject_);
}
StaticRWLock::operator RWLock&()
{
return static_cast<RWLock&>(*this);
}
/**** Glib::RWLock *********************************************************/
RWLock::RWLock()
{
g_static_rw_lock_init(&gobject_);
// GLib doesn't have GRWLock, only GStaticRWLock. Force initialization
// of the mutex and the condition variables now, to mimic the behaviour
// of a (hypothetical) GRWLock.
if(g_static_mutex_get_mutex(&gobject_.mutex))
{
gobject_.read_cond = g_cond_new();
gobject_.write_cond = g_cond_new();
}
}
RWLock::~RWLock()
{
g_static_rw_lock_free(&gobject_);
}
/**** Glib::Cond ***********************************************************/
Cond::Cond()
:
gobject_ (g_cond_new())
{}
Cond::~Cond()
{
g_cond_free(gobject_);
}
void Cond::signal()
{
g_cond_signal(gobject_);
}
void Cond::broadcast()
{
g_cond_broadcast(gobject_);
}
void Cond::wait(Mutex& mutex)
{
g_cond_wait(gobject_, mutex.gobj());
}
bool Cond::timed_wait(Mutex& mutex, const Glib::TimeVal& abs_time)
{
return g_cond_timed_wait(gobject_, mutex.gobj(), const_cast<Glib::TimeVal*>(&abs_time));
}
} // namespace Glib

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,22 @@
// -*- c++ -*-
/* $Id: unicode.ccg,v 1.1 2003/01/07 16:58:42 murrayc Exp $ */
/* 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/unicode.h>

View file

@ -0,0 +1,147 @@
/* $Id: unicode.hg,v 1.2 2003/08/20 10:31:23 murrayc Exp $ */
/* 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.
*/
_DEFS(glibmm,glib)
#m4begin
_PUSH()
// m4 helper macros to generate the character-class inline functions.
m4_define(`_UNICHAR_FUNC',`dnl
inline $1 $2(gunichar uc)
{ return g_unichar_$2(uc); }
`'dnl`'')
//MSVC++ needs the != 0 to avoid an int -> bool cast warning.
m4_define(`_UNICHAR_FUNC_BOOL',`dnl
inline $1 $2(gunichar uc)
{ return (g_unichar_$2(uc) != 0); }
`'dnl`'')
m4_define(`_ASCII_FUNC',`dnl
inline $1 $2(char c)
{ return g_ascii_$2(c); }
`'dnl`'')
_POP()
#m4end
#include <glib/gmacros.h>
#include <glib/gstrfuncs.h>
#include <glib/gunicode.h>
// Not used, but we want to get rid of possible <ctype.h> macros.
#include <cctype>
#undef isalnum
#undef isalpha
#undef iscntrl
#undef isdigit
#undef isgraph
#undef islower
#undef isprint
#undef ispunct
#undef isspace
#undef isupper
#undef isxdigit
#undef istitle
#undef isdefined
#undef iswide
#undef toupper
#undef tolower
#undef totitle
namespace Glib
{
_WRAP_ENUM(UnicodeType, GUnicodeType, NO_GTYPE)
_WRAP_ENUM(UnicodeBreakType, GUnicodeBreakType, NO_GTYPE)
_WRAP_ENUM(AsciiType, GAsciiType, NO_GTYPE)
_WRAP_ENUM(NormalizeMode, GNormalizeMode, NO_GTYPE)
/** @defgroup Unicode Unicode Manipulation
* Functions operating on Unicode characters and UTF-8 strings.
* @{
*/
namespace Unicode
{
_UNICHAR_FUNC_BOOL(bool, validate)
_UNICHAR_FUNC_BOOL(bool, isalnum)
_UNICHAR_FUNC_BOOL(bool, isalpha)
_UNICHAR_FUNC_BOOL(bool, iscntrl)
_UNICHAR_FUNC_BOOL(bool, isdigit)
_UNICHAR_FUNC_BOOL(bool, isgraph)
_UNICHAR_FUNC_BOOL(bool, islower)
_UNICHAR_FUNC_BOOL(bool, isprint)
_UNICHAR_FUNC_BOOL(bool, ispunct)
_UNICHAR_FUNC_BOOL(bool, isspace)
_UNICHAR_FUNC_BOOL(bool, isupper)
_UNICHAR_FUNC_BOOL(bool, isxdigit)
_UNICHAR_FUNC_BOOL(bool, istitle)
_UNICHAR_FUNC_BOOL(bool, isdefined)
_UNICHAR_FUNC_BOOL(bool, iswide)
_UNICHAR_FUNC(gunichar, toupper)
_UNICHAR_FUNC(gunichar, tolower)
_UNICHAR_FUNC(gunichar, totitle)
_UNICHAR_FUNC(int, digit_value)
_UNICHAR_FUNC(int, xdigit_value)
inline Glib::UnicodeType type(gunichar uc)
{ return static_cast<Glib::UnicodeType>(static_cast<int>(g_unichar_type(uc))); }
inline Glib::UnicodeBreakType break_type(gunichar uc)
{ return static_cast<Glib::UnicodeBreakType>(static_cast<int>(g_unichar_break_type(uc))); }
} // namespace Unicode
namespace Ascii
{
_ASCII_FUNC(bool, isalnum)
_ASCII_FUNC(bool, isalpha)
_ASCII_FUNC(bool, iscntrl)
_ASCII_FUNC(bool, isdigit)
_ASCII_FUNC(bool, isgraph)
_ASCII_FUNC(bool, islower)
_ASCII_FUNC(bool, isprint)
_ASCII_FUNC(bool, ispunct)
_ASCII_FUNC(bool, isspace)
_ASCII_FUNC(bool, isupper)
_ASCII_FUNC(bool, isxdigit)
_ASCII_FUNC(char, tolower)
_ASCII_FUNC(char, toupper)
_ASCII_FUNC(int, digit_value)
_ASCII_FUNC(int, xdigit_value)
} // namespace Ascii
/** @} group Unicode */
} // namespace Glib

View file

@ -0,0 +1,84 @@
divert(-1)
dnl $Id: value_basictypes.cc.m4 348 2006-11-22 11:14:43Z murrayc $
dnl Glib::Value specializations for fundamental types
dnl
dnl Copyright 2002 The gtkmm Development Team
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Library General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Library General Public License for more details.
dnl
dnl You should have received a copy of the GNU Library General Public
dnl License along with this library; if not, write to the Free
dnl Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include(template.macros.m4)
dnl
dnl GLIB_VALUE_BASIC(bool, boolean)
dnl
define([GLIB_VALUE_BASIC],[dnl
LINE(]__line__[)dnl
dnl Please ignore the format stuff. I was just tired and played a little.
/**** Glib::Value<$1> translit(format([%]eval(57-len([$1]))[s],[****/]),[ ],[*])
// static
GType Value<$1>::value_type()
{
return G_TYPE_[]UPPER($2);
}
void Value<$1>::set($1 data)
{
g_value_set_$2(&gobject_, data);
}
$1 Value<$1>::get() const
{
return g_value_get_$2(&gobject_);
}
GParamSpec* Value<$1>::create_param_spec(const Glib::ustring& name) const
{
return g_param_spec_$2(
name.c_str(), 0, 0,ifelse($2,pointer,,[
ifelse($3,,,[$3, $4, ])[]g_value_get_$2(&gobject_),])
GParamFlags(G_PARAM_READABLE | G_PARAM_WRITABLE));
}
])
divert[]dnl
// -*- c++ -*-
// This is a generated file, do not edit. Generated from __file__
#include <glibmm/value.h>
namespace Glib
{
G_GNUC_EXTENSION typedef long long long_long;
G_GNUC_EXTENSION typedef unsigned long long unsigned_long_long;
GLIB_VALUE_BASIC(bool, boolean)
GLIB_VALUE_BASIC(char, char, -128, 127)
GLIB_VALUE_BASIC(unsigned char, uchar, 0, 255)
GLIB_VALUE_BASIC(int, int, G_MININT, G_MAXINT)
GLIB_VALUE_BASIC(unsigned int, uint, 0, G_MAXUINT)
GLIB_VALUE_BASIC(long, long, G_MINLONG, G_MAXLONG)
GLIB_VALUE_BASIC(unsigned long, ulong, 0, G_MAXULONG)
GLIB_VALUE_BASIC(long_long, int64, G_GINT64_CONSTANT[](0x8000000000000000), G_GINT64_CONSTANT[](0x7fffffffffffffff))
GLIB_VALUE_BASIC(unsigned_long_long, uint64, G_GINT64_CONSTANT[](0U), G_GINT64_CONSTANT[](0xffffffffffffffffU))
GLIB_VALUE_BASIC(float, float, -G_MAXFLOAT, G_MAXFLOAT)
GLIB_VALUE_BASIC(double, double, -G_MAXDOUBLE, G_MAXDOUBLE)
GLIB_VALUE_BASIC(void*, pointer)
} // namespace Glib

View file

@ -0,0 +1,83 @@
divert(-1)
dnl $Id: value_basictypes.h.m4 2 2003-01-07 16:59:16Z murrayc $
dnl Glib::Value specializations for fundamental types
dnl
dnl Copyright 2002 The gtkmm Development Team
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Library General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Library General Public License for more details.
dnl
dnl You should have received a copy of the GNU Library General Public
dnl License along with this library; if not, write to the Free
dnl Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include(template.macros.m4)
dnl
dnl GLIB_VALUE_BASIC(bool, boolean)
dnl
define([GLIB_VALUE_BASIC],[dnl
LINE(]__line__[)dnl
/**
* @ingroup glibmmValue
*/
template <>
class Value<$1> : public ValueBase
{
public:
typedef $1 CppType;
typedef g$2 CType;
static GType value_type() G_GNUC_CONST;
void set($1 data);
$1 get() const;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
GParamSpec* create_param_spec(const Glib::ustring& name) const;
#endif
};
])
divert[]dnl
// -*- c++ -*-
// This is a generated file, do not edit. Generated from __file__
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifndef _GLIBMM_VALUE_H_INCLUDE_VALUE_BASICTYPES_H
#error "glibmm/value_basictypes.h cannot be included directly"
#endif
#endif
/* Suppress warnings about `long long' when GCC is in -pedantic mode.
*/
#if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
#pragma GCC system_header
#endif
namespace Glib
{
GLIB_VALUE_BASIC(bool, boolean)
GLIB_VALUE_BASIC(char, char)
GLIB_VALUE_BASIC(unsigned char, uchar)
GLIB_VALUE_BASIC(int, int)
GLIB_VALUE_BASIC(unsigned int, uint)
GLIB_VALUE_BASIC(long, long)
GLIB_VALUE_BASIC(unsigned long, ulong)
GLIB_VALUE_BASIC(long long, int64)
GLIB_VALUE_BASIC(unsigned long long, uint64)
GLIB_VALUE_BASIC(float, float)
GLIB_VALUE_BASIC(double, double)
GLIB_VALUE_BASIC(void*, pointer)
} // namespace Glib