# Set V to `1' to echo each build command in full. The default behavior
# will keep output minimal.
-V = 0
+V = 0
SHELL = /bin/sh
DATA_TARGETS :=
EXEC_TARGETS :=
-SUBDIRS :=
+SUBDIRS :=
define include_func =
ifeq (,$$d)
else
dir := $$d/$1
endif
-sp := $$(sp).x
+sp := $$(sp).x
dirstack_$$(sp) := $$d
datstack_$$(sp) := $$(data)
exestack_$$(sp) := $$(exec)
-d := $$(dir)
-data :=
-exec :=
+d := $$(dir)
+data :=
+exec :=
include $$(dir)/rules.mk
SUBDIRS += $$d $$b
data := $$(sort $$(data) $$(appdir_$$b) $$(mandir_$$b) $$(pkgdatadir_$$b) $$(desktop_$$b))
DEPFILE := $$(DEPFILE) $$(deps)
DATA_TARGETS += $$(data)
EXEC_TARGETS += $$(exec)
-d := $$(dirstack_$$(sp))
+d := $$(dirstack_$$(sp))
data := $$(datstack_$$(sp))
exec := $$(exestack_$$(sp))
sp := $$(basename $$(sp))
targets = $(EXEC_TARGETS) $(DATA_TARGETS)
builddir = build/obj
-b = $(builddir)/$(d)
+b = $(builddir)/$(d)
this = $(d)/rules.mk
ifeq (gzip,$(manCompression))
#
$(call include,src data doc)
--include build/$(platform)/rules.mk
+-include build/arch/$(platform)/rules.mk
#
endif
# Include current directory to allow sources to include config.h.
-override CPPFLAGS += -I.
+override CPPFLAGS += -I. -DHAVE_CONFIG_H=1
TGT_CXXFLAGS = $(TGT_CFLAGS)
ARFLAGS = rc
INSTALL = install
tarname = $(TARNAME)-$(VERSION)
cmd_compile_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(CPPFLAGS) \
- $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
+ $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
cmd_compile_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) \
- $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
-cmd_link_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(CPPFLAGS) \
- $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \
- $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@
-cmd_link_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) \
- $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \
- $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@
-cmd_ar = $(AR) $(ARFLAGS) $@ $^; $(RANLIB) $@
+ $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
+cmd_link_c = $(CC) $(PKG_CFLAGS) $(TGT_CFLAGS) $(CFLAGS) $(CPPFLAGS) \
+ $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \
+ $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@
+cmd_link_cc = $(CXX) $(PKG_CXXFLAGS) $(TGT_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) \
+ $(PKG_LDFLAGS) $(TGT_LDFLAGS) $(LDFLAGS) \
+ $(TARGET_ARCH) $^ $(LOADLIBES) $(PKG_LDLIBS) $(TGT_LDLIBS) $(LDLIBS) -o $@
+cmd_ar = $(AR) $(ARFLAGS) $@ $^; $(RANLIB) $@
cmd_compile_rc = $(WINDRES) $(CPPFLAGS) $(TARGET_ARCH) $(OUTPUT_OPTION) -i $<
-cmd_sed = sed -f config.sed <$< >$@
-cmd_gzip = gzip -c $< >$@
-cmd_bzip2 = bzip2 -c $< >$@
-cmd_xxd = id=$(subst .,_,$(notdir $<)); \
- printf "\#include <stddef.h>\nsize_t\tdata_%s_size = %d;\nchar\tdata_%s[] = {\n" \
- $$id $$(wc -c <$<) $$id >$@; \
- xxd -i <$< >>$@; \
- printf ", 0x00\n};\n" >>$@
+cmd_sed = sed -f config.sed <$< >$@
+cmd_gzip = gzip -c $< >$@
+cmd_bzip2 = bzip2 -c $< >$@
+cmd_xxd = id=$(subst .,_,$(notdir $<)); \
+ printf "\#include <stddef.h>\nsize_t\tdata_%s_size = %d;\nchar\tdata_%s[] = {\n" \
+ $$id $$(wc -c <$<) $$id >$@; \
+ xxd -i <$< >>$@; \
+ printf ", 0x00\n};\n" >>$@
cmd_configure = ./configure
func_install = mkdir -p $(DESTDIR)$3 && $(INSTALL) -m $1 $2 $(DESTDIR)$3
-func_remove = rm -f $1
-func_dist = git archive HEAD --prefix='$(tarname)/' | $1 >"$(tarname).tar.$2" && \
- (md5 "$(tarname).tar.$2" 2>/dev/null || md5sum "$(tarname).tar.$2")
+func_remove = rm -f $1
+func_dist = git archive HEAD --prefix='$(tarname)/' | $1 >"$(tarname).tar.$2" && \
+ (md5 "$(tarname).tar.$2" 2>/dev/null || md5sum "$(tarname).tar.$2")
compile_c = $(call func_print,CC,$@) $(cmd_compile_c)
compile_cc = $(call func_print,CXX,$@) $(cmd_compile_cc)
compile_rc = $(call func_print,RC,$@) $(cmd_compile_rc)
link_c = $(call func_print,LINK,$@) $(cmd_link_c)
link_cc = $(call func_print,LINK,$@) $(cmd_link_cc)
-ar = $(call func_print,AR,$@) $(cmd_ar)
-sed = $(call func_print,SED,$@) $(cmd_sed)
+ar = $(call func_print,AR,$@) $(cmd_ar)
+sed = $(call func_print,SED,$@) $(cmd_sed)
gzip = $(call func_print,GZIP,$@) $(cmd_gzip)
bzip2 = $(call func_print,BZIP2,$@) $(cmd_bzip2)
-xxd = $(call func_print,XXD,$@) $(cmd_xxd)
+xxd = $(call func_print,XXD,$@) $(cmd_xxd)
configure = $(call func_print,MAKE,$@) $(cmd_configure)
dist = $(call func_print,DIST,$1) $(func_dist)
-install = $(call func_print,CP,$(DESTDIR)$(3:%/=%)/$(notdir $2)) $(func_install)
+install = $(call func_print,CP,$(DESTDIR:%/=%)$(3:%/=%)/$(notdir $2)) $(func_install)
remove = $(call func_print,RM,$1) $(func_remove)
ifeq (1,$V)
-Q =
+Q =
func_print =
else
-Q = @
+Q = @
func_print = printf "\x20\x20$1\t%s\n" $2;
endif
$(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(pkgdatadir_$d),\
$(call install,644,$f,$(dir $(f:$d%=$(pkgdatadir)%)));))
$(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(mandir_$d),\
- $(call install,644,$f,$(dir $(f:$d%=$(mandir)/man$(shell echo "$f" | sed 's/[^.]*\.\([^.]*\).*/\1/')%)));))
+ $(call install,644,$f,\
+ $(dir $(f:$d%=$(mandir)/man$(shell echo "$f" | sed 's/[^.]*\.\([^.]*\).*/\1/')%)));))
install-exec: $(EXEC_TARGETS)
$(Q)$(foreach d,$(SUBDIRS),$(foreach f,$(bindir_$d),\
# Prevent make from removing any build targets.
#
-.SECONDARY: $(clean)
+.SECONDARY: $(clean)
.PHONY: all clean distclean install install-data install-exec
.PHONY: install-desktop-entry
o Stick to the coding style of the source code files you edit. Follow
the general style of method and variable naming, as well as white
space formatting. In particular, use literal tabs with an assumed
- tabstop of 4 characters. Also, try to limit line lengths to 75
+ tabstop of 8 characters. Also, try to limit line lengths to 78
characters.
o For legal reasons, don't include other peoples' code with your patch.
The roadmap and ticket tracker are available on the website:
There are lists of goals and tasks on the website:
-Roadmap: http://www.dogcows.com/yoink/roadmap
-Ticket Tracker: http://www.dogcows.com/yoink/report/1
+Roadmap: http://www.dogcows.com/yoink/roadmap
+Ticket Tracker: http://www.dogcows.com/yoink/report/1
Other than that, the itself code is documented with stuff that needs doing:
# make -f deps.mk -j2 host=i486-mingw32 prefix=/usr/i486-mingw32
# sudo make install
#
-# A lot of temporary files and directories are downloaded or extracted to
-# the current directory, so you may want to make from a clean directory.
+# A lot of temporary files and directories are downloaded or extracted to the
+# current directory, so you may want to make from a clean directory.
#
-
host = i686-mingw32
prefix = /usr/i686-mingw32/usr
###########################################################################
-BOOST = boost_1_46_1
-BOOST_CKSUM = 7375679575f4c8db605d426fc721d506
-BOOST_EXT = .tar.bz2
+BOOST = boost_1_46_1
+BOOST_CKSUM = 7375679575f4c8db605d426fc721d506
+BOOST_EXT = .tar.bz2
BOOST_VERSION = 1.46.1
$(BOOST)$(BOOST_EXT):
###########################################################################
-SDL = SDL-1.2.14
+SDL = SDL-1.2.14
SDL_CKSUM = e52086d1b508fa0b76c52ee30b55bec4
SDL_EXT = .tar.gz
###########################################################################
-LIBOGG = libogg-1.2.2
+LIBOGG = libogg-1.2.2
LIBOGG_CKSUM = 5a9fcabc9a1b7c6f1cd75ddc78f36c56
-LIBOGG_EXT = .tar.gz
+LIBOGG_EXT = .tar.gz
$(LIBOGG)$(LIBOGG_EXT):
$(call getdist,$@,http://downloads.xiph.org/releases/ogg/$@)
###########################################################################
-LIBVORBIS = libvorbis-1.3.2
+LIBVORBIS = libvorbis-1.3.2
LIBVORBIS_CKSUM = c870b9bd5858a0ecb5275c14486d9554
LIBVORBIS_EXT = .tar.gz
###########################################################################
-OPENAL = openal-soft-1.13-bin
+OPENAL = openal-soft-1.13-bin
OPENAL_CKSUM = b545d3ebb8138cc581cd67f988638f43
-OPENAL_EXT = .zip
+OPENAL_EXT = .zip
OPENAL_VERSION = 1.13
define OPENAL_PCFILE
###########################################################################
-ZLIB = zlib-1.2.5
-ZLIB_CKSUM = c735eab2d659a96e5a594c9e8541ad63
-ZLIB_EXT = .tar.gz
+ZLIB = zlib-1.2.5
+ZLIB_CKSUM = c735eab2d659a96e5a594c9e8541ad63
+ZLIB_EXT = .tar.gz
ZLIB_VERSION = 1.2.5
define ZLIB_PCFILE
###########################################################################
-LIBPNG = libpng-1.5.2
+LIBPNG = libpng-1.5.2
LIBPNG_CKSUM = 31d448eb93a1646359a23f1b23434ab3
-LIBPNG_EXT = .tar.gz
+LIBPNG_EXT = .tar.gz
define LIBPNG_PATCH
diff -ur libpng-1.5.2.orig/configure.pc libpng-1.5.2/configure.pc
###########################################################################
-LUA = lua-5.1.4
+LUA = lua-5.1.4
LUA_CKSUM = d0870f2de55d59c1c8419f36e8fac150
LUA_EXT = .tar.gz
+
#
-# Yoink
-# Run this script to create a win32 package.
-#
-# You should typically only run this through the "portable" and "installer"
-# makes targets in the package root directory. The build system will take
-# care to pass the correct arguments.
+# Rules to create win32 packages.
#
docs = AUTHORS COPYING README TODO
libraries = libogg-0 libpng15 libvorbis-0 libvorbisfile-3 lua51 OpenAL32 SDL zlib1
-MAN2HTML = lua doc/man2html.lua
-UNIX2DOS = arch/win32/unix2dos.sh
+MAN2HTML = $${LUA:-lua} scripts/man2html.lua
+UNIX2DOS = scripts/unix2dos.sh
MAKENSIS = makensis
stagedir = $(builddir)/$(tarname)
local arguments = parseArguments(unpack(arg))
local interactive = arguments["--interactive"]
-local rules = arguments["--rules"] or "options.lua"
-local configfile = arguments["--configfile"] or "config.mk"
+local rules = arguments["--rules"] or "options.lua"
+local configfile = arguments["--configfile"] or "config.mk"
local printendmsg = arguments["--print-instructions"]
local exportHeader = arguments["--export-header"]
local exportTerms = arguments["--export-terms"]
return function(progress, caption)
if progress ~= nil
then
- if 0.0 <= progress and progress <= 1.0 then progress = progress * 100 end
+ if 0.0 <= progress and progress <= 1.0 then
+ progress = progress * 100
+ end
return updater(progress, caption)
end
print()
local function loadDialog(name, configfile)
local dialog
local result, err = pcall(function() dialog = require "dialog" end)
- if not result
- then
- printWarning(err)
- return nil
- end
+ if not result then printWarning(err) return nil end
dialog.title = string.format("%s - %s Configuration", configfile, name)
- printInfo = dialog.msgbox
- printWarning = dialog.msgbox
- printError = dialog.msgbox
- beginProcess = dialog.gauge
+ printInfo = dialog.msgbox
+ printWarning = dialog.msgbox
+ printError = dialog.msgbox
+ beginProcess = dialog.gauge
return dialog
end
---------------------------------------------------------------------------
function Option:__init(rule, lookup, objects)
- self.name = rule.name
+ self.name = rule.name
self.caption = rule.caption
- self.help = rule.help
- self.value = rule.value
- self.symbol = rule.symbol
+ self.help = rule.help
+ self.value = rule.value
+ self.symbol = rule.symbol
self.cmdline = rule.cmdline
- self.config = rule.config
- self.export = rule.export
+ self.config = rule.config
+ self.export = rule.export
self.visible = rule.visible
- self.check = rule.check
- self.temp = rule.temp
- self.before = rule.before
- self.after = rule.after
- self.lookup = lookup or {}
+ self.check = rule.check
+ self.temp = rule.temp
+ self.before = rule.before
+ self.after = rule.after
+ self.lookup = lookup or {}
self.objects = objects or {}
if type(self.check) == "function" then setfenv(self.check, self.lookup) end
if self.symbol ~= nil and not self.temp
then
fd:write(util.align(self.symbol, "= " .. tostring(self.lookup[self.symbol]), 16) .. "\n")
- --fd:write(string.format("%s\t= %s\n", self.symbol, tostring(self.lookup[self.symbol])))
end
end
function Option:writeSedLine(fd)
if self.export
then
- local value = self:toExpandedString():gsub("/", "\\/")
+ local value = self:toExpandedString():gsub("/", "\\/")
local function writeLine(key)
key = tostring(key):gsub("/", "\\/")
fd:write(string.format("s/@%s@/%s/g\n", key, value))
end
function Option:getHelpText()
- local value = self:toString()
- local help = self.help or "No help available.\n"
- local name = self.name or "Unnamed"
+ local value = self:toString()
+ local help = self.help or "No help available.\n"
+ local name = self.name or "Unnamed"
local symbol = self:getSymbol() or "None"
- local arg = self:getArg() or "None"
+ local arg = self:getArg() or "None"
local problem = self:getProblem()
if problem then problem = "\nProblem(s):\n" .. problem
function BooleanOption:writeCppLine(fd)
if self.config
then
- local value = self.lookup[self.symbol]
+ local value = self.lookup[self.symbol]
local function writeLine(key)
-- Reverse the value if key starts with a bang.
local value = value
dialog.msgbox(value.name, value:getHelpText(), {["--no-collapse"] = true})
selected = value:getMenuItem()
else
- dialog.msgbox("No Help",
- "Sorry, no help is available for this option.")
+ dialog.msgbox("No Help", "Sorry, no help is available for this option.")
end
else
running = false
options:convertDependenciesToDependants()
checkSymbols(options:getObjects())
-if dialog
-then
+if dialog then
local action = options:runMenu()
if action == "exit" or action == "error"
then
options:saveToFile(configfile)
print("configuration saved to " .. configfile)
end
-elseif options:isValid()
-then
+elseif options:isValid() then
options:saveToFile(configfile)
else
printError("Uh oh!", [[
-/*] Copyright (c) 2011, Charles McGarvey [*******************************
+/*] Copyright (c) 2011, Charles McGarvey [**********************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#define LUA_DIALOG_NAME "dialog"
#define LUA_DIALOG_VERSION "1.0"
/**
* Fork and execute a command with arguments and optionally get a file
* descriptor connected to one of the child's own file descriptors. The
- * process id of the child is returned, or -1 on error. If fd is not NULL,
- * a pipe will be created and connected to *fd. If *fd is 0, then *fd will
- * be set to a write file descriptor connected to the child's standard
- * input. If *fd is not 0, then *fd will be set to a read file descriptor
- * set connected to the specified file descriptor of the child. In either
- * case, the caller has the responsibility to close fd when it is no longer
- * needed.
+ * process id of the child is returned, or -1 on error. If fd is not NULL, a
+ * pipe will be created and connected to *fd. If *fd is 0, then *fd will be
+ * set to a write file descriptor connected to the child's standard input. If
+ * *fd is not 0, then *fd will be set to a read file descriptor set connected
+ * to the specified file descriptor of the child. In either case, the caller
+ * has the responsibility to close fd when it is no longer needed.
*/
static pid_t myexec(const char* command, char* const argv[], int* fd)
{
int p[2];
pid_t child;
- if (fd)
- {
+ if (fd) {
if (pipe(p) != 0) return -1;
parentFd = (*fd == 0);
}
- if (!(child = fork()))
- {
- if (fd)
- {
+ if (!(child = fork())) {
+ if (fd) {
close(p[parentFd]);
if (dup2(p[!parentFd], *fd) == -1) _exit(127);
}
execv(command, argv);
_exit(127);
}
- if (child == -1)
- {
+ if (child == -1) {
if (parentFd != -1)
- {
close(p[0]); close(p[1]);
- }
return -1;
}
- if (parentFd != -1)
- {
+ if (parentFd != -1) {
close(p[!parentFd]);
*fd = p[parentFd];
}
/**
- * Read from a file descriptor until EOF and push contents to the top of
- * the Lua stack. Closes the file descriptor afterward.
+ * Read from a file descriptor until EOF and push contents to the top of the
+ * Lua stack. Closes the file descriptor afterward.
*/
static void pushstream(lua_State* L, int fd)
{
char buffer[BUFSIZ];
ssize_t bytes;
- while ((bytes = read(fd, buffer, sizeof(buffer))))
- {
+ while ((bytes = read(fd, buffer, sizeof(buffer)))) {
if (bytes == -1) break;
luaL_addlstring(&B, buffer, bytes);
}
static void writelstring(int fd, const char* str, size_t len)
{
ssize_t bytes;
- while ((bytes = write(fd, str, len)))
- {
+ while ((bytes = write(fd, str, len))) {
if (bytes == -1) break;
str += bytes;
len -= bytes;
int i; for (i = 0; argv[i]; ++i);
va_start(ap, argv);
const char* arg = va_arg(ap, const char*);
- while (arg)
- {
+ while (arg) {
argv[i++] = arg;
arg = va_arg(ap, const char*);
}
lua_getfield(L, -1, "command");
lua_getfield(L, -2, "title");
addstrings(argv, lua_tostring(L, -2), NULL);
- if (lua_isstring(L, -1))
- {
+ if (lua_isstring(L, -1)) {
addstrings(argv, "--backtitle", lua_tostring(L, -1), NULL);
}
lua_pop(L, 3);
{
if (!lua_istable(L, n)) return 0;
lua_pushnil(L);
- while (lua_next(L, n))
- {
+ while (lua_next(L, n)) {
addstrings(argv, lua_tostring(L, -2), NULL);
if (lua_isstring(L, -1)) addstrings(argv, lua_tostring(L, -1), NULL);
lua_pop(L, 1);
if (searchstrings(argv, "--item-help") != -1) fields = 3;
if (!lua_istable(L, 3)) luaL_argerror(L, 3, "menu items");
- int i; for (i = 1;; ++i)
- {
+ int i; for (i = 1;; ++i) {
lua_pushinteger(L, i);
lua_gettable(L, 3);
- if (lua_isnil(L, -1))
- {
+ if (lua_isnil(L, -1)) {
lua_pop(L, 1);
break;
}
- else if (lua_istable(L, -1))
- {
+ else if (lua_istable(L, -1)) {
int subtable = lua_gettop(L);
lua_pushnil(L);
- int j; for (j = 0; j < fields; ++j)
- {
+ int j; for (j = 0; j < fields; ++j) {
if (!lua_next(L, subtable)) luaL_argerror(L, 3, "not enough fields");
addstrings(argv, lua_tostring(L, -1), NULL);
lua_pop(L, 1);
}
lua_pop(L, 1);
}
- else
- {
+ else {
if (fields == 2) addstrings(argv, "", "", NULL);
else addstrings(argv, "", "", "", NULL);
}
{
lua_getfield(L, LUA_REGISTRYINDEX, "dialog_gauge_pid");
lua_getfield(L, LUA_REGISTRYINDEX, "dialog_gauge_fd");
- if (!lua_isnumber(L, -2) || !lua_isnumber(L, -1))
- {
+ if (!lua_isnumber(L, -2) || !lua_isnumber(L, -1)) {
lua_pop(L, 2);
return;
}
*/
static int updategauge(lua_State* L)
{
- if (!lua_isnumber(L, 1))
- {
+ if (!lua_isnumber(L, 1)) {
closegauge(L);
return 0;
}
if (0.0 <= percent && percent <= 1.0) percent *= 100.0;
lua_pushinteger(L, (lua_Integer)percent);
lua_replace(L, 1);
- if (lua_isstring(L, 2))
- {
+ if (lua_isstring(L, 2)) {
writestring(fd, "XXX");
tostream(L, 1, fd);
tostream(L, 2, fd);
writestring(fd, "XXX");
}
- else
- {
+ else {
tostream(L, 1, fd);
}
return 0;
LUALIB_API int luaopen_dialog(lua_State* L)
{
const struct luaL_Reg dialog_funcs[] = {
- {"gauge", dialog_gauge},
+ {"gauge", dialog_gauge},
{"inputbox", dialog_inputbox},
- {"menu", dialog_menu},
- {"msgbox", dialog_msgbox},
- {"yesno", dialog_yesno},
+ {"menu", dialog_menu},
+ {"msgbox", dialog_msgbox},
+ {"yesno", dialog_yesno},
{NULL, NULL}
};
luaL_register(L, LUA_DIALOG_NAME, dialog_funcs);
const char* names[] = {getenv("DIALOG"), "dialog", "cdialog"};
- int i; for (i = 0; i < 3; ++i)
- {
- if (names[i])
- {
+ int i; for (i = 0; i < 3; ++i) {
+ if (names[i]) {
char* path = strdup(getenv("PATH"));
char* token; char** paths = &path;
- while ((token = strsep(paths, ":")))
- {
+ while ((token = strsep(paths, ":"))) {
luaL_Buffer B;
luaL_buffinit(L, &B);
luaL_addstring(&B, token);
luaL_addstring(&B, "/");
luaL_addstring(&B, names[i]);
luaL_pushresult(&B);
- if (access(lua_tostring(L, -1), X_OK) == 0)
- {
+ if (access(lua_tostring(L, -1), X_OK) == 0) {
lua_setfield(L, -2, "command");
goto break2;
}
free(path);
}
}
- luaL_error(L, "cannot find dialog executable in the path; set DIALOG");
+ luaL_error(L, "cannot find dialog executable in the path; set DIALOG");
break2:
[ -f build/config.lua ] || die 1 <<"END"
You must first `cd' to the project directory root where the Makefile is.
-There is no support for out-of-tree builds.
+There is no support for out-of-source-tree builds.
END
LUA=${LUA:-lua}
export PATH="./build:$PATH"
exec "$LUA" build/config.lua "$@" -L./build
-# vi:ts=4
-
#
pkgdatadir_$d := $(shell find $d -name "*.ac" \
- -o -name "*.lua" \
- -o -name "*.gz" \
- -o -name "*.ogg" \
- -o -name "*.png") $d/yoinkrc
+ -o -name "*.lua" \
+ -o -name "*.gz" \
+ -o -name "*.ogg" \
+ -o -name "*.png") $d/yoinkrc
# Install resource files to pkgdatadir.
desktop_$b := $b/yoink.desktop # Install desktop entry file.
do
local mysound = yoink.sound("Explosion")
- --local mysound = yoink.sound()
- --mysound:sample("Explosion")
+ mysound = yoink.sound()
+ mysound:sample("Pop")
local count = 0
function Event.Think()
if count % 300 == 0 then
- --mysound:play()
+ mysound:play()
+ LogDebug("Hello world!")
end
count = count + 1
end
.It
Stick to the coding style of the source code files you edit. Follow the
general style of method and variable naming, as well as white space
-formatting. In particular, use literal tabs with an assumed tabstop of 4
+formatting. In particular, use literal tabs with an assumed tabstop of 8
characters. Also, try to limit line lengths to 75 characters.
.It
For legal reasons, don't include other peoples' code with your patch. You
check = function(value)
if value == ""
then
- CC = "gcc"
- CXX = "g++"
- AR = "ar"
+ CC = "gcc"
+ CXX = "g++"
+ AR = "ar"
RANLIB = "ranlib"
WINDRES = "windres"
else
- CC = value .. "-gcc"
- CXX = value .. "-g++"
- AR = value .. "-ar"
+ CC = value .. "-gcc"
+ CXX = value .. "-g++"
+ AR = value .. "-ar"
RANLIB = value .. "-ranlib"
WINDRES = value .. "-windres"
end
check = function(value)
if value
then
- PKG_CFLAGS = PKG_CFLAGS:setFlag("-pg")
- PKG_LDFLAGS = PKG_LDFLAGS:setFlag("-pg")
+ PKG_CFLAGS = PKG_CFLAGS:setFlag("-pg")
+ PKG_LDFLAGS = PKG_LDFLAGS:setFlag("-pg")
else
- PKG_CFLAGS = PKG_CFLAGS:unsetFlag("-pg")
- PKG_LDFLAGS = PKG_LDFLAGS:unsetFlag("-pg")
+ PKG_CFLAGS = PKG_CFLAGS:unsetFlag("-pg")
+ PKG_LDFLAGS = PKG_LDFLAGS:unsetFlag("-pg")
end
return value
end
If in doubt, say No.
]],
check = function(value)
- if value
- then
+ if value then
CFLAGS = CFLAGS:setFlag("-Wall", "-g")
- CFLAGS = CFLAGS:replaceFlag("%-O%d?", "-O0")
end
return value
end
}
}
-
--- vi:ft=lua
-
-----
function die(...) print("die:", ...); os.exit(1) end
-function isReadable(file) return os.execute("test -r "..file) == 0 end
+function readable(file) return os.execute("test -r "..file) == 0 end
arg.hideEmail = false
arg.output = "yoink.html"
arg.input = "yoink.6"
-if not isReadable(arg.input) then arg.input = "build/doc/yoink.6" end
+if not readable(arg.input) then arg.input = "build/doc/yoink.6" end
do
local t = {
showhelp(); os.exit(1)
end
skip = t[v](args, i)
- if tonumber(skip) then skip = skip + 1 else skip = 1 end
+ if tonumber(skip) then
+ skip = skip + 1
+ else
+ skip = 1
+ end
end
skip = skip - 1
end
parseArgs(arg)
filters = {
- function(t) -- 1. Edit page title
+ function(t) -- 1. Edit page title
return t:gsub("(<title>).*(</title>)", "%1Yoink Manual%2")
end,
- function(t) -- 2. Insert footer before </body>
+ function(t) -- 2. Insert footer before </body>
return t:gsub("</body>", [[
<p style="font-size: 9px; text-align: center;">
This manual page was generated on ]]..os.date("%d %b %Y")..[[.
# An implementation of unix2dos using sed.
#
-if [ -f "$1" ];
+if [ -f "$1" ]
then
TMPFILE="$1.$$"
sed 's/\r*$/\r/' "$1" >$TMPFILE
- if [ ! "$2" ];
+ if [ ! "$2" ]
then
mv -f "$TMPFILE" "$1"
else
rm -f "$TMPFILE"
else
echo "`basename $0` infile [outfile]"
- echo " convert a file from unix to dos file format"
+ echo " convert a text file from unix to dos line-endings"
exit 1
fi
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <map>
#include <stdexcept>
/**
- * The collection of nested animation classes. The animation
- * implementation consists of an impl class which is allocated and
- * initialized with the interface object. This class contains the specific
- * fields which are required to run a single instance of an animation. The
- * sequence data is loaded in a different class which can be shared amongst
- * multiple animation implementation instances.
+ * The collection of nested animation classes. The animation implementation
+ * consists of an impl class which is allocated and initialized with the
+ * interface object. This class contains the specific fields which are
+ * required to run a single instance of an animation. The sequence data is
+ * loaded in a different class which can be shared amongst multiple animation
+ * implementation instances.
*/
-
class Animation::impl
{
public:
/**
* Contains "global" animation data for the various animations which
- * get loaded. This is a mippleton, so it will be shared amongst any
+ * get loaded. This is a manager, so it will be shared amongst any
* animation which wants to use these loaded sequences.
*/
-
class Data : public moof::manager<Data>
{
public:
/**
- * A frame of an animation sequence. A frame is merely an index
- * which presumably represents a "slide" or tile which should be
- * displayed, and the duration that is how long the slide will be
- * shown.
+ * A frame of an animation sequence. A frame is merely an
+ * index which presumably represents a "slide" or tile which
+ * should be displayed, and the duration that is how long the
+ * slide will be shown.
*/
-
class Frame
{
public:
- unsigned mIndex; ///< Frame index.
- moof::scalar mDuration; ///< Frame duration.
+ unsigned mIndex; ///< Frame index.
+ moof::scalar mDuration; ///< Frame duration.
/**
- * Construction is initialization. The frame data is loaded
- * from a frame map which is probably loaded within an
- * animation file.
+ * Construction is initialization. The frame data is
+ * loaded from a frame map which is probably loaded
+ * within an animation file.
*/
-
Frame(const moof::script::slot& table) :
mIndex(0),
mDuration(1.0)
}
};
-
/**
- * A sequence is just a few attributes and a list of frames in the
- * order that they should be played.
+ * A sequence is just a few attributes and a list of frames in
+ * the order that they should be played.
*/
-
class Sequence
{
public:
std::vector<Frame> mFrames; ///< List of frames.
- moof::scalar mDelay; ///< Scale frame durations.
- bool mLoop; ///< Does the sequence repeat?
- std::string mNext; ///< Next sequence name.
+ moof::scalar mDelay; ///< Scale frame durations.
+ bool mLoop; ///< Does the sequence repeat?
+ std::string mNext; ///< Next sequence name.
/**
- * Construction is initialization. The constructor loads
- * sequence data from the sequence map, presumably loaded from
- * an animation file. The rest of the loading takes place in
- * the frame's constructor which loads each individual frame.
+ * Construction is initialization. The constructor
+ * loads sequence data from the sequence map,
+ * presumably loaded from an animation file. The rest
+ * of the loading takes place in the frame's
+ * constructor which loads each individual frame.
*/
-
Sequence(const moof::script::slot& table) :
mDelay(0.0),
mLoop(true)
// TODO - sequence class/type not yet implemented
moof::script::slot frameTable = table.push_field("frames");
- if (frameTable.is_table())
- {
+ if (frameTable.is_table()) {
int max = frameTable.length();
- for (int index = 1; index <= max; ++index)
- {
+ for (int index = 1; index <= max; ++index) {
moof::script::slot top = frameTable.push_field(index);
if (top.is_table())
- {
mFrames.push_back(Frame(top));
- }
else
- {
moof::log_warning << "invalid frame at index "
<< index << std::endl;
- }
}
}
frameTable.remove();
}
};
-
/**
* Starts loading a file with animation data. Such a file is
* formatted as a map of named sequences. The sequence
* constructor loads each individual sequence.
*/
-
void init(const std::string& name)
{
moof::script script;
moof::log::import(script);
importAnimationBindings(script);
- if (script.do_file(path) != moof::script::success)
- {
+ if (script.do_file(path) != moof::script::success) {
std::string str;
script[-1].get(str);
moof::log_warning(str);
return 0;
}
-
void importAnimationBindings(moof::script& script)
{
script.import_function("DefineSequence",
- boost::bind(&Data::defineSequence,
- this, _1));
+ boost::bind(&Data::defineSequence, this, _1));
script.globals().set_field("ATTACK", 1);
script.globals().set_field("CHARGE", 2);
script.globals().set_field("STAND", 7);
}
-
std::map<std::string,Sequence> mSequences; ///< List of sequences.
};
-
/**
* Construction is intialization.
*/
-
impl(const std::string& name) :
mData(Data::instance(name)),
mCurrentSequence(0),
mTimeAccum(0),
mFrameDuration(0) {}
-
/**
* Sets up the animation classes to "play" a named sequence. If
* another sequence was active, it will be replaced. Future updates
* will progress the new sequence.
*/
-
void startSequence(const std::string& name)
{
std::map<std::string,Data::Sequence>::iterator it;
it = mData->mSequences.find(name);
- if (it != mData->mSequences.end())
- {
+ if (it != mData->mSequences.end()) {
mCurrentSequence = &(*it).second;
mFrameCounter = 0;
mFrameIndex = mCurrentSequence->mFrames[0].mIndex;
mTimeAccum = 0.0;
mFrameDuration = mCurrentSequence->mDelay *
- mCurrentSequence->mFrames[0].mDuration;
+ mCurrentSequence->mFrames[0].mDuration;
}
}
/**
* Updates or progresses the animation sequence. If the time interval
- * surpasses the duration of the current frame, a new frame becomes the
- * current frame. If the last frame of a sequence expires, the active
- * sequence will switch automatically to the designated "next"
+ * surpasses the duration of the current frame, a new frame becomes
+ * the current frame. If the last frame of a sequence expires, the
+ * active sequence will switch automatically to the designated "next"
* sequence, or if none is specified but the sequence is set to loop,
* the first frame of the sequence will become the current frame, and
* the animation essentially starts over again.
*/
-
void update(moof::scalar t, moof::scalar dt)
{
if (!mCurrentSequence) return;
mTimeAccum += dt;
- if (mTimeAccum >= mFrameDuration)
- {
- if (++mFrameCounter >= mCurrentSequence->mFrames.size())
- {
- if (!mCurrentSequence->mNext.empty())
- {
+ if (mTimeAccum >= mFrameDuration) {
+ if (++mFrameCounter >= mCurrentSequence->mFrames.size()) {
+ if (!mCurrentSequence->mNext.empty()) {
startSequence(mCurrentSequence->mNext);
}
- else if (mCurrentSequence->mLoop)
- {
+ else if (mCurrentSequence->mLoop) {
mFrameCounter = 0;
}
- else
- {
+ else {
mFrameCounter--;
mCurrentSequence = 0;
}
}
}
- boost::shared_ptr<Data> mData; ///< Internal data.
+ boost::shared_ptr<Data> mData; ///< Internal data.
- Data::Sequence* mCurrentSequence; ///< Active sequence.
- unsigned mFrameCounter; ///< Current frame.
- unsigned mFrameIndex; ///< Index of current frame.
- moof::scalar mTimeAccum; ///< Time accumulation.
- moof::scalar mFrameDuration; ///< Scaled frame duration.
+ Data::Sequence* mCurrentSequence; ///< Active sequence.
+ unsigned mFrameCounter; ///< Current frame.
+ unsigned mFrameIndex; ///< Index of current frame.
+ moof::scalar mTimeAccum; ///< Time accumulation.
+ moof::scalar mFrameDuration; ///< Scaled frame duration.
};
-
Animation::Animation(const std::string& name) :
// pass through
impl_(new Animation::impl(name)) {}
-
void Animation::startSequence(const std::string& name)
{
// pass through
impl_->update(t, dt);
}
-
/**
* Gets the index for the current frame. This is presumably called by some
* drawing code which will draw the correct current frame.
*/
-
unsigned Animation::getFrame() const
{
return impl_->mFrameIndex;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _ANIMATION_HH_
#define _ANIMATION_HH_
* is determined. This class is generic enough that a frame can mean just
* about anything to whatever drawing context is used to render the frame.
*/
-
class Animation
{
public:
return AnimationP(new Animation(name));
}
-
void startSequence(const std::string& name);
void update(moof::scalar t, moof::scalar dt);
unsigned getFrame() const;
-
private:
class impl;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <iostream>
moof::vector2 location;
};
+
class ResistanceForce
{
public:
prev_state_ = state_;
}
-
void Character::update(moof::scalar t, moof::scalar dt)
{
moof::rigid_body2::update(t, dt); // update physics
tilemap.tile(frame);
}
-
void Character::draw(moof::scalar alpha) const
{
moof::state2 state = moof::rigid_body2::state(alpha);
tilemap.draw(coords);
}
-
/*int Character::getOctant(const moof::Aabb<3>& aabb) const
{
int octantNum = -1;
}
*/
-
void Character::addImpulse(moof::vector2 impulse)
{
state_.momentum += impulse;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _CHARACTER_HH_
#define _CHARACTER_HH_
class Character;
typedef boost::shared_ptr<Character> CharacterP;
-
/**
* Parent class of animate objects with "personalities." This basically
* includes the heroine herself and the bad guys.
*/
-
class Character : public moof::rigid_body2
{
public:
//virtual int getOctant(const moof::Aabb<3>& aabb) const;
moof::sprite tilemap;
- Animation animation;
+ Animation animation;
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _GAMESTATE_HH_
#define _GAMESTATE_HH_
struct GameState
{
- moof::script script;
+ moof::script script;
std::vector<std::string> sceneList;
- HeroineP heroine;
- SceneP scene;
+ HeroineP heroine;
+ SceneP scene;
- moof::lerp_scalar interp;
+ moof::lerp_scalar interp;
- moof::camera camera;
+ moof::camera camera;
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <moof/log.hh>
#include <moof/sound.hh>
#include "Heroine.hh"
+
Heroine::Heroine() :
Character("Heroine") {}
-
void Heroine::update(moof::scalar t, moof::scalar dt)
{
Character::update(t, dt);
- moof::vector3 at(0.0, 0.0, 0.0);
- const moof::vector3 up(0.0, 1.0, 0.0);
+ moof::vector3 at(0.0, 0.0, 0.0);
+ const moof::vector3 up(0.0, 1.0, 0.0);
if (state_.velocity[0] < 0.0) at[0] = -1.0;
- else at[0] = 1.0;
+ else at[0] = 1.0;
moof::sound::listener_position(moof::promote(state_.position));
moof::sound::listener_velocity(moof::promote(state_.velocity));
moof::sound::listener_orientation(at, up);
}
-
bool Heroine::handle_event(const moof::event& event)
{
moof::scalar force = 40.0;
switch (event.type)
{
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_a)
- {
- state_.force += moof::vector2(-force, 0.0);
- return true;
- }
- else if (event.key.keysym.sym == SDLK_d)
- {
- state_.force += moof::vector2(force, 0.0);
- return true;
- }
- else if (event.key.keysym.sym == SDLK_s)
- {
- state_.force += moof::vector2(0.0, -force);
- return true;
- }
- else if (event.key.keysym.sym == SDLK_w)
- {
- state_.force += moof::vector2(0.0, force);
- return true;
- }
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_a)
+ {
+ state_.force += moof::vector2(-force, 0.0);
+ return true;
+ }
+ else if (event.key.keysym.sym == SDLK_d)
+ {
+ state_.force += moof::vector2(force, 0.0);
+ return true;
+ }
+ else if (event.key.keysym.sym == SDLK_s)
+ {
+ state_.force += moof::vector2(0.0, -force);
+ return true;
+ }
+ else if (event.key.keysym.sym == SDLK_w)
+ {
+ state_.force += moof::vector2(0.0, force);
+ return true;
+ }
+ break;
- case SDL_KEYUP:
- if (event.key.keysym.sym == SDLK_a)
- {
- state_.force += moof::vector2(force, 0.0);
- return true;
- }
- else if (event.key.keysym.sym == SDLK_d)
- {
- state_.force += moof::vector2(-force, 0.0);
- return true;
- }
- else if (event.key.keysym.sym == SDLK_s)
- {
- state_.force += moof::vector2(0.0, force);
- return true;
- }
- else if (event.key.keysym.sym == SDLK_w)
- {
- state_.force += moof::vector2(0.0, -force);
- return true;
- }
+ case SDL_KEYUP:
+ if (event.key.keysym.sym == SDLK_a)
+ {
+ state_.force += moof::vector2(force, 0.0);
+ return true;
+ }
+ else if (event.key.keysym.sym == SDLK_d)
+ {
+ state_.force += moof::vector2(-force, 0.0);
+ return true;
+ }
+ else if (event.key.keysym.sym == SDLK_s)
+ {
+ state_.force += moof::vector2(0.0, force);
+ return true;
+ }
+ else if (event.key.keysym.sym == SDLK_w)
+ {
+ state_.force += moof::vector2(0.0, -force);
+ return true;
+ }
+ break;
}
return false;
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _HEROINE_HH_
#define _HEROINE_HH_
class Heroine;
typedef boost::shared_ptr<Heroine> HeroineP;
-
/**
* The protagonist.
*/
-
class Heroine : public Character
{
public:
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <moof/aabb.hh>
#include <moof/log.hh>
void ProgressBar::draw(moof::scalar alpha) const
{
- if (moof::is_equal(mProgress, 0.0))
- {
- // don't draw anything if the progress is 0%
- return;
- }
+ if (moof::is_equal(mProgress, 0.0)) return;
+ // don't draw anything if the progress is 0%
glColor4f(1.0f, 1.0f, 1.0f, 0.85f);
mTilemap.bind();
resize(video->width(), video->height());
}
-
void Hud::resize(int width, int height)
{
moof::matrix_orthographic_RH(mProjection, SCALAR(0.0),
- moof::scalar(width), SCALAR(0.0),
- moof::scalar(height),
- SCALAR(1.0), SCALAR(-1.0), moof::z_clip_neg_one);
+ moof::scalar(width), SCALAR(0.0),
+ moof::scalar(height), SCALAR(1.0),
+ SCALAR(-1.0), moof::z_clip_neg_one);
// position the two progress bars at the top-left of the screen
mBar1.resize(moof::rectangle(20, height - 51, 0.7 * width, height - 3));
setBar2Progress(0.0);
}
-
void Hud::update(moof::scalar t, moof::scalar dt)
{
state_.interp.update(t, dt);
{
switch (event.type)
{
- case SDL_KEYUP:
- if (event.key.keysym.sym == SDLK_h)
- {
- // don't want the hud anymore
- //parent().remove_child(this);
-
- moof::log_warning("okay bye bye hud");
- return true;
- }
- break;
-
- case SDL_VIDEORESIZE:
- resize(event.resize.w, event.resize.h);
- break;
+ case SDL_KEYUP:
+ if (event.key.keysym.sym == SDLK_h)
+ {
+ // don't want the hud anymore
+ //parent().remove_child(this);
+
+ moof::log_warning("okay bye bye hud");
+ return true;
+ }
+ break;
+
+ case SDL_VIDEORESIZE:
+ resize(event.resize.w, event.resize.h);
+ break;
}
return false;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _HUD_HH_
#define _HUD_HH_
#include "GameState.hh"
+// forward declarations
class rectangle;
// TODO this stuff is still just hacked up
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
+#if HAVE_CONFIG_H
#include "config.h"
+#endif
-#include <cstdlib> // atexit
+#include <cstdlib> // atexit
#include <exception>
#include <functional>
#include <iostream>
#include <string>
-#if PLATFORM_WIN32
-inline int isatty(int dummy) { return 0; }
-#else
+#if PLATFORM_POSIX
#include <termios.h>
+#else
+inline int isatty(int dummy) { return 0; }
#endif
#include <stlplus/portability/file_system.hpp>
#endif
}
-
void Main::update(moof::scalar t, moof::scalar dt)
{
yoink.update(t, dt);
switch (event.type)
{
- case SDL_KEYUP:
-
- if (event.key.keysym.sym == SDLK_f)
- {
- moof::video::current()->toggle_fullscreen();
- }
- else if (event.key.keysym.sym == SDLK_l)
- {
- moof::video::current()->toggle_cursor_captured();
- moof::video::current()->toggle_cursor_visible();
- }
- else if (event.key.keysym.sym == SDLK_ESCAPE)
- {
- stop();
- }
- break;
-
- case SDL_VIDEORESIZE:
-
- glViewport(0, 0, event.resize.w, event.resize.h);
- break;
-
- case SDL_QUIT:
-
+ case SDL_KEYUP:
+ if (event.key.keysym.sym == SDLK_f)
+ {
+ moof::video::current()->toggle_fullscreen();
+ }
+ else if (event.key.keysym.sym == SDLK_l)
+ {
+ moof::video::current()->toggle_cursor_captured();
+ moof::video::current()->toggle_cursor_visible();
+ }
+ else if (event.key.keysym.sym == SDLK_ESCAPE)
+ {
stop();
+ }
+ break;
+
+ case SDL_VIDEORESIZE:
+ glViewport(0, 0, event.resize.w, event.resize.h);
+ break;
+
+ case SDL_QUIT:
+ stop();
}
}
-
std::string Main::search_paths()
{
// Add search paths; they should be searched in this order:
return path;
}
-
void Main::setup_opengl()
{
glEnable(GL_TEXTURE_2D);
glLightfv(GL_LIGHT0, GL_SPECULAR, spec);
}
-
void Main::print_usage()
{
std::cout << "Usage: "
- << PACKAGE" [-h|--help] [-i|--info] [OPTION=VALUE]..."
- << std::endl
- << "The alien-smashing action game." << std::endl
- << std::endl
- << "Options:" << std::endl
- << " -h, --help" << std::endl
- << " show this help and exit" << std::endl
- << " -i, --info" << std::endl
- << " show version and build information" << std::endl
- << " detail=1|2|3" << std::endl
- << " the level of detail of game scenes" << std::endl
- << " fullscreen=true|false" << std::endl
- << " if true, uses the entire display" << std::endl
- << " framerate=num" << std::endl
- << " number of frames to draw per second" << std::endl
- << std::endl
- << "See documentation for more options." << std::endl;
+ << PACKAGE" [-h|--help] [-i|--info] [OPTION=VALUE]..."
+ << std::endl
+ << "The alien-smashing action game." << std::endl
+ << std::endl
+ << "Options:" << std::endl
+ << " -h, --help" << std::endl
+ << " show this help and exit" << std::endl
+ << " -i, --info" << std::endl
+ << " show version and build information" << std::endl
+ << " detail=1|2|3" << std::endl
+ << " the level of detail of game scenes" << std::endl
+ << " fullscreen=true|false" << std::endl
+ << " if true, uses the entire display" << std::endl
+ << " framerate=num" << std::endl
+ << " number of frames to draw per second" << std::endl
+ << std::endl
+ << "See documentation for more options." << std::endl;
}
void Main::print_info(int argc, char* argv[])
#endif
}
-void Main::print_option(const std::string& option, bool enabled)
-{
- if (isatty(1) == 1)
- {
- if (enabled) std::cout << "\033[1;94m";
- else std::cout << "\033[1m";
- }
- if (!enabled) std::cout << "-";
- std::cout << option;
- if (isatty(1) == 1) std::cout << "\033[0m";
- std::cout << " ";
-}
-
void hello()
{
if (isatty(1) == 1) std::cout << "\033[94m";
std::cout << std::endl << PACKAGE_STRING << std::endl
- << "Compiled " << __TIME__ " " __DATE__ << std::endl
- << "Send patches and bug reports to <"
- PACKAGE_BUGREPORT << ">." << std::endl << moof::log::endl;
+ << "Compiled " << __TIME__" "__DATE__ << std::endl
+ << "Send patches and bug reports to <"PACKAGE_BUGREPORT">."
+ << std::endl << moof::log::endl;
}
void goodbye()
catch (const std::exception& e)
{
moof::modal_dialog dialog(moof::modal_dialog::error,
- PACKAGE_STRING, "unhandled exception",
- e.what());
+ PACKAGE_STRING, "unhandled exception",
+ e.what());
dialog.run();
}
catch (const char* e)
{
moof::modal_dialog dialog(moof::modal_dialog::error,
- PACKAGE_STRING, "unhandled exception",
- e);
+ PACKAGE_STRING, "unhandled exception", e);
dialog.run();
}
-
return 1;
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MAIN_HH_
#define _MAIN_HH_
{
public:
- Main(moof::settings& settings);
+ explicit Main(moof::settings& settings);
void update(moof::scalar t, moof::scalar dt);
void draw(moof::scalar alpha) const;
*/
static void setup_opengl();
- static void print_option(const std::string& option, bool enabled);
-
moof::dispatcher::handle video_reloaded_;
moof::timer hotload_timer_;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <map>
NONE = 0,
LEFT = 1,
RIGHT = 2,
- TOP = 3
+ TOP = 3
};
Quad(const moof::vector3* vertices[4],
- const moof::image_handle& texture,
- int tileIndex) :
+ const moof::image_handle& texture,
+ int tileIndex) :
mTilemap(texture, tileIndex),
mBlending(false),
mFog(false),
moof::sprite mTilemap;
- bool mBlending;
- bool mFog;
- Surface mSurface;
+ bool mBlending;
+ bool mFog;
+ Surface mSurface;
};
moof::image_handle mTexture;
std::list< boost::shared_ptr<impl::Quad> > mObjects;
- std::list<moof::line2> mLines;
+ std::list<moof::line2> mLines;
- moof::aabb<3> mBounds;
+ moof::aabb<3> mBounds;
enum AXIS
int rotate(moof::script& script)
{
- size_t index = 0;
+ size_t index = 0;
moof::scalar value;
script[1].require_number().get(index);
script[2].require_number().get(value);
- moof::matrix_rotate_about_world_axis(mTransform, index,
- moof::rad(value));
+ moof::matrix_rotate_about_world_axis(mTransform, index, moof::rad(value));
return 0;
}
}
}
- Quad::Surface surface = Quad::NONE;
+ Quad::Surface surface = Quad::NONE;
table.get(surface, "surface");
if (surface != Quad::NONE)
mLines.push_back(moof::line<2>(bl, tr));
}
-
return 0;
}
moof::script::slot param = script[1];
moof::script::slot top = script[-1];
- int index = 0;
- int width = 1;
+ int index = 0;
+ int width = 1;
bool blending = false;
bool fog = false;
bool Scene::castRay(const moof::ray<2>& ray,
- std::list<moof::ray<2>::contact>& hits) const
+ std::list<moof::ray<2>::contact>& hits) const
{
std::list< moof::line<2> >& lines = impl_->mLines;
std::list< moof::line<2> >::const_iterator it;
return false;
}
-
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _SCENE_HH_
#define _SCENE_HH_
#include <moof/script.hh>
-class Character;
-
-
+// forward declarations
namespace moof {
class settings;
}
+class Character;
class Scene;
typedef boost::shared_ptr<Scene> SceneP;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <iostream>
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _TILEMAPFONT_HH_
#define _TILEMAPFONT_HH_
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <algorithm>
#include <cstdarg>
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _TYPESETTER_HH_
#define _TYPESETTER_HH_
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include "aabb.hh"
#include "script.hh"
-
namespace moof {
-
void import_aabb_class(script& script)
{
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_AABB_HH_
#define _MOOF_AABB_HH_
namespace moof {
+// forward declarations
class script;
-
template <int D = 3>
struct aabb : public cullable, public drawable, public shape<D>
{
vector min;
vector max;
-
aabb() {}
aabb(const vector& a, const vector& b)
init(a, b);
}
-
void init(const vector2& a, const vector2& b)
{
if (a[0] < b[0])
}
}
-
vector center() const
{
return (min + max) / 2.0;
}
-
plane xy_plane() const
{
plane plane;
return plane;
}
-
void get_corners(vector2 corners[4]) const
{
corners[0][0] = min[0]; corners[0][1] = min[1];
corners[7][2] = min[2];
}
-
void enclose_vertices(const vector vertices[], unsigned count)
{
min.zero();
max.zero();
-
for (unsigned i = 1; i < count; ++i)
{
min.minimize(vertices[i]);
}
}
-
void draw(scalar alpha = 0.0) const
{
glRect(min[0], min[1], max[0], max[1]);
template <>
inline void aabb<3>::draw(scalar alpha) const
{
- scalar vertices[] = {min[0], min[1], min[2],
- min[0], max[1], min[2],
- max[0], max[1], min[2],
- max[0], min[1], min[2],
- min[0], max[1], max[2],
- min[0], min[1], max[2],
- max[0], min[1], max[2],
- max[0], max[1], max[2]};
-
- GLubyte indices[] = {0, 1, 2, 3,
- 1, 2, 7, 4,
- 3, 0, 5, 6,
- 2, 3, 6, 7,
- 5, 0, 1, 4,
- 4, 5, 6, 7};
+ scalar vertices[] = {
+ min[0], min[1], min[2],
+ min[0], max[1], min[2],
+ max[0], max[1], min[2],
+ max[0], min[1], min[2],
+ min[0], max[1], max[2],
+ min[0], min[1], max[2],
+ max[0], min[1], max[2],
+ max[0], max[1], max[2]
+ };
+
+ GLubyte indices[] = {
+ 0, 1, 2, 3,
+ 1, 2, 7, 4,
+ 3, 0, 5, 6,
+ 2, 3, 6, 7,
+ 5, 0, 1, 4,
+ 4, 5, 6, 7
+ };
glEnableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
image::reset_binding();
- glDrawElements(GL_QUADS, sizeof(indices), GL_UNSIGNED_BYTE,
- indices);
+ glDrawElements(GL_QUADS, sizeof(indices), GL_UNSIGNED_BYTE, indices);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//glDisableClientState(GL_VERTEX_ARRAY);
return frustum.contains(*this);
}
-
typedef aabb<2> aabb2;
typedef aabb2 rectangle;
typedef aabb<3> aabb3;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
-#include <cstdlib> // exit, srand
+#include <cstdlib> // exit, srand
#include <boost/noncopyable.hpp>
#include <SDL/SDL.h>
settings.get("framerate", framerate);
framerate = SCALAR(1.0) / framerate;
- //timer::default_source().scale(SCALAR(0.76));
-
//update_timer_.init(boost::bind(&application::dispatch_update,
- //this, _1, _2),
- //timestep_, timer::repeat);
+ //this, _1, _2), timestep_, timer::repeat);
//add_timer(update_timer_);
game_time_.reset(timestep_);
+ //game_time_.scale(SCALAR(0.5));
draw_timer_.init(boost::bind(&application::dispatch_draw,
- this, _1, _2), framerate, timer::repeat);
+ this, _1, _2), framerate, timer::repeat);
add_timer(draw_timer_);
-}
+ //timer::default_source().scale(SCALAR(0.2));
+}
void application::dispatch_update(timer& timer, scalar t)
{
{
switch (event.type)
{
- case SDL_KEYDOWN:
-
- if (event.key.keysym.sym == SDLK_ESCAPE &&
- (SDL_GetModState() & KMOD_CTRL) )
- {
- // emergency escape
- log_warning("escape forced");
- exit(1);
- }
- break;
-
- case SDL_VIDEORESIZE:
-
- video::current()->resize(event.resize.w, event.resize.h);
- break;
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE &&
+ (SDL_GetModState() & KMOD_CTRL))
+ {
+ log_warning("escape forced");
+ exit(1);
+ }
+ break;
+
+ case SDL_VIDEORESIZE:
+ video::current()->resize(event.resize.w,
+ event.resize.h);
+ break;
}
-
handle_event(event);
}
-
const int MAX_CONSECUTIVE_UPDATES = 15;
log_debug("updating", timer.expiration(), "/", t);
int i = 0;
while (timestep_ <= accum_ && i < MAX_CONSECUTIVE_UPDATES)
{
- log_debug("UPDATING");
- update(game_time_.ticks(), timestep_);
- game_time_.step();
+ scalar dt = game_time_.step();
+ update(game_time_.ticks(), dt);
accum_ -= timestep_;
}
scalar alpha = accum_ * inverse_timestep_;
- alpha = cml::clamp(alpha, SCALAR(-1.0), SCALAR(2.0));
+ //alpha = cml::clamp(alpha, SCALAR(-1.0), SCALAR(2.0));
if (alpha < SCALAR(0.0)) log_warning("alpha:", alpha);
else if (alpha > SCALAR(1.0)) log_warning("alpha:", alpha);
else log_debug("alpha:", alpha);
scalar begin = timer::ticks();
video::current()->swap(t);
-
scalar duration = timer::ticks() - begin;
- log_debug("flip duration:", duration);
+ log_debug("flip duration:", duration, begin, timer::ticks());
+
+ log_info("draw difference:", t - last_draw_);
+ last_draw_ = t;
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_APPLICATION_HH_
#define _MOOF_APPLICATION_HH_
namespace moof {
+// forward declarations
class settings;
class application : public runloop
{
public:
- application(settings& settings);
+ explicit application(settings& settings);
virtual ~application() {}
virtual void update(scalar t, scalar dt) = 0;
virtual void draw(scalar alpha) const = 0;
virtual void handle_event(const event& event) = 0;
-
private:
void dispatch_update(timer& timer, scalar t);
void dispatch_draw(timer& timer, scalar t);
- scalar last_update_;
- scalar accum_;
+ scalar last_update_;
+ scalar last_draw_;
+ scalar accum_;
game_time game_time_;
- timer update_timer_;
- timer draw_timer_;
+ timer update_timer_;
+ timer draw_timer_;
- scalar timestep_;
- scalar inverse_timestep_;
+ scalar timestep_;
+ scalar inverse_timestep_;
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
#include <stdexcept>
namespace moof {
-struct impl
-{
- static bool is_initialized;
- static int retain_count;
-};
-
-bool impl::is_initialized = false;
-int impl::retain_count = 0;
-
+static int retain_count = 0;
backend::backend()
{
- if (impl::retain_count++ == 0)
+ if (retain_count++ == 0)
{
-#if defined(_WIN32)
+#if PLATFORM_WIN32
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
#else
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) != 0)
{
char name[128];
SDL_VideoDriverName(name, sizeof(name));
- log_info << "initialized SDL; using video driver `"
- << name << "'" << std::endl;
+ log_info << "initialized SDL; using video driver `" <<
+ name << "'" << std::endl;
}
-
if (FE_Init() != 0)
{
throw std::runtime_error(FE_GetError());
}
}
-
- impl::is_initialized = true;
}
backend::backend(const backend& backend)
{
- ++impl::retain_count;
+ ++retain_count;
}
-backend& backend::operator=(const backend& backend)
+backend& backend::operator = (const backend& backend)
{
- ++impl::retain_count;
+ ++retain_count;
return *this;
}
backend::~backend()
{
- if (--impl::retain_count == 0)
+ if (--retain_count == 0)
{
log_info("shutting down SDL...");
FE_Quit();
SDL_Quit();
-
- impl::is_initialized = false;
}
}
bool backend::is_initialized()
{
- return impl::is_initialized;
+ return 0 < retain_count;
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_BACKEND_HH_
#define _MOOF_BACKEND_HH_
/**
* Some classes and subsystems require certain backend libraries to be
- * initialized. This is the mechanism to accomplish that. Classes which
- * rely on any backend libraries just need to instantiate this class as a
- * member. Backend cleanup will occur automagically when there are no more
- * instances.
+ * initialized. This is the mechanism to accomplish that. Classes which rely
+ * on any backend libraries just need to instantiate this class as a member.
+ * Backend cleanup will occur automagically when there are no more instances.
*/
class backend
{
public:
/**
- * Construct a backend reference, initializing the backend if it hasn't
- * already been initialized.
+ * Construct a backend reference, initializing the backend if it
+ * hasn't already been initialized.
*/
backend();
*/
static bool is_initialized();
-
- // The rest of this stuff is to implement the reference counting.
+ /* The rest of this stuff is to implement the reference counting. */
backend(const backend& backend);
- backend& operator=(const backend& backend);
+ backend& operator = (const backend& backend);
~backend();
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include "camera.hh"
#include "opengl.hh"
{
// FIXME: this doesn't work as expected
quaternion_rotation_aim_at(state_.orientation, state_.position, point,
- vector3(0.0, 1.0, 0.0));
+ vector3(0.0, 1.0, 0.0));
}
-
void camera::projection(const matrix4& projection)
{
projection_ = projection;
}
-void camera::projection(scalar fovy, scalar aspect, scalar abutting,
- scalar distant)
+void camera::projection(scalar fovy,
+ scalar aspect, scalar abutting, scalar distant)
{
matrix_perspective_yfov_RH(projection_, fovy, aspect, abutting,
- distant, z_clip_neg_one);
+ distant, z_clip_neg_one);
}
-
void camera::upload_to_gl(scalar alpha) const
{
calculate(alpha);
frustum_.init(modelview_, projection_);
}
-
void camera::update(scalar t, scalar dt)
{
rigid_body3::update(t, dt);
sphere_.draw(alpha);
}
-
void camera::handle_event(const event& event)
{
const scalar ds = 50.0;
switch (event.type)
{
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_RIGHT)
- {
- state_.position[0] -= ds;
- }
- else if (event.key.keysym.sym == SDLK_LEFT)
- {
- state_.position[0] += ds;
- }
- else if (event.key.keysym.sym == SDLK_UP)
- {
- state_.position[1] -= ds;
- }
- else if (event.key.keysym.sym == SDLK_DOWN)
- {
- state_.position[1] += ds;
- }
- else if (event.key.keysym.sym == SDLK_PAGEUP)
- {
- state_.position[2] += ds;
- }
- else if (event.key.keysym.sym == SDLK_PAGEDOWN)
- {
- state_.position[2] -= ds;
- }
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym)
+ {
+ case SDLK_RIGHT:
+ state_.position[0] -= ds; break;
+ case SDLK_LEFT:
+ state_.position[0] += ds; break;
+ case SDLK_UP:
+ state_.position[1] -= ds; break;
+ case SDLK_DOWN:
+ state_.position[1] += ds; break;
+ case SDLK_PAGEUP:
+ state_.position[2] += ds; break;
+ case SDLK_PAGEDOWN:
+ state_.position[2] -= ds; break;
+ default:
break;
+ }
+ break;
- case SDL_MOUSEMOTION:
- {
- scalar xrel = rad(scalar(event.motion.xrel) / 6.0);
- scalar yrel = rad(scalar(event.motion.yrel) / 6.0);
+ case SDL_MOUSEMOTION:
+ {
+ scalar xrel = rad(scalar(event.motion.xrel) / 6.0);
+ scalar yrel = rad(scalar(event.motion.yrel) / 6.0);
- quaternion rotation = state_.orientation;
+ quaternion rotation = state_.orientation;
- quaternion_rotate_about_world_x(rotation, yrel);
- //mRotation.normalize();
- quaternion_rotate_about_world_y(rotation, xrel);
+ quaternion_rotate_about_world_x(rotation, yrel);
+ //mRotation.normalize();
+ quaternion_rotate_about_world_y(rotation, xrel);
- rotation.normalize();
- state_.orientation = rotation;
- }
- break;
+ rotation.normalize();
+ state_.orientation = rotation;
+ break;
+ }
- case SDL_MOUSEBUTTONDOWN:
- if (event.button.button == SDL_BUTTON_WHEELUP)
- {
- state_.position[2] -= ds;
- }
- else if (event.button.button == SDL_BUTTON_WHEELDOWN)
- {
- state_.position[2] -= ds;
- }
+ case SDL_MOUSEBUTTONDOWN:
+ switch (event.button.button)
+ {
+ case SDL_BUTTON_WHEELUP:
+ state_.position[2] -= ds;
+ break;
+ case SDL_BUTTON_WHEELDOWN:
+ state_.position[2] += ds;
break;
+ }
}
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_CAMERA_HH_
#define _MOOF_CAMERA_HH_
return frustum_;
}
-
void upload_to_gl(scalar alpha = 0) const;
void update(scalar t, scalar dt);
void draw(scalar alpha = 0) const;
void handle_event(const event& event);
-
private:
void calculate(scalar alpha) const;
- mutable matrix4 modelview_;
- matrix4 projection_;
-
+ mutable matrix4 modelview_;
+ matrix4 projection_;
mutable class frustum frustum_;
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_CONTACT_HH_
#define _MOOF_CONTACT_HH_
{
typedef moof::vector< scalar, fixed<D> > vector;
- vector point; // point of contact
- scalar distance; // distance of penetration
- vector normal; // normal of surface at point of contact
+ vector point; // point of contact
+ scalar distance; // distance of penetration
+ vector normal; // normal of surface at point of contact
bool operator < (const contact& rhs)
{
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_CULLABLE_HH_
#define _MOOF_CULLABLE_HH_
namespace moof {
+// forward declarations
class frustum;
/**
* Interface for anything that can be culled.
*/
-
class cullable
{
public:
+
virtual ~cullable() {}
virtual bool is_visible(const frustum& frustum) const
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_DEBUG_HH_
#define _MOOF_DEBUG_HH_
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <map>
dispatcher_(dispatcher),
id_(0) {}
- dispatcher::handle getNewHandle()
+ dispatcher::handle new_handle()
{
- ++id_;
- dispatcher::handle handle(dispatcher_->impl_, id_);
+ dispatcher::handle handle(dispatcher_->impl_, --id_);
return handle;
}
typedef std::pair<unsigned,dispatcher::function> callback;
- typedef std::multimap<std::string,callback> callback_lookup;
- typedef callback_lookup::iterator callback_it;
-
- typedef std::multimap<unsigned,std::string> handle_lookup;
- typedef handle_lookup::iterator handle_it;
+ typedef std::multimap<std::string,callback> callback_lookup;
+ typedef callback_lookup::iterator callback_it;
+ typedef std::multimap<unsigned,std::string> handle_lookup;
+ typedef handle_lookup::iterator handle_it;
handle add_target(const std::string& event,
- const function& callback,
- handle handle)
+ const function& callback, handle handle)
{
- callbacks_.insert(std::make_pair(event, std::make_pair(handle.id(),
- callback)));
+ callbacks_.insert(std::make_pair(event,
+ std::make_pair(handle.id(), callback)));
handles_.insert(std::make_pair(handle.id(), event));
-
return handle;
}
{
std::pair<handle_it,handle_it> matching(handles_.equal_range(id));
- for (handle_it it = matching.first; it != matching.second; ++it)
+ for (handle_it it = matching.first;
+ it != matching.second; ++it)
{
callback_it first = callbacks_.find((*it).second);
callback_it last = callbacks_.end();
}
}
-
- dispatcher* dispatcher_;
-
- unsigned id_;
+ dispatcher* dispatcher_;
+ unsigned id_;
callback_lookup callbacks_;
handle_lookup handles_;
};
-
void dispatcher::handle::clear()
{
boost::shared_ptr<impl> dispatcher;
dispatcher::dispatcher() :
impl_(new dispatcher::impl(this)) {}
-
-dispatcher::handle dispatcher::add_target(const std::string& event,
- const function& callback)
+dispatcher::handle
+dispatcher::add_target(const std::string& event, const function& callback)
{
- return add_target(event, callback, impl_->getNewHandle());
+ return add_target(event, callback, impl_->new_handle());
}
dispatcher::handle dispatcher::add_target(const std::string& event,
- const function& callback,
- handle handle)
+ const function& callback, handle handle)
{
// pass through
return impl_->add_target(event, callback, handle);
}
-
void dispatcher::remove_target(unsigned id)
{
// pass through
return impl_->remove_target(id);
}
-
void dispatcher::dispatch(const std::string& event)
{
// pass through
impl_->dispatch(event);
}
-
dispatcher& dispatcher::global()
{
static dispatcher dispatcher;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_DISPATCH_HH_
#define _MOOF_DISPATCH_HH_
/**
* Dispatcher of messages to interested parties.
*/
-
class dispatcher
{
class impl;
void remove_target(unsigned id);
-
public:
class handle
private:
boost::weak_ptr<impl> dispatcher_;
- mutable unsigned id_;
+ mutable unsigned id_;
};
typedef boost::function<void(void)> function;
-
dispatcher();
handle add_target(const std::string& event, const function& callback);
handle add_target(const std::string& event, const function& callback,
- handle handle);
+ handle handle);
void dispatch(const std::string& event);
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_DRAWABLE_HH_
#define _MOOF_DRAWABLE_HH_
class drawable
{
public:
- virtual ~drawable() {}
+ virtual ~drawable() {}
virtual void draw(scalar alpha) const = 0;
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_ENTITY_HH_
#define _MOOF_ENTITY_HH_
namespace moof {
+// forward declarations
class frustum;
-
-class entity;
-
-/**
- * Entity pointer.
- */
-typedef boost::shared_ptr<entity> entity_ptr;
-
-
/**
* Interface for game objects that can be drawn to the screen and have a
* specified volume (take up space).
* timestep.
* \param frustum The camera frustum for determining visibility.
*/
- virtual void draw_if_visible(scalar alpha, const frustum& frustum) const
+ virtual void
+ draw_if_visible(scalar alpha, const frustum& frustum) const
{
if (is_visible(frustum)) draw(alpha);
}
return sphere_.is_visible(frustum) && aabb_.is_visible(frustum);
}
-
/**
* Get the axis-aligned bounding box surrounding the entity.
* \return The AABB.
return sphere_;
}
-
protected:
- moof::aabb3 aabb_;
+ moof::aabb3 aabb_;
moof::sphere3 sphere_;
};
+typedef boost::shared_ptr<entity> entity_ptr;
+
} // namespace moof
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_EVENT_HH_
#define _MOOF_EVENT_HH_
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include "aabb.hh"
#include "frustum.hh"
void frustum::init(const matrix4& modelview, const matrix4& projection)
{
scalar planes[6][4];
-
extract_frustum_planes(modelview, projection, planes, z_clip_neg_one);
- planes_[0] = plane(planes[0][0], planes[0][1],
- planes[0][2], planes[0][3]);
- planes_[1] = plane(planes[1][0], planes[1][1],
- planes[1][2], planes[1][3]);
- planes_[2] = plane(planes[2][0], planes[2][1],
- planes[2][2], planes[2][3]);
- planes_[3] = plane(planes[3][0], planes[3][1],
- planes[3][2], planes[3][3]);
- planes_[4] = plane(planes[4][0], planes[4][1],
- planes[4][2], planes[4][3]);
- planes_[5] = plane(planes[5][0], planes[5][1],
- planes[5][2], planes[5][3]);
+ planes_[0] = plane(planes[0][0], planes[0][1], planes[0][2], planes[0][3]);
+ planes_[1] = plane(planes[1][0], planes[1][1], planes[1][2], planes[1][3]);
+ planes_[2] = plane(planes[2][0], planes[2][1], planes[2][2], planes[2][3]);
+ planes_[3] = plane(planes[3][0], planes[3][1], planes[3][2], planes[3][3]);
+ planes_[4] = plane(planes[4][0], planes[4][1], planes[4][2], planes[4][3]);
+ planes_[5] = plane(planes[5][0], planes[5][1], planes[5][2], planes[5][3]);
}
void frustum::init(const matrix4& modelview, scalar fovy, scalar aspect,
- scalar abutting, scalar distant)
+ scalar abutting, scalar distant)
{
matrix4 projection;
-
- matrix_perspective_yfov_RH(projection, fovy, aspect, abutting,
- distant, z_clip_neg_one);
-
+ matrix_perspective_yfov_RH(projection,
+ fovy, aspect, abutting, distant, z_clip_neg_one);
init(modelview, projection);
}
frustum::collision frustum::contains(const aabb<3>& aabb) const
{
- vector3 corners[8];
- int nTotalInside = 0;
-
+ int total = 0;
+ vector3 corners[8];
aabb.get_corners(corners);
for (int i = 0; i < 6; ++i)
{
- int nInside = 8;
-
+ int num = 8;
for (int j = 0; j < 8; ++j)
{
if (planes_[i].intersects(corners[j]) == plane::negative)
- {
- --nInside;
- }
+ --num;
}
-
- if (nInside == 0) return outside;
- else if (nInside == 8) ++nTotalInside;
+ if (num == 0) return outside;
+ else if (num == 8) ++total;
}
- if (nTotalInside == 6) return inside;
- else return intersecting;
+ if (total == 6) return inside;
+ return intersecting;
}
-
-frustum::collision frustum::contains(const sphere<3>& sphere) const
+frustum::collision frustum::contains(const sphere3& sphere) const
{
for (int i = 0; i < 6; ++i)
{
plane::halfspace halfspace = planes_[i].intersects(sphere);
-
- if (halfspace == plane::negative) return outside;
+ if (halfspace == plane::negative) return outside;
else if (halfspace == plane::intersecting) return intersecting;
}
-
return inside;
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_FRUSTUM_HH_
#define _MOOF_FRUSTUM_HH_
#include <moof/math.hh>
#include <moof/plane.hh>
-
namespace moof {
-
template <int D> class aabb;
template <int D> class sphere;
-
/**
- * A six-sided volume for representing the space visible by a position
- * looking outward.
+ * A six-sided volume for representing the space visible by a position looking
+ * outward.
*/
class frustum
{
enum collision
{
- outside = 0,
- inside = 1,
+ outside = 0,
+ inside = 1,
intersecting = 2
};
void init(const matrix4& modelview, const matrix4& projection);
void init(const matrix4& modelview, scalar fovy, scalar aspect,
- scalar abutting, scalar distant);
+ scalar abutting, scalar distant);
collision contains(const aabb<3>& aabb) const;
collision contains(const sphere<3>& sphere) const;
-
private:
plane planes_[6]; // left, right, bottom, top, near, far
};
-
} // namespace moof
#endif // _MOOF_FRUSTUM_HH_
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include "hash.hh"
// 2. It will not produce the same results on little-endian and big-endian
// machines.
-unsigned hash_function::operator()(const void* key, int len,
- unsigned int seed) const
+unsigned
+hash_function::operator()(const void* key, int len, unsigned int seed) const
{
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_HASH_HH_
#define _MOOF_HASH_HH_
using stlplus::hash;
-
struct hash_function
{
// generic hash function
- unsigned operator () (const void* key, int len,
- unsigned seed = -1) const;
+ unsigned operator () (const void* key, int len, unsigned seed = -1) const;
unsigned operator () (const std::string& val) const
{
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <cstring> // strncmp
#include <fstream>
wrap_s_(GL_CLAMP),
wrap_t_(GL_CLAMP)
{
- std::ifstream file(path.c_str());
- if (!file.good()) throw std::runtime_error("no valid image found at " + path);
+ std::ifstream file(path.c_str(), std::ifstream::binary);
+ if (!file.good())
+ throw std::runtime_error("no valid image found at " + path);
png_byte signature[8];
size_t bytesRead;
- int bpp;
+ int bpp;
png_byte colors;
png_bytepp rows = 0;
png_textp texts = 0;
- int nutext_s;
+ int nutext_s;
bytesRead = file.read((char*)signature, sizeof(signature)).gcount();
if (bytesRead < sizeof(signature) ||
struct png
{
- png_structp context;
+ png_structp context;
png_infop info;
png() :
- context(png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0)),
+ context(png_create_read_struct(PNG_LIBPNG_VER_STRING,
+ 0, 0, 0)),
info(png_create_info_struct(context))
{
if (!context || !info) throw 0;
~png()
{
png_destroy_read_struct(context ? &context : 0,
- info ? &info : 0, 0);
+ info ? &info : 0, 0);
}
} png;
colors = png_get_color_type(png.context, png.info);
switch (colors)
{
- case PNG_COLOR_TYPE_PALETTE:
- png_set_palette_to_rgb(png.context);
- break;
+ case PNG_COLOR_TYPE_PALETTE:
+ png_set_palette_to_rgb(png.context);
+ break;
- case PNG_COLOR_TYPE_GRAY:
- if (bpp < 8) png_set_expand(png.context);
- break;
+ case PNG_COLOR_TYPE_GRAY:
+ if (bpp < 8) png_set_expand(png.context);
+ break;
- case PNG_COLOR_TYPE_GRAY_ALPHA:
- png_set_gray_to_rgb(png.context);
- break;
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ png_set_gray_to_rgb(png.context);
+ break;
}
if (bpp == 16) png_set_strip_16(png.context);
depth_ = bpp * channels_;
// read comments
- bool isTexture = false;
+ bool texture = false;
png_get_text(png.context, png.info, &texts, &nutext_s);
for (int i = 0; i < nutext_s; ++i)
{
if (strncmp(texts[i].key, "X-Yoink-Texture", 11) == 0)
{
set_texture_info(texts[i].text);
- isTexture = true;
+ texture = true;
break;
}
}
pixels_ = new char[width_ * pitch_];
rows = new png_bytep[height_];
- if (isTexture)
+ if (texture)
{
log_debug("texture detected; loading flipped");
for (int i = 0; i < height_; ++i)
{
- rows[height_-1-i] = (png_bytep)(pixels_ + i * channels_ * width_);
+ rows[height_-1-i] = (png_bytep)(pixels_ +
+ i * channels_ * width_);
}
}
else
log_debug("no texture attributes found");
for (int i = 0; i < height_; ++i)
{
- rows[i] = (png_bytep)(pixels_ + i * channels_ * width_);
+ rows[i] = (png_bytep)(pixels_ +
+ i * channels_ * width_);
}
}
);
SDL_WM_SetIcon(context, 0);
-
SDL_FreeSurface(context);
}
-
bool image::tile_coordinates(int index, scalar coords[8]) const
{
// make sure the index represents a real tile
return true;
}
-
void image::bind() const
{
ASSERT(video::current() && "should have a video context set");
global_object_ = 0;
}
-
/*
* Upload the image to GL so that it will be accessible by a much more
* manageable handle and hopefully reside in video memory.
*/
void image::upload_to_gl() const
{
- if (object_)
- {
- // already loaded
- return;
- }
+ if (object_) return; // already loaded
glGenTextures(1, (GLuint*)&object_);
glBindTexture(GL_TEXTURE_2D, (GLuint)object_);
GLuint mode;
if (channels_ == 3) mode = GL_RGB;
- else mode = GL_RGBA;
+ else mode = GL_RGBA;
glTexImage2D
//gluBuild2DMipmaps
{
if (object_)
{
- if (object_ == global_object_)
- {
- global_object_ = 0;
- }
-
+ if (object_ == global_object_) global_object_ = 0;
glDeleteTextures(1, (GLuint*)&object_);
object_ = 0;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_);
}
-
void image::set_texture_info(const std::string& info)
{
script script;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_IMAGE_HH_
#define _MOOF_IMAGE_HH_
static const int no_tile = -1;
-
explicit image(const std::string& path);
-
~image();
int width() const
return channels_;
}
-
std::string comment() const
{
return comment_;
return pixels_;
}
-
void set_as_icon() const;
-
/**
* Calculate texture coordinates for a tile at a certain index. Tiles
* are indexed start with zero as the top-left tile and moving across,
*/
bool tile_coordinates(int index, scalar coords[8]) const;
-
void bind() const;
static void reset_binding();
-
private:
void upload_to_gl() const;
void set_properties() const;
void set_texture_info(const std::string& info);
-
- char* pixels_;
+ char* pixels_;
mutable unsigned object_;
static unsigned global_object_;
- int width_;
- int height_;
- int depth_;
- int pitch_;
- int channels_;
+ int width_;
+ int height_;
+ int depth_;
+ int pitch_;
+ int channels_;
- std::string comment_;
+ std::string comment_;
- unsigned min_filter_;
- unsigned mag_filter_;
- int tile_s_;
- int tile_t_;
- unsigned wrap_s_;
- unsigned wrap_t_;
+ unsigned min_filter_;
+ unsigned mag_filter_;
+ int tile_s_;
+ int tile_t_;
+ unsigned wrap_s_;
+ unsigned wrap_t_;
//mutable dispatcher::handle new_context_;
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_INTERPOLATOR_HH_
#define _MOOF_INTERPOLATOR_HH_
{
stop = 0, /// Interpolator will stop when done.
repeat = 1, /// Interpolator will go back to the beginning.
- oscillate = 2 /// Interpolator will reverse direction.
+ oscillate = 2 /// Interpolator will reverse direction.
};
-
/**
* Construct an uninitialized interpolator.
*/
* \param t The duration of the interpolation.
* \param mode The interpolation mode.
*/
- interpolator(const T& a, const T& b, scalar t = 1.0, mode mode = stop) :
+ interpolator(const T& a, const T& b,
+ scalar t = 1.0, mode mode = stop) :
state_(a),
prior_(a),
a_(a),
is_done_ = false;
}
-
/**
* Update the interpolation state with a timeslice.
* \param t The total time in seconds.
{
switch (mode_)
{
- case stop:
- alpha_ = SCALAR(1.0);
- is_done_ = true;
- break;
- case repeat:
- alpha_ -= SCALAR(1.0);
- break;
- case oscillate:
- alpha_ = SCALAR(2.0) - alpha_;
- scale_ = -scale_;
- break;
+ case stop:
+ alpha_ = SCALAR(1.0);
+ is_done_ = true;
+ break;
+ case repeat:
+ alpha_ -= SCALAR(1.0);
+ break;
+ case oscillate:
+ alpha_ = SCALAR(2.0) - alpha_;
+ scale_ = -scale_;
+ break;
}
}
else if (alpha_ < 0.0)
{
switch (mode_)
{
- case stop:
- alpha_ = SCALAR(0.0);
- is_done_ = true;
- break;
- case repeat:
- alpha_ += SCALAR(1.0);
- break;
- case oscillate:
- alpha_ = -alpha_;
- scale_ = -scale_;
- break;
+ case stop:
+ alpha_ = SCALAR(0.0);
+ is_done_ = true;
+ break;
+ case repeat:
+ alpha_ += SCALAR(1.0);
+ break;
+ case oscillate:
+ alpha_ = -alpha_;
+ scale_ = -scale_;
+ break;
}
}
-
state_ = function_(a_, b_, alpha_);
}
}
-
/**
* Get the interpolated value.
* \return The interpolated value.
return is_done_;
}
-
private:
T state_;
}
};
-
typedef interpolator<linear_interpolation_function> lerp_scalar;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_LINE_HH_
#define _MOOF_LINE_HH_
{
typedef moof::vector< scalar, fixed<D> > vector;
-
vector a;
vector b;
-
line() {}
line(const vector& point1, const vector& point2) :
a(point1),
b(point2) {}
-
vector direction() const
{
return b - a;
return direction().length();
}
-
bool intersect(const line& other, contact<D>& hit) const
{
scalar d = (other.b[1] - other.a[1]) * (b[0] - a[0]) -
- (other.b[0] - other.a[0]) * (b[1] - a[1]);
+ (other.b[0] - other.a[0]) * (b[1] - a[1]);
- if (d == SCALAR(0.0)) return false; // lines are parallel
+ if (d == SCALAR(0.0)) return false; // lines are parallel
// ignoring the (somewhat remote) possibility of coincidence
- scalar m = ((other.b[0] - other.a[0]) * (a[1] - other.a[1]) -
- (other.b[1] - other.a[1]) * (a[0] - other.a[0])) / d;
+ scalar m = ((other.b[0] - other.a[0]) *
+ (a[1] - other.a[1]) -
+ (other.b[1] - other.a[1]) *
+ (a[0] - other.a[0])) / d;
scalar n = ((b[0] - a[0]) * (b[1] - other.a[1]) -
- (b[1] - a[1]) * (b[0] - other.a[0])) / d;
+ (b[1] - a[1]) * (b[0] - other.a[0])) / d;
if (m < SCALAR(0.0) || m > SCALAR(1.0) || // not intersecting
- n < SCALAR(0.0) || n > SCALAR(1.0)) return false;
+ n < SCALAR(0.0) || n > SCALAR(1.0))
+ return false;
vector2 tangent = b - a;
vector2 normal = perp(tangent).normalize();
if (dot(normal, other.a - other.b) < SCALAR(0.0))
- {
normal = -normal;
- }
hit.point = a + m * tangent;
hit.normal = normal;
if (projection < SCALAR(0.0) || projection > surfaceLength)
{
// try endpoints
-
if (other.intersect(a, hit))
{
hit.normal = -hit.normal;
hit.point = b;
return true;
}
-
return false;
}
scalar distance = normal.length();
- if (distance > other.radius) false; // not intersecting
+ if (distance > other.radius) false; // not intersecting
normal.normalize();
return true;
}
-
- bool intersect_ray(const ray<2>& ray, moof::ray<2>::contact& hit) const
+ bool
+ intersect_ray(const ray<2>& ray, moof::ray<2>::contact& hit) const
{
vector2 v1 = a - ray.point;
scalar a1 = signed_angle_2D(v1, b - ray.point);
hit.normal = perp(a - b);
return true;
-
/*
// solve: Cx + r*Dx = Ax + s(Bx - Ax)
// Cy + r*Dy = Ay + s(By - Ay)
*/
}
-
void draw(scalar alpha = 0.0) const
{
image::reset_binding();
}
};
-
typedef line<2> line2;
typedef line<3> line3;
polygon() {}
bool intersect_ray(const ray<D>& ray,
- typename moof::ray<D>::contact& hit)
+ typename moof::ray<D>::contact& hit)
{
return false;
}
{
image::reset_binding();
glBegin(GL_POLYGON);
- for (int i = 0; i < D; ++i)
- {
- glVertex(points[0]);
- }
+ for (int i = 0; i < D; ++i) glVertex(points[0]);
glEnd();
}
};
-
typedef polygon<2,3> triangle2;
typedef polygon<3,3> triangle3;
template <int D>
-bool intersect(const line<D>& line, const sphere<D>& sphere,
- contact<D>& hit)
+bool intersect(const line<D>& line, const sphere<D>& sphere, contact<D>& hit)
{
return false;
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
+
+#if HAVE_INCLUDE_H
+#include "config.h"
+#endif
#include <fstream>
-#if !defined(__WIN32)
+#if PLATFORM_POSIX
#include <termios.h>
#else
inline int isatty(int dummy) { return 0; }
#endif
-
#include "log.hh"
#include "script.hh"
return global_level_;
}
-
log::log(enum level level) :
level_(level)
{
if (isatty(1) == 0)
switch (level)
{
- case log::error: prefix_ = " error: "; break;
- case log::warning: prefix_ = "warning: "; break;
- case log::info: prefix_ = " info: "; break;
- case log::debug: prefix_ = " debug: "; break;
- case log::none: break;
+ case log::error: prefix_ = " error: "; break;
+ case log::warning: prefix_ = "warning: "; break;
+ case log::info: prefix_ = " info: "; break;
+ case log::debug: prefix_ = " debug: "; break;
+ case log::none: break;
}
else
switch (level)
{
- case log::error: prefix_ = "\033[30;101m error: "; break;
- case log::warning: prefix_ = "\033[30;103mwarning: "; break;
- case log::info: prefix_ = " info: "; break;
- case log::debug: prefix_ = "\033[2m debug: "; break;
- case log::none: break;
+ case log::error: prefix_ = "\033[30;101m error: ";
+ break;
+ case log::warning: prefix_ = "\033[30;103mwarning: ";
+ break;
+ case log::info: prefix_ = " info: ";
+ break;
+ case log::debug: prefix_ = "\033[2m debug: ";
+ case log::none: break;
}
}
{
if (log::global_level_ < log.level_) return null_log;
if (isatty(1) == 0) return moof::log << std::endl;
- else return moof::log << "\033[0m" << std::endl;
+ return moof::log << "\033[0m" << std::endl;
}
std::ostream& operator << (std::ostream& stream, log::endl_ endl)
{
if (isatty(1) == 0) return stream << std::endl;
- else return stream << "\033[0m" << std::endl;
+ return stream << "\033[0m" << std::endl;
}
-
std::ostream& log(std::cout);
static std::ofstream null_log_;
std::ostream& null_log(null_log_);
-
// These objects are intentionally not deconstructed so that logging will
// still be available after this module has been cleaned up.
class log& log_error(*new class log(log::error));
class log& log_info(*new class log(log::info));
class log& log_debug(*new class log(log::debug));
-
static int log_script(script& script, enum log::level level)
{
static class log* logs[] = {
script::slot param = script[1];
- while (!param.is_none())
- {
+ while (!param.is_none()) {
(*logs[level])(param);
++param.index;
}
void log::import(script& script)
{
script.import_function("LogError",
- boost::bind(log_script, _1, log::error));
+ boost::bind(log_script, _1, log::error));
script.import_function("LogWarning",
- boost::bind(log_script, _1, log::warning));
+ boost::bind(log_script, _1, log::warning));
script.import_function("LogInfo",
- boost::bind(log_script, _1, log::info));
+ boost::bind(log_script, _1, log::info));
script.import_function("print",
- boost::bind(log_script, _1, log::info));
+ boost::bind(log_script, _1, log::info));
script.import_function("LogDebug",
- boost::bind(log_script, _1, log::debug));
+ boost::bind(log_script, _1, log::debug));
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_LOG_HH_
#define _MOOF_LOG_HH_
/**
* \file log.hh
- * Functions related to logging the process.
- * The logging functions are log_error(), log_warning(), and log_info(),
- * listed from most critical to least critical.
+ * Functions related to logging the process. The logging functions are
+ * log_error(), log_warning(), and log_info(), listed from most critical to
+ * least critical.
*/
#include <cstdlib> // exit
namespace moof {
+// forward declarations
class script;
-
/**
* A class for handling a log priority. There are two ways to log
* messages: by treating a log object as a function whose parameters are
*/
enum level
{
- none = 0, ///< Disable all logging.
- error = 1, ///< Log only errors.
- warning = 2, ///< Log warnings and errors.
- info = 3, ///< Log everything.
- debug = 4, ///< Log absolutely everything.
+ none = 0, ///< Disable all logging.
+ error = 1, ///< Log only errors.
+ warning = 2, ///< Log warnings and errors.
+ info = 3, ///< Log everything.
+ debug = 4, ///< Log absolutely everything.
};
-
/**
* Set the lowest-priority log message that will be outputted to the
* log. Any logging with a lower priority will be ignored.
*/
static enum level level();
-
/**
* Import log functions to a script.
* \param The script.
*/
static void import(script& script);
-
/**
* Construct a log with a certain priority and prefix string.
* \param level The log level.
*/
log(enum level level);
-
/**
* Output this to end a line. This is equivalent to std::endl except
* this will also reset terminal format attributes.
{
} endl;
-
template <class A>
void operator () (const A& a)
{
template <class A, class B, class C, class D, class E>
void operator () (const A& a,
- const B& b,
- const C& c,
- const D& d,
- const E& e)
+ const B& b,
+ const C& c,
+ const D& d,
+ const E& e)
{
- *this << a << " "
- << b << " "
- << c << " "
- << d << " "
- << e << endl;
+ *this << a << " " << b << " " << c << " " << d << " " << e <<
+ endl;
}
-
private:
template <class T> friend std::ostream& operator << (log&, const T&);
static enum level global_level_;
- enum level level_;
- std::string prefix_;
+ enum level level_;
+ std::string prefix_;
};
-
extern std::ostream& log;
extern std::ostream& null_log;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_MANAGER_HH_
#define _MOOF_MANAGER_HH_
return boost::shared_ptr<T>(retain(name), &release);
}
-
private:
typedef stlplus::hash<std::string,T*,hash_function> ptr_lookup;
{
new_object->name_ = name;
new_object->init(name);
- ptr_lookup_.insert(std::make_pair(name, new_object));
+ ptr_lookup_.insert(std::make_pair(name,
+ new_object));
}
return new_object;
}
static ptr_lookup ptr_lookup_;
- std::string name_;
- unsigned retain_count_;
+ std::string name_;
+ unsigned retain_count_;
};
template <class T>
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_MATH_HH_
#define _MOOF_MATH_HH_
* General math-related types and functions.
*/
+#if HAVE_CONFIG_H
#include "config.h"
+#endif
#include <cmath>
#include <cml/cml.h>
#include <SDL/SDL_opengl.h>
-
#if ENABLE_DOUBLE_PRECISION
typedef GLdouble GLscalar;
#define GL_SCALAR GL_DOUBLE
using namespace cml;
-
typedef GLscalar scalar;
typedef vector< scalar, fixed<2> > vector2;
typedef matrix< scalar, fixed<3,3>, col_basis, col_major > matrix3;
typedef matrix< scalar, fixed<4,4>, col_basis, col_major > matrix4;
-typedef quaternion< scalar, fixed<>, vector_first, positive_cross > quaternion;
+typedef quaternion< scalar, fixed<>, vector_first, positive_cross > quaternion;
typedef constants<scalar> constants;
-
inline vector3 demote(const vector4& vec)
{
return vector3(vec[0], vec[1], vec[2]);
}
-// Here are some generic implementations of a few simple integrators. To
-// use, you need one type representing the state and another containing the
-// derivatives of the primary state variables. The state class must
-// implement these methods:
+// Here are some generic implementations of a few simple integrators. To use,
+// you need one type representing the state and another containing the
+// derivatives of the primary state variables. The state class must implement
+// these methods:
//
// void calculate_derivative(Derivative_Type& derivative, scalar absoluteTime);
// void step(const Derivative_Type& derivative, scalar deltaTime);
return evaluate<S,D>(state, t + dt);
}
-
template <class S, class D>
inline void euler(S& state, scalar t, scalar dt)
{
D a = evaluate<S,D>(state, t);
-
state.step(a, dt);
}
{
D a = evaluate<S,D>(state, t);
D b = evaluate<S,D>(state, t, dt * SCALAR(0.5), a);
-
state.step(b, dt);
}
D b = evaluate<S,D>(state, t, dt * SCALAR(0.5), a);
D c = evaluate<S,D>(state, t, dt * SCALAR(0.5), b);
D d = evaluate<S,D>(state, t, dt, c);
-
state.step((a + (b + c) * SCALAR(2.0) + d) * SCALAR(1.0/6.0), dt);
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <cstring>
#include <fstream>
#include <boost/algorithm/string/trim.hpp>
#include <zlib.h>
-#include <stlplus/strings/string_utilities.hpp>
-
#include "debug.hh"
#include "log.hh"
#include "mesh.hh"
// TODO: this file needs to be cleaned up
-
-#define AC3D_FORMAT_VERSION (0x0b)
-#define ZLIB_BUF_SIZE (262114)
+#define AC3D_FORMAT_VERSION 0x0b
+#define ZLIB_BUF_SIZE 262114
namespace moof {
MOOF_REGISTER_RESOURCE(mesh, ac, models);
-
static std::string read_string(std::istream& stream)
{
std::string str;
char atom;
- do // skip to the next non-space character
- {
- stream.get(atom);
- }
+ do stream.get(atom);
while (stream && std::isspace(atom));
if (atom == '"')
{
- do
- {
+ do {
stream.get(atom);
if (atom == '"') break;
str += atom;
}
else
{
- do
- {
+ do {
stream.get(atom);
if (std::isspace(atom)) break;
str += atom;
return str;
}
-inline int read_hex(std::istream& stream)
+static int read_hex(std::istream& stream)
{
int hex;
std::ios::fmtflags flags = stream.flags();
return hex;
}
-inline vector2 read_pair(std::istream& stream)
+static vector2 read_pair(std::istream& stream)
{
vector2 triplet;
stream >> triplet[0] >> triplet[1];
return triplet;
}
-inline vector3 read_triplet(std::istream& stream)
+static vector3 read_triplet(std::istream& stream)
{
vector3 triplet;
stream >> triplet[0] >> triplet[1] >> triplet[2];
return triplet;
}
-inline vector4 read_color(std::istream& stream)
+static vector4 read_color(std::istream& stream)
{
vector4 color;
stream >> color[0] >> color[1] >> color[2];
return color;
}
-
void mesh::import(std::istream& stream)
{
- std::string atom;
-
- object_ptr obj;
+ std::string atom;
+ object_ptr obj;
std::stack<int> kids;
// read and verify the AC3D header
//face.triangles.push_back(vert);
//}
-
-
mesh::mesh(const std::string& path)
{
std::ifstream file(path.c_str(), std::ifstream::in |
- std::ifstream::binary);
+ std::ifstream::binary);
if (!file) throw std::runtime_error("cannot find mesh file");
// if we can read the header, the file isn't compressed
{
log_info("text mesh detected");
file.seekg(std::ios::beg);
-
import(file);
}
else
zstream.next_in = Z_NULL;
int result = inflateInit2(&zstream, 32+MAX_WBITS);
- if (result != Z_OK) throw std::runtime_error("zlib init error");
+ if (result != Z_OK)
+ throw std::runtime_error("zlib init error");
- do
- {
+ do {
file.read(in, sizeof(in));
zstream.next_in = (Bytef*)in;
zstream.avail_in = file.gcount();
if (zstream.avail_in == 0) break;
- do
- {
+ do {
zstream.next_out = (Bytef*)out;
zstream.avail_out = sizeof(out);
result = inflate(&zstream, Z_NO_FLUSH);
switch (result)
{
- case Z_NEED_DICT:
- case Z_DATA_ERROR:
- case Z_MEM_ERROR:
- inflateEnd(&zstream);
- throw std::runtime_error("zlib inflate error");
- case Z_STREAM_ERROR:
- throw std::runtime_error("zlib stream error");
+ case Z_NEED_DICT:
+ case Z_DATA_ERROR:
+ case Z_MEM_ERROR:
+ inflateEnd(&zstream);
+ throw std::runtime_error("zlib inflate error");
+ case Z_STREAM_ERROR:
+ throw std::runtime_error("zlib stream error");
}
int inflated = sizeof(out) - zstream.avail_out;
while(result != Z_STREAM_END);
inflateEnd(&zstream);
-
import(stream);
}
}
-
void mesh::draw(scalar alpha) const
{
glEnableClientState(GL_VERTEX_ARRAY);
// TODO: disable vertex array?
}
-
void mesh::set_material(int index) const
{
set_material(materials_[index]);
glMaterial(GL_FRONT, GL_SHININESS, material.shininess);
}
-
void mesh::object::draw(scalar alpha, bool recurse) const
{
glVertexPointer(verts);
{
std::vector<object_ptr>::const_iterator jt;
for (jt = kids.begin(); jt != kids.end(); ++jt)
- {
(*jt)->draw(alpha);
- }
}
}
-
//class mesh_resource_loader
//{
//public:
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_MESH_HH_
#define _MOOF_MESH_HH_
namespace moof {
+// forward declarations
class script;
-
class mesh : public boost::noncopyable, public entity
{
public:
void draw(scalar alpha = SCALAR(0.0)) const;
-
struct material
{
material(const std::string& id) :
name(id) {}
-
+ scalar shininess;
std::string name;
-
- vector4 diffuse;
vector4 ambient;
+ vector4 diffuse;
vector4 emissive;
vector4 specular;
- scalar shininess;
};
-
void set_material(int index) const;
void set_material(const material& material) const;
std::vector<vector2> triangles_uv;
};
-
class object;
typedef boost::shared_ptr<object> object_ptr;
typedef boost::weak_ptr<object> object_weakptr;
return object_ptr(new object(m));
}
- void draw(scalar alpha = SCALAR(0.0), bool recurse = true) const;
-
+ void
+ draw(scalar alpha = SCALAR(0.0), bool recurse = true) const;
- const moof::mesh& mesh;
+ const moof::mesh& mesh;
- std::string name;
- std::string data;
- std::string url;
+ std::string name;
+ std::string data;
+ std::string url;
- image_handle texture;
- vector2 texrep;
+ image_handle texture;
+ vector2 texrep;
- std::vector<vector3> verts;
- std::vector<material_group> faces;
+ std::vector<vector3> verts;
+ std::vector<material_group> faces;
- std::vector<object_ptr> kids;
- std::map<std::string,object_ptr> kids_byname;
- object_weakptr parent;
+ std::vector<object_ptr> kids;
+ std::map<std::string,object_ptr> kids_byname;
+ object_weakptr parent;
};
-
object_ptr operator [] (unsigned index) const
{
return objects_[index];
}
-
/**
* Import script bindings for the mesh class.
* \param The script.
*/
static void import(script& script, const std::string& nspace = "");
-
private:
void import(std::istream& stream);
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include "log.hh"
#include "mesh.hh"
script[1].require_object<mesh_handle>("mesh").get(mesh);
scalar alpha;
- if (script[2].get(alpha)) (*mesh)->draw(alpha);
- else (*mesh)->draw();
+ if (script[2].get(alpha))
+ (*mesh)->draw(alpha);
+ else
+ (*mesh)->draw();
return 0;
}
mesh::object_ptr* object;
script[1].require_object<mesh::object_ptr>("mesh object").get(object);
- scalar alpha;
- bool recurse;
- if (script[2].get(alpha))
- {
- if (script[3].get(recurse)) (*object)->draw(alpha, recurse);
- else (*object)->draw(alpha);
+ scalar alpha;
+ bool recurse;
+ if (script[2].get(alpha)) {
+ if (script[3].get(recurse))
+ (*object)->draw(alpha, recurse);
+ else
+ (*object)->draw(alpha);
}
- else
- {
- if (script[2].get(recurse)) (*object)->draw(SCALAR(0.0), recurse);
- else (*object)->draw();
+ else {
+ if (script[2].get(recurse))
+ (*object)->draw(SCALAR(0.0), recurse);
+ else
+ (*object)->draw();
}
return 0;
mesh::object_ptr* object;
script[1].require_object<mesh::object_ptr>("mesh object").get(object);
- if (script[2].is_number())
- {
+ if (script[2].is_number()) {
unsigned index;
script[2].get(index);
--index;
script.push((*object)->kids[index]);
}
- else if (script[2].is_string())
- {
+ else if (script[2].is_string()) {
std::string name;
script[2].get(name);
script.push((*object)->kids_byname[name]);
}
- else
- {
+ else {
script[2].raise_type_error("index or name");
}
return 1;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_MODAL_DIALOG_HH_
#define _MOOF_MODAL_DIALOG_HH_
* supported, but only one can be used as determined at build time.
*/
+#if HAVE_CONFIG_H
#include "config.h"
+#endif
#include <string>
/**
* Small wrapper over various user interface modal dialog windows.
*/
-
struct modal_dialog
{
enum type
error = 3
};
-
- std::string title;
+ std::string title;
type type;
- std::string text1;
- std::string text2;
-
+ std::string text1;
+ std::string text2;
/**
* Construct a dialog box.
* \param text2 The second line.
*/
modal_dialog(enum type type = information,
- const std::string& title = "",
- const std::string& text1 = "",
- const std::string& text2 = "") :
+ const std::string& title = "",
+ const std::string& text1 = "",
+ const std::string& text2 = "") :
title(title),
type(type),
text1(text1),
text2(text2) {}
-
void run() const
{
switch (type)
{
- case warning:
- log_warning(text1);
- log_warning(text2);
- break;
- case error:
- log_error(text1);
- log_error(text2);
- break;
- default:
- log_info(text1);
- log_info(text2);
- break;
+ case warning:
+ log_warning(text1);
+ log_warning(text2);
+ break;
+ case error:
+ log_error(text1);
+ log_error(text2);
+ break;
+ default:
+ log_info(text1);
+ log_info(text2);
+ break;
}
#if PLATFORM_WIN32
-
int icon_type;
switch (type)
{
- case warning:
- icon_type = MB_ICONWARNING;
- break;
- case error:
- icon_type = MB_ICONERROR;
- break;
- default:
- icon_type = MB_ICONINFORMATION;
- break;
+ case warning:
+ icon_type = MB_ICONWARNING;
+ break;
+ case error:
+ icon_type = MB_ICONERROR;
+ break;
+ default:
+ icon_type = MB_ICONINFORMATION;
+ break;
}
MessageBox(0, (text1 + "\n" + text2).c_str(), title.c_str(),
MB_OK | icon_type);
-
#elif WITH_GUI_GTK
-
- int argc = 0;
+ int argc = 0;
char** argv;
gtk_init(&argc, &argv);
GtkMessageType icon_type;
switch (type)
{
- case warning:
- icon_type = GTK_MESSAGE_WARNING;
- break;
- case error:
- icon_type = GTK_MESSAGE_ERROR;
- break;
- default:
- icon_type = GTK_MESSAGE_INFO;
- break;
+ case warning:
+ icon_type = GTK_MESSAGE_WARNING;
+ break;
+ case error:
+ icon_type = GTK_MESSAGE_ERROR;
+ break;
+ default:
+ icon_type = GTK_MESSAGE_INFO;
+ break;
}
GtkWidget* dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT, icon_type,
GTK_BUTTONS_CLOSE, "%s", text1.c_str());
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
- "%s", text2.c_str());
+ "%s", text2.c_str());
gtk_window_set_title(GTK_WINDOW(dialog), title.c_str());
- std::string icon_path = resource::find_file(PACKAGE".png");
+ std::string icon_path = resource::find_file(PACKAGE_TARNAME".png");
if (!icon_path.empty())
{
GdkPixbuf* iconPixbuf = gdk_pixbuf_new_from_file(icon_path.c_str(),
- NULL);
+ NULL);
gtk_window_set_icon(GTK_WINDOW(dialog), iconPixbuf);
}
gtk_widget_destroy(dialog);
// FIXME - this doesn't seem to actually remove the window from the
// screen when it closes
-
#elif WITH_GUI_QT4
-
- int argc = 0;
+ int argc = 0;
char** argv;
QApplication qt_app(argc, argv);
QMessageBox::Icon icon_type;
switch (type)
{
- case warning:
- icon_type = QMessageBox::Warning;
- break;
- case error:
- icon_type = QMessageBox::Critical;
- break;
- default:
- icon_type = QMessageBox::Information;
- break;
+ case warning:
+ icon_type = QMessageBox::Warning;
+ break;
+ case error:
+ icon_type = QMessageBox::Critical;
+ break;
+ default:
+ icon_type = QMessageBox::Information;
+ break;
}
QMessageBox dialog;
dialog.setInformativeText(text2.c_str());
dialog.setStandardButtons(QMessageBox::Close);
- std::string icon_path = resource::find_file(PACKAGE".png");
+ std::string icon_path = resource::find_file(PACKAGE_TARNAME".png");
if (!icon_path.empty())
{
QIcon icon(icon_path.c_str());
}
dialog.exec();
-
#endif
}
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_NETWORK_HH_
#define _MOOF_NETWORK_HH_
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_OPENGL_HH_
#define _MOOF_OPENGL_HH_
/**
* \file opengl.hh
- * Defines macros for OpenGL functions that operate on scalars, vectors,
- * and matrices.
+ * Defines macros for OpenGL functions that operate on scalars, vectors, and
+ * matrices.
*/
+#if HAVE_CONFIG_H
#include "config.h"
+#endif
#include <vector>
#define ARGS_V4 const moof::vector4& v
#define PASS_V4 v[0], v[1], v[2], v[3]
-
#if ENABLE_DOUBLE_PRECISION
-#define OPENGL_GENERIC_FUNC(R, N, L) \
+#define OPENGL_GENERIC_FUNC(R, N, L) \
inline R gl##N(ARGS_##L) { gl##N##d(PASS_##L); }//
-#define OPENGL_ORDINAL_FUNC(R, N, K) \
- inline R gl##N(ARGS_##S##K) { gl##N##K##d(PASS_##S##K); } \
+#define OPENGL_ORDINAL_FUNC(R, N, K) \
+ inline R gl##N(ARGS_##S##K) { gl##N##K##d(PASS_##S##K); } \
inline R gl##N(ARGS_##P##K) { gl##N##K##d##v(PASS_##P##K); }//
#else
-#define OPENGL_GENERIC_FUNC(R, N, L) \
+#define OPENGL_GENERIC_FUNC(R, N, L) \
inline R gl##N(ARGS_##L) { gl##N##f(PASS_##L); }//
-#define OPENGL_ORDINAL_FUNC(R, N, K) \
- inline R gl##N(ARGS_##S##K) { gl##N##K##f(PASS_##S##K); } \
+#define OPENGL_ORDINAL_FUNC(R, N, K) \
+ inline R gl##N(ARGS_##S##K) { gl##N##K##f(PASS_##S##K); } \
inline R gl##N(ARGS_##P##K) { gl##N##K##f##v(PASS_##P##K); }//
#endif
+OPENGL_GENERIC_FUNC(void, LoadMatrix, P);
+OPENGL_GENERIC_FUNC(void, LoadMatrix, M);
+OPENGL_GENERIC_FUNC(void, MultMatrix, P);
+OPENGL_GENERIC_FUNC(void, MultMatrix, M);
+
+OPENGL_GENERIC_FUNC(void, Scale, S3);
+OPENGL_GENERIC_FUNC(void, Scale, V3);
+OPENGL_GENERIC_FUNC(void, Rotate, S4);
+OPENGL_GENERIC_FUNC(void, Rotate, V4);
+OPENGL_GENERIC_FUNC(void, Translate, S3);
+OPENGL_GENERIC_FUNC(void, Translate, V3);
-OPENGL_GENERIC_FUNC(void, LoadMatrix, P);
-OPENGL_GENERIC_FUNC(void, LoadMatrix, M);
-OPENGL_GENERIC_FUNC(void, MultMatrix, P);
-OPENGL_GENERIC_FUNC(void, MultMatrix, M);
-
-OPENGL_GENERIC_FUNC(void, Scale, S3);
-OPENGL_GENERIC_FUNC(void, Scale, V3);
-OPENGL_GENERIC_FUNC(void, Rotate, S4);
-OPENGL_GENERIC_FUNC(void, Rotate, V4);
-OPENGL_GENERIC_FUNC(void, Translate, S3);
-OPENGL_GENERIC_FUNC(void, Translate, V3);
-
-OPENGL_ORDINAL_FUNC(void, Color, 3);
-OPENGL_ORDINAL_FUNC(void, Color, 4);
+OPENGL_ORDINAL_FUNC(void, Color, 3);
+OPENGL_ORDINAL_FUNC(void, Color, 4);
-OPENGL_ORDINAL_FUNC(void, Vertex, 2);
-OPENGL_ORDINAL_FUNC(void, Vertex, 3);
-OPENGL_ORDINAL_FUNC(void, Vertex, 4);
+OPENGL_ORDINAL_FUNC(void, Vertex, 2);
+OPENGL_ORDINAL_FUNC(void, Vertex, 3);
+OPENGL_ORDINAL_FUNC(void, Vertex, 4);
-OPENGL_ORDINAL_FUNC(void, TexCoord, 2);
-OPENGL_ORDINAL_FUNC(void, TexCoord, 3);
-OPENGL_ORDINAL_FUNC(void, TexCoord, 4);
-
-OPENGL_GENERIC_FUNC(void, Rect, S4);
-OPENGL_GENERIC_FUNC(void, Rect, V4);
+OPENGL_ORDINAL_FUNC(void, TexCoord, 2);
+OPENGL_ORDINAL_FUNC(void, TexCoord, 3);
+OPENGL_ORDINAL_FUNC(void, TexCoord, 4);
+OPENGL_GENERIC_FUNC(void, Rect, S4);
+OPENGL_GENERIC_FUNC(void, Rect, V4);
inline void glMaterial(GLenum face, GLenum pname, moof::scalar s)
{
glDrawElements(type, v.size(), GL_UNSIGNED_INT, &v[0]);
}
-
+inline void glGetScalar(GLenum a, GLscalar* b)
+{
#if ENABLE_DOUBLE_PRECISION
-inline void glGetScalar(GLenum a, GLscalar* b) { glGetDoublev(a, b); }
+ glGetDoublev(a, b);
#else
-inline void glGetScalar(GLenum a, GLscalar* b) { glGetFloatv(a, b); }
+ glGetFloatv(a, b);
#endif
+}
#endif // _MOOF_OPENGL_HH_
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include "aabb.hh"
#include "plane.hh"
namespace moof {
-plane::halfspace plane::intersects(const aabb<3>& aabb) const
+plane::halfspace plane::intersects(const aabb3& aabb) const
{
- vector3 corners[8];
int nPositive = 8;
-
+ vector3 corners[8];
aabb.get_corners(corners);
for (int i = 0; i < 8; ++i)
{
- if (intersects(corners[i]) == negative)
- {
- --nPositive;
- }
+ if (intersects(corners[i]) == negative) --nPositive;
}
- if (nPositive == 0) return negative;
+ if (nPositive == 0) return negative;
else if (nPositive == 8) return positive;
- else return intersecting;
+ return intersecting;
}
-plane::halfspace plane::intersects(const sphere<3>& sphere) const
+plane::halfspace plane::intersects(const sphere3& sphere) const
{
scalar distance = distance_to_point(sphere.point);
- if (distance < -sphere.radius) return negative;
+ if (distance < -sphere.radius) return negative;
else if (distance < sphere.radius) return intersecting;
- else return positive;
+ return positive;
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_PLANE_HH_
#define _MOOF_PLANE_HH_
namespace moof {
+// forward declarations
template <int D> class aabb;
template <int D> class sphere;
-
/**
- * A plane in 3-space defined by the equation Ax + By + Cz = D, where [A,
- * B, C] is normal to the plane.
+ * A plane in 3-space defined by the equation Ax + By + Cz = D, where [A, B,
+ * C] is normal to the plane.
*/
struct plane : public shape<3>
{
enum halfspace
{
- negative = -1,
+ negative = -1,
intersecting = 0,
- positive = 1
+ positive = 1
};
plane() {}
normal(a, b, c),
d(scalar) {}
-
bool intersect_ray(const ray3& ray, ray3::contact& hit)
{
// solve: [(ray.point + t*ray.direction) dot normal] + d = 0
if (hit.distance < SCALAR(0.0)) return false;
if (numer >= 0.0) hit.normal = normal;
- else hit.normal = -normal;
+ else hit.normal = -normal;
return true;
}
-
/* Causes the normal of the plane to become normalized. The scalar may
* also be changed to keep the equation true. Word to the wise: don't
* normalize a plane if the normal is the zero vector.
void normalize()
{
scalar mag = normal.length();
-
normal /= mag;
d /= mag;
}
scalar distance = distance_to_point(point);
if (is_equal(distance, 0.0)) return intersecting;
- else if (distance < 0.0) return negative;
- else return positive;
+ else if (distance < 0.0) return negative;
+ return positive;
}
halfspace intersects(const aabb<3>& aabb) const;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_RAY_HH_
#define _MOOF_RAY_HH_
}
};
-
-typedef ray<2> ray2;
-typedef ray<3> ray3;
+typedef ray<2> ray2;
+typedef ray<3> ray3;
} // namespace moof
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
+#if HAVE_CONFIG_H
#include "config.h"
+#endif
#include <queue>
#include "hash.hh"
#include "resource.hh"
-
#ifndef BUF_SIZE
-#define BUF_SIZE 4096
+#define BUF_SIZE 8192
#endif
namespace moof {
-
+
/*] Filesystem searching
*************************************************************************/
boost::split(search_paths_, paths, boost::is_any_of(":"));
}
-
std::string resource::find_file(const std::string& name)
{
std::string ext = stlplus::extension_part(name);
return std::string();
}
-std::string resource::find_file(const std::string& name,
- const std::string& ext)
+std::string
+resource::find_file(const std::string& name, const std::string& ext)
{
std::string actual_ext = stlplus::extension_part(name);
if (actual_ext != ext)
{
hash<std::string,resource_weakptr,hash_function>::iterator it;
for (it = table.begin(); it != table.end(); ++it)
- {
log_warning("leaked resource:", (*it).first);
- }
}
#endif
} rsrc_list;
int add(resource_ptr rsrc)
{
int wd = inotify_add_watch(fd, rsrc->path().c_str(),
- IN_DELETE_SELF | IN_MODIFY);
+ IN_DELETE_SELF | IN_MODIFY);
table[wd] = rsrc;
return wd;
}
} watch_list;
#endif
-
resource_ptr resource::load(const std::string& name)
{
std::string ext = stlplus::extension_part(name);
return load_with_path(find_file(name, ext), ext);
}
-resource_ptr resource::load(const std::string& name,
- const std::string& ext)
+resource_ptr resource::load(const std::string& name, const std::string& ext)
{
return load_with_path(find_file(name, ext), ext);
}
-
-resource_ptr resource::load_with_path(const std::string& path,
- const std::string& ext)
+resource_ptr
+resource::load_with_path(const std::string& path, const std::string& ext)
{
if (path.empty()) return resource_ptr();
return resource_ptr();
}
-
/*] Hotloading
*************************************************************************/
}
}
#endif
-
return count;
}
#endif
}
-
/*] Resource registration
*************************************************************************/
bool resource::call_registry(const std::string& ext,
- loader_ptr& loader,
- registry_action action)
+ loader_ptr& loader, registry_action action)
{
static std::map<std::string,loader_ptr> table;
switch (action)
{
- case set:
- {
- if (loader) table[ext] = loader;
- else table.erase(ext);
- break;
- }
+ case lookup:
+ {
+ std::map<std::string,loader_ptr>::iterator it;
+ it = table.find(ext);
+ if (it != table.end()) loader = (*it).second;
+ break;
+ }
- case lookup:
- {
- std::map<std::string,loader_ptr>::iterator it;
- it = table.find(ext);
- if (it != table.end()) loader = (*it).second;
- break;
- }
+ case set:
+ if (loader)
+ table[ext] = loader;
+ else
+ table.erase(ext);
+ break;
}
return loader;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_RESOURCE_HH_
#define _MOOF_RESOURCE_HH_
class resource;
typedef boost::shared_ptr<resource> resource_ptr;
-
/**
* Generic resource class capable of containing any type of resource,
* providing a type-safe interface.
*/
static void set_search_paths(const std::string& paths);
-
/**
* Get the path to a resource of a given name. This uses the search
* path(s) and resources prefixes to locate resource files.
* extension is not already a part of name.
* \return The full path of the resource.
*/
- static std::string find_file(const std::string& name,
- const std::string& ext);
+ static std::string
+ find_file(const std::string& name, const std::string& ext);
/**
* Register a type with the extension of files which this type can
*/
template <class T>
static void register_type(const std::string& extension,
- const std::string& prefix = "")
+ const std::string& prefix = "")
{
loader_ptr loader(new specific_loader<T>(prefix));
call_registry(extension, loader, set);
call_registry(extension, loader, set);
}
-
/**
* Find and load a resource by name or path.
* \param name The name or partial path of the resource. This should
* \param
* \return The resource.
*/
- static resource_ptr load(const std::string& name,
- const std::string& ext);
-
+ static resource_ptr
+ load(const std::string& name, const std::string& ext);
/**
* Reload the resource data. This will cause the resource file to be
*/
static int reload_as_needed();
-
/**
* Get whether or not the type of the underlying resource data matches
* an expected type.
return 0;
}
-
/**
* Deconstruct a resource container.
*/
virtual ~resource();
-
private:
template <class T>
unloader_(new specific_unloader<T>(ptr)),
wd_(-1) {}
- static resource_ptr load_with_path(const std::string& path,
- const std::string& extension);
-
+ static resource_ptr
+ load_with_path(const std::string& path, const std::string& extension);
class loader
{
return prefix_;
}
-
private:
std::string prefix_;
}
};
-
class unloader
{
public:
delete object_;
}
-
private:
T* object_;
};
-
enum registry_action
{
lookup,
};
static bool call_registry(const std::string& extension,
- loader_ptr& loader,
- registry_action action);
+ loader_ptr& loader, registry_action action);
-
- void* resource_;
+ void* resource_;
std::type_info* typeinfo_;
unloader_ptr unloader_;
- int wd_;
- std::string path_;
- std::string type_;
+ int wd_;
+ std::string path_;
+ std::string type_;
};
resource_handle(const std::string& name, const std::string& ext) :
resource_(resource::load(name, ext)) {}
-
/**
* Get whether or not the handle is dereferenceable to the type of this
* handle. A resource handle is dereferenceable if it is not a null
return resource_->check<T>();
}
-
/**
* Get a pointer to the underlying resource.
* \return The pointer, or null if this handle is not dereferenceable.
return *(resource_->get<T>());
}
-
/**
* Same as get() for getting a pointer to the underlying resources.
* \return The pointer, or null if this handle is not dereferenceable.
return get_reference();
}
-
/**
* Unload the resource associated with this handle.
*/
resource_ = resource_ptr();
}
-
private:
resource_ptr resource_;
};
-
/**
* This macro easily registers types to act as resources. It should be
* used in a module file in global scope.
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_RIGID_BODY_HH_
#define _MOOF_RIGID_BODY_HH_
{
typedef moof::vector< scalar, fixed<D> > vector;
typedef boost::function<const vector& (const linear_state&)>
- force_function;
+ force_function;
// primary
-
vector position;
vector momentum;
// secondary
-
vector velocity;
// user
-
vector force;
std::vector<force_function> forces;
// constant
-
scalar mass;
scalar inverse_mass;
-
void recalculate()
{
velocity = momentum * inverse_mass;
}
-
struct gravity_force
{
explicit gravity_force(scalar a = -9.8)
return force;
}
-
private:
vector force;
scalar acceleration;
};
-
void init()
{
position.zero();
inverse_mass = 1.0 / mass;
}
-
struct derivative
{
vector velocity;
}
};
-
vector total_force() const
{
vector f(force);
}
};
-
struct rotational_state2
{
// primary
-
scalar orientation;
scalar angular_momentum;
// secondary
-
scalar angularVelocity;
// constant
-
scalar inertia;
scalar inverse_inertia;
-
void recalculate()
{
angularVelocity = angular_momentum * inertia;
}
-
struct derivative
{
scalar angularVelocity;
struct rotational_state3
{
// primary
-
quaternion orientation;
vector3 angular_momentum;
// secondary
-
quaternion spin;
vector3 angularVelocity;
// constant
-
scalar inertia;
scalar inverse_inertia;
-
void recalculate()
{
angularVelocity = angular_momentum * inertia;
}
};
-
template <class T>
inline T interpolate(const T& a, const T& b, scalar alpha)
{
}
template <>
-inline state2 interpolate<state2>(const state2& a, const state2& b,
- scalar alpha)
+inline state2
+interpolate<state2>(const state2& a, const state2& b, scalar alpha)
{
state2 state(b);
state.position = interpolate(a.position, b.position, alpha);
state.momentum = interpolate(a.momentum, b.momentum, alpha);
state.orientation = interpolate(a.orientation, b.orientation, alpha);
state.angular_momentum = interpolate(a.angular_momentum,
- b.angular_momentum, alpha);
+ b.angular_momentum, alpha);
return state;
}
template <>
-inline state3 interpolate<state3>(const state3& a, const state3& b,
- scalar alpha)
+inline state3
+interpolate<state3>(const state3& a, const state3& b, scalar alpha)
{
state3 state(b);
state.position = interpolate(a.position, b.position, alpha);
state.momentum = interpolate(a.momentum, b.momentum, alpha);
state.orientation = slerp(a.orientation, b.orientation, alpha);
state.angular_momentum = interpolate(a.angular_momentum,
- b.angular_momentum, alpha);
+ b.angular_momentum, alpha);
return state;
}
-
-
/**
* Interface for anything that can move.
*/
-
template <class T>
class rigid_body : public entity
{
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
+#if HAVE_CONFIG_H
#include "config.h"
+#endif
#include <algorithm>
return a->expiration() < b->expiration();
}
-void runloop::run_once()
+
+int runloop::run_once()
{
#if ENABLE_THREADS
thread_id_ = thread::current_identifier();
#endif
//log_debug("------------------------------------");
- //scalar next_event = SCALAR(0.0);
- {
- MOOF_MUTEX_LOCK(timers_mutex_);
+ int expired = 0;
+ MOOF_MUTEX_LOCK(timers_mutex_);
- for (timers_it_ = timers_.begin();
- timers_it_ != timers_.end();
- ++timers_it_)
- {
- (*timers_it_)->fire_if_expired();
- }
-
- std::sort(timers_.begin(), timers_.end(), comp);
- //next_event = timers_[0]->expiration();
+ std::sort(timers_.begin(), timers_.end(), comp);
+ for (timers_it_ = timers_.begin();
+ timers_it_ != timers_.end(); ++timers_it_)
+ {
+ if ((*timers_it_)->fire_if_expired()) ++expired;
}
+ return expired;
}
int runloop::run()
stop_ = false;
while (!stop_)
{
- run_once();
- //timer::sleep(next_event, timer::absolute);
- timer::sleep(SCALAR(0.0));
+ if (run_once() == 0);//timer::sleep(SCALAR(0.0));
+ // TODO: maybe sleep(0.0001) will actually return sooner than
+ // sleep(0)... if the kernel interprets sleep(0) as we don't need
+ // to process for an arbitrarily long timespan while specifying a
+ // value lets the kernel know when we need control back...
}
-
return code_;
}
-
void runloop::stop(int code)
{
code_ = code;
stop_ = true;
}
-
void runloop::add_timer(timer& timer)
{
#if ENABLE_THREADS
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_RUNLOOP_HH_
#define _MOOF_RUNLOOP_HH_
// forward declarations
class timer;
-
/**
* A runloop is a loop with scheduled timers.
/**
* Do one iteration of the runloop.
+ * \return The number of tasks which were given time.
*/
- void run_once();
-
+ int run_once();
/**
* Start running the runloop.
*/
void stop(int code = 0);
+ bool is_running() const
+ {
+ return !stop_;
+ }
void add_timer(timer& timer);
void remove_timer(timer& timer);
-
private:
bool stop_;
- int code_;
+ int code_;
typedef std::vector<timer*> timer_table;
timer_table timers_;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_SCRIPT_HH_
#define _MOOF_SCRIPT_HH_
* \file script.hh
* A thin wrapper over Lua 5.1. This is not meant as a complicated binding
* package between C++ and Lua. It is not meant to obscure the division
- * between C++ and Lua but rather to clarify it and make it more
- * manageable. It does not hide the concept of the Lua stack, but rather
- * provides that mechanism with a certain level of abstraction while also
- * providing a cleaner, more consistent API.
+ * between C++ and Lua but rather to clarify it and make it more manageable.
+ * It does not hide the concept of the Lua stack, but rather provides that
+ * mechanism with a certain level of abstraction while also providing a
+ * cleaner, more consistent API.
*/
#include <cstring>
class script;
typedef boost::shared_ptr<script> script_ptr;
-
class script
{
public:
enum status
{
- success = 0,
- yielding = LUA_YIELD,
+ success = 0,
+ yielding = LUA_YIELD,
runtime_error = LUA_ERRRUN,
syntax_error = LUA_ERRSYNTAX,
memory_error = LUA_ERRMEM,
handler_error = LUA_ERRERR,
- file_error = LUA_ERRFILE
+ file_error = LUA_ERRFILE
};
enum pseudoindex
globals_index = LUA_GLOBALSINDEX
};
-
template <class T>
static int object_finalizer(script& script)
{
return 0;
}
-
/**
* This is the most prominent abstraction on top of the standard Lua
* API. A slot object represents a value on the stack. More
* specifically, it represents a position on the stack. The
* distinction is only important when objects are moved around on the
* stack or if the slot represents a negative index on the stack (the
- * value of which will change as things are pushed onto and popped from
- * the stack).
+ * value of which will change as things are pushed onto and popped
+ * from the stack).
*/
struct slot
{
/**
- * You have direct access to the index of the value on the stack
- * being represented.
+ * You have direct access to the index of the value on the
+ * stack being represented.
*/
int index;
-
enum type
{
- none = LUA_TNONE,
- nil = LUA_TNIL,
- boolean = LUA_TBOOLEAN,
- light_data = LUA_TLIGHTUSERDATA,
- number = LUA_TNUMBER,
- string = LUA_TSTRING,
- table = LUA_TTABLE,
- function = LUA_TFUNCTION,
- data = LUA_TUSERDATA,
- thread = LUA_TTHREAD
+ none = LUA_TNONE,
+ nil = LUA_TNIL,
+ boolean = LUA_TBOOLEAN,
+ light_data = LUA_TLIGHTUSERDATA,
+ number = LUA_TNUMBER,
+ string = LUA_TSTRING,
+ table = LUA_TTABLE,
+ function = LUA_TFUNCTION,
+ data = LUA_TUSERDATA,
+ thread = LUA_TTHREAD
};
static std::string type_name(type type)
{
switch (type)
{
- case none: return "none";
- case nil: return "nil";
- case boolean: return "boolean";
+ case none: return "none";
+ case nil: return "nil";
+ case boolean: return "boolean";
case light_data:
- case data: return "userdata";
- case number: return "number";
- case string: return "string";
- case table: return "table";
- case function: return "function";
- case thread: return "thread";
+ case data: return "userdata";
+ case number: return "number";
+ case string: return "string";
+ case table: return "table";
+ case function: return "function";
+ case thread: return "thread";
}
return "?";
}
-
slot(const class script& s, int i = 0) :
index(i),
script_(const_cast<class script*>(&s)) {}
-
// check the type of the value
bool is_boolean() const
- { return (bool)lua_isboolean(script_->state_, index); }
+ {
+ return (bool)lua_isboolean(script_->state_, index);
+ }
bool is_imported_function() const
- { return (bool)lua_iscfunction(script_->state_, index); }
+ {
+ return (bool)lua_iscfunction(script_->state_, index);
+ }
bool is_function() const
- { return (bool)lua_isfunction(script_->state_, index); }
+ {
+ return (bool)lua_isfunction(script_->state_, index);
+ }
bool is_nil() const
- { return (bool)lua_isnil(script_->state_, index); }
+ {
+ return (bool)lua_isnil(script_->state_, index);
+ }
bool is_none() const
- { return (bool)lua_isnone(script_->state_, index); }
+ {
+ return (bool)lua_isnone(script_->state_, index);
+ }
bool is_none_or_nil() const
- { return (bool)lua_isnoneornil(script_->state_, index); }
+ {
+ return (bool)lua_isnoneornil(script_->state_, index);
+ }
bool is_number() const
- { return (bool)lua_isnumber(script_->state_, index); }
+ {
+ return (bool)lua_isnumber(script_->state_, index);
+ }
bool is_string() const
- { return (bool)lua_isstring(script_->state_, index); }
+ {
+ return (bool)lua_isstring(script_->state_, index);
+ }
bool is_table() const
- { return (bool)lua_istable(script_->state_, index); }
+ {
+ return (bool)lua_istable(script_->state_, index);
+ }
bool is_thread() const
- { return (bool)lua_isthread(script_->state_, index); }
+ {
+ return (bool)lua_isthread(script_->state_, index);
+ }
bool is_data() const
- { return (bool)lua_isuserdata(script_->state_, index); }
+ {
+ return (bool)lua_isuserdata(script_->state_, index);
+ }
bool is_light_data() const
- { return (bool)lua_islightuserdata(script_->state_, index); }
+ {
+ return (bool)lua_islightuserdata(script_->state_, index);
+ }
/**
* Check the value and throw an error if its the wrong type.
return *this;
}
- const slot& require_boolean(const std::string& what = "boolean") const
+ const slot&
+ require_boolean(const std::string& what = "boolean") const
{
if (!is_boolean()) raise_type_error(what);
return *this;
}
- const slot& require_number(const std::string& what = "number") const
+ const slot&
+ require_number(const std::string& what = "number") const
{
if (!is_number()) raise_type_error(what);
return *this;
}
- const slot& require_string(const std::string& what = "string") const
+ const slot&
+ require_string(const std::string& what = "string") const
{
if (!is_string()) raise_type_error(what);
return *this;
}
- const slot& require_table(const std::string& what = "table") const
+ const slot&
+ require_table(const std::string& what = "table") const
{
if (!is_table()) raise_type_error(what);
return *this;
}
- const slot& require_function(const std::string& what = "function") const
+ const slot&
+ require_function(const std::string& what = "function") const
{
if (!is_function()) raise_type_error(what);
return *this;
}
- const slot& require_data(const std::string& what = "userdata") const
+ const slot&
+ require_data(const std::string& what = "userdata") const
{
if (!is_data()) raise_type_error(what);
return *this;
}
- const slot& require_nil(const std::string& what = "nil") const
+ const slot&
+ require_nil(const std::string& what = "nil") const
{
if (!is_nil()) raise_type_error(what);
return *this;
}
- const slot& require_thread(const std::string& what = "thread") const
+ const slot&
+ require_thread(const std::string& what = "thread") const
{
if (!is_thread()) raise_type_error(what);
return *this;
}
template <class T>
- const slot& require_object(const std::string& what = typeid(T).name()) const
+ const slot&
+ require_object(const std::string& what = typeid(T).name()) const
{
if (!is_data()) raise_type_error(what);
return *this;
}
-
/**
* Get the type of the value.
*/
*/
std::string type_name() const
{
- if (is_none()) return "none";
+ if (is_none())
+ {
+ return "none";
+ }
else if (is_data() && !is_light_data())
{
slot metatable = push_metatable();
return luaL_typename(script_->state_, index);
}
-
/**
- * Get the length of the value according to the definition given by
- * Lua.
+ * Get the length of the value according to the definition
+ * given by Lua.
*/
size_t size() const
{
return lua_objlen(script_->state_, index);
}
-
size_t length() const
{
return size();
int positive_index() const
{
- if (index < 0) return index + lua_gettop(script_->state_) + 1;
- else return index;
+ if (index < 0)
+ return index + lua_gettop(script_->state_) + 1;
+ else
+ return index;
}
-
/**
* Get a pointer value (for userdata, tables, threads, and
* functions).
return !is_none();
}
-
bool operator == (const slot& rhs) const
{
- return (bool)lua_equal(script_->state_, index, rhs.index);
+ return (bool)lua_equal(script_->state_,
+ index, rhs.index);
}
bool operator < (const slot& rhs) const
{
- return (bool)lua_lessthan(script_->state_, index, rhs.index);
+ return (bool)lua_lessthan(script_->state_,
+ index, rhs.index);
}
-
/**
* Convert the underlying value to a C++ type.
*/
array.clear();
slot value = (*script_)[-1];
- int realIndex = positive_index();
+ int realIndex = positive_index();
bool done = false;
for (int i = 1; !done; ++i)
lua_rawgeti(script_->state_, realIndex, i);
T v;
- if (value.get(v)) array.push_back(v);
- else done = true;
+ if (value.get(v))
+ array.push_back(v);
+ else
+ done = true;
script_->pop();
}
slot key = (*script_)[-2];
slot value = (*script_)[-1];
- int realIndex = positive_index();
+ int realIndex = positive_index();
script_->push_nil();
while (lua_next(script_->state_, realIndex) != 0)
return ret;
}
-
template <class T, class V>
void set_field(const T& field, const V& value)
{
lua_settable(script_->state_, index);
}
-
void set_field(const std::string& field)
{
set_field(field.c_str());
lua_setfield(script_->state_, index, field);
}
-
template <class T>
void set_field(const std::string& field, const T& value)
{
set();
}
-
void remove()
{
lua_remove(script_->state_, index);
*/
void pop()
{
- if (index < 0) script_->pop(-index);
- else script_->pop(script_->stack_size() - index + 1);
+ if
+ (index < 0) script_->pop(-index);
+ else
+ script_->pop(script_->stack_size() -
+ index + 1);
}
/**
lua_insert(script_->state_, index);
}
-
/**
* Copy the value and push the copy to the stack.
*/
return script_->top();
}
-
slot push_field() const
{
lua_gettable(script_->state_, index);
return script_->top();
}
-
class script& script()
{
return *script_;
return *script_;
}
-
/**
- * Throw an exception with a message formatted to communicate a
- * type mismatch with the argument represented by this slot.
+ * Throw an exception with a message formatted to communicate
+ * a type mismatch with the argument represented by this slot.
*/
int raise_type_error(const std::string& expected) const
{
return 0;
}
-
private:
mutable class script* script_;
};
-
script() :
state_(0)
{
destroy();
}
-
static script_ptr alloc()
{
return script_ptr(new script);
state_ = luaL_newstate();
}
-
void import_standard_libraries()
{
luaL_openlibs(state_);
push(LUA_COLIBNAME);
call(1, 0);
}
-
void import_package_library()
{
push(luaopen_package);
push(LUA_LOADLIBNAME);
call(1, 0);
}
-
void import_string_library()
{
push(luaopen_string);
push(LUA_STRLIBNAME);
call(1, 0);
}
-
void import_table_library()
{
push(luaopen_table);
push(LUA_TABLIBNAME);
call(1, 0);
}
-
void import_math_library()
{
push(luaopen_math);
push(LUA_MATHLIBNAME);
call(1, 0);
}
-
void import_io_library()
{
push(luaopen_io);
push(LUA_IOLIBNAME);
call(1, 0);
}
-
void import_os_library()
{
push(luaopen_os);
push(LUA_OSLIBNAME);
call(1, 0);
}
-
void import_debug_library()
{
push(luaopen_debug);
call(1, 0);
}
-
- void import_function(const std::string& name, const function& function)
+ void
+ import_function(const std::string& name, const function& function)
{
push(function);
lua_setglobal(state_, name.c_str());
return status(luaL_dofile(state_, file.c_str()));
}
-
/*
* Thread-handling methods.
*/
return is_main;
}
-
/**
* Throw an error with the value at the top of the stack. If this is
* called from an imported function, the error will be caught and
return 0;
}
-
/*
* Get significant values.
*/
{
return slot(*this, globals_index);
}
-
slot registry() const
{
return slot(*this, registry_index);
}
-
slot environment() const
{
return slot(*this, environment_index);
}
-
slot top() const
{
return slot(*this, stack_size());
}
-
/**
* Set the size of the stack.
* \param size The stack size.
stack_size(0);
}
-
/**
* Makes sure there is at least extra more places on the stack.
* Returns false if space couldn't be created. Just like with the
return (bool)lua_checkstack(state_, extra);
}
-
/**
* Concatenates the top-most n slots on the stack.
*/
lua_concat(state_, n);
}
-
/*
* Push some values onto the stack.
*/
}
slot push_code(const std::string& name,
- const char* buffer,
- size_t size,
- status& result)
+ const char* buffer, size_t size, status& result)
{
result = status(luaL_loadbuffer(state_,
- buffer, size, name.c_str()));
+ buffer, size, name.c_str()));
return top();
}
template <class T>
slot push_pointer(const T* ptr)
{
- lua_pushlightuserdata(state_, const_cast<void*>((const void*)ptr));
+ lua_pushlightuserdata(state_,
+ const_cast<void*>((const void*)ptr));
return top();
}
slot push_pointer(cfunction function)
return push_pointer(&typeid(T));
}
-
/**
* Call a function on the stack. The correct procedure is to push a
* function onto the stack followed by nargs arguments. This method
return status(lua_pcall(state_, nargs, nresults, 0));
}
-
/**
* Pops n values from the top of the stack.
*/
lua_pop(state_, n);
}
-
/**
* Index into the stack to get a slot.
*/
return slot(*this, index);
}
-
/*
* Control over the garbage collection process.
*/
lua_gc(state_, LUA_GCSETSTEPMUL, step);
}
-
private:
script(lua_State* state) :
slot metatable = push_metatable(typeid(T).name(), is_new);
if (is_new)
{
- metatable.push_copy(); // class behavior
+ metatable.push_copy(); // class behavior
metatable.set_field("__index");
-
push_type<T>();
metatable.set_field("__cxxtype"); // type_info
-
push(object_finalizer_<T>);
metatable.set_field("__gc"); // finalizer
-
//push(object_tostring_<T>);
//metatable.set_field("__tostring"); // tostring
}
{
std::ostringstream stream;
stream << *reinterpret_cast<T*>(lua_touserdata(state, 1));
- lua_pushlstring(state, stream.str().c_str(), stream.str().length());
+ lua_pushlstring(state,
+ stream.str().c_str(), stream.str().length());
return 1;
}
}
}
-
static int call_function(lua_State* state)
{
cfunction function = (cfunction)lua_touserdata(state,
}
}
-
void destroy()
{
if (is_main_thread()) lua_close(state_);
}
-
lua_State* state_;
};
using namespace std::rel_ops;
-
/**
* Output a script value to a stream.
*/
-inline std::ostream& operator << (std::ostream& stream,
- const script::slot& slot)
+inline std::ostream&
+operator << (std::ostream& stream, const script::slot& slot)
{
std::string str;
bool boolean;
else if (slot.get(boolean))
{
if (boolean) stream << "true";
- else stream << "false";
+ else stream << "false";
}
else if (slot.is_nil())
{
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include "service.hh"
#include "socket.hh"
-
-#define SOLICIT 0x1234ABCD
-#define RESPONSE 0xABCD1234
+#define SOLICIT 0x1234ABCD
+#define RESPONSE 0xABCD1234
namespace moof {
int service::handle_packet(socket_multiplexer& mux,
- packet& packet,
- const socket::address& address)
+ packet& packet, const socket::address& address)
{
try
{
}
}
}
- catch (...) {}
+ catch (...)
+ {
+ }
return -1;
}
int service_finder::handle_packet(socket_multiplexer& mux,
- packet& packet,
- const socket::address& address)
+ packet& packet, const socket::address& address)
{
try
{
}
}
}
- catch (...) {}
+ catch (...)
+ {
+ }
return -1;
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_SERVICE_HH_
#define _MOOF_SERVICE_HH_
const std::string& name,
const std::string& text);
-
/**
* Publish the service on the network.
*/
*/
void stop();
-
/**
* Get the host address.
* \return The address.
return text_;
}
-
~service();
-
private:
int handle_packet(socket_multiplexer& mux,
- packet& packet,
- const socket::address& address);
+ packet& packet, const socket::address& address);
socket::address address_;
- std::string type_;
- std::string name_;
- std::string text_;
+ std::string type_;
+ std::string name_;
+ std::string text_;
};
* \param sockType The type of socket.
*/
explicit service_finder(const std::string& type,
- int sockType = SOCK_STREAM);
-
+ int sockType = SOCK_STREAM);
const std::map<std::string,service>& services() const
{
return services_;
}
-
private:
int handle_packet(socket_multiplexer& mux,
- packet& packet,
- const socket::address& address);
+ packet& packet, const socket::address& address);
- std::string type_;
+ std::string type_;
std::map<std::string,service> services_;
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <stlplus/portability/file_system.hpp>
save();
}
-
void settings::parse_args(int argc, char* argv[])
{
for (int i = 1; i < argc; ++i)
}
}
-
void settings::load_files(const std::string& path)
{
std::vector<std::string> paths;
boost::split(paths, path, boost::is_any_of(":"));
-
load_files(paths);
}
boost::replace_all(*it, "$HOME", home);
//logDebug("Copying global settings...");
- //mUserFile = *it;
+ //userfile_ = *it;
//mGlobals.push_copy();
//script_.set("globals", script::registry_index);
}
-
if (script_.do_file(*it) != script::success)
{
std::string str;
}
}
-
void settings::clear()
{
script_.reset();
}
-
void settings::save_as(const std::string& path)
{
- mUserFile = path;
+ userfile_ = path;
save();
}
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_SETTINGS_HH_
#define _MOOF_SETTINGS_HH_
public:
settings(int argc, char* argv[], const std::string& path);
-
~settings();
void parse_args(int argc, char* argv[]);
void load_files(const std::string& path);
void load_files(const std::vector<std::string>& path);
-
/**
* Remove all settings.
*/
void save_as(const std::string& path);
void save() const;
-
/**
* Get a setting by name.
* \param key The name of the setting.
template <class T>
bool get(const std::string& key, T& value) const;
-
private:
mutable script script_;
-
- std::string mUserFile;
+ std::string userfile_;
};
-
template <class T>
bool settings::get(const std::string& key, T& value) const
{
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_SHAPE_HH_
#define _MOOF_SHAPE_HH_
#include <moof/opengl.hh>
#include <moof/ray.hh>
-
// frustum
// plane (can construct from triangle2)
// ray
// shape<>
// +- line<>
-// - line2 line<2>
-// - line3 line<3>
+// - line2 line<2>
+// - line3 line<3>
// +- sphere<>
// | sphere2, circle sphere<2>
-// | sphere3 sphere<3>
+// | sphere3 sphere<3>
// +- aabb<>
// | aabb2, rectangle aabb<2>
-// | aabb3 aabb<3>
+// | aabb3 aabb<3>
// +- polygon<>
-// | triangle2 polygon<2,3>
-// | triangle3 polygon<3,3>
+// | triangle2 polygon<2,3>
+// | triangle3 polygon<3,3>
namespace moof {
* returned if there is no contact.
*/
virtual bool intersect_ray(const ray<D>& ray,
- typename moof::ray<D>::contact& hit) const
+ typename moof::ray<D>::contact& hit) const
{
return false;
}
};
-
-typedef shape<2> shape2;
-typedef shape<3> shape3;
+typedef shape<2> shape2;
+typedef shape<3> shape3;
} // namespace moof
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <deque>
#include <stdexcept>
#include "thread.hh"
#include "timer.hh"
-
#ifndef BUF_SIZE
-#define BUF_SIZE (4096)
+#define BUF_SIZE 8192
#endif
-#define NUM_SAMPLE_BITS (16)
+#define NUM_SAMPLE_BITS 16
namespace moof {
thread stream_thread_;
-/*] Sound backend
- *************************************************************************/
-
class sound_backend
{
public:
if (!al_device || !al_context)
{
const char* error = alcGetString(al_device,
- alcGetError(al_device));
+ alcGetError(al_device));
log_error("audio subsystem initialization failure", error);
}
else
{
alcMakeContextCurrent(al_context);
- log_info << "opened sound device `"
- << alcGetString(al_device,
- ALC_DEFAULT_DEVICE_SPECIFIER)
- << "'" << std::endl;
+ log_info << "opened sound device `" <<
+ alcGetString(al_device, ALC_DEFAULT_DEVICE_SPECIFIER) <<
+ "'" << std::endl;
}
}
}
-
sound_backend(const sound_backend& backend)
{
++retain_count;
}
- sound_backend& operator=(const sound_backend& backend)
+ sound_backend& operator = (const sound_backend& backend)
{
++retain_count;
return *this;
}
}
-
- static int retain_count;
+ static int retain_count;
static ALCdevice* al_device;
static ALCcontext* al_context;
};
-int sound_backend::retain_count = 0;
+int sound_backend::retain_count = 0;
ALCdevice* sound_backend::al_device;
ALCcontext* sound_backend::al_context;
-
class sound_resource;
typedef resource_handle<sound_resource> sound_handle;
MOOF_REGISTER_RESOURCE(sound_resource, ogg, sounds);
-/*] Sound resource
- *************************************************************************/
-
class sound_resource : public boost::noncopyable
{
public:
sample_(0)
{
if (ov_fopen((char*)path.c_str(), &file_) < 0)
- {
- throw std::runtime_error("problem reading audio: " + path);
- }
+ throw std::runtime_error("problem reading audio: " +
+ path);
}
~sound_resource()
if (buffer_) alDeleteBuffers(1, &buffer_);
}
-
ALuint read_all() const
{
if (buffer_) return buffer_;
while (size < sizeof(data))
{
int section;
- int result = ov_read(&file_,
- data + size, sizeof(data) - size,
- 0, 2, 1, §ion);
+ int result = ov_read(&file_, data + size,
+ sizeof(data) - size, 0, 2, 1, §ion);
if (0 < result)
{
ALuint buffer;
alGenBuffers(1, &buffer);
alBufferData(buffer, get_audio_format(info),
- data, size, info->rate);
+ data, size, info->rate);
buffer_ = buffer;
return buffer;
break;
}
}
-
return AL_NONE;
}
{
if ((sample == sample_ && ov_pcm_seek_lap(&file_, sample) != 0) ||
(sample != sample_ && ov_pcm_seek(&file_, sample) != 0))
- {
return false;
- }
- char data[BUF_SIZE];
+ char data[BUF_SIZE];
int section;
- int result = ov_read(&file_, data, sizeof(data), 0, 2, 1, §ion);
+ int result = ov_read(&file_, data, sizeof(data),
+ 0, 2, 1, §ion);
if (0 < result)
{
sample_ = sample = ov_pcm_tell(&file_);
return true;
}
- else if (result < 0) log_warning("vorbis playback error");
-
+ else if (result < 0)
+ {
+ log_warning("vorbis playback error");
+ }
return false;
}
{
ov_crosslap(&other->file_, &file_);
- char data[BUF_SIZE];
+ char data[BUF_SIZE];
int section;
- int result = ov_read(&file_, data, sizeof(data), 0, 2, 1, §ion);
+ int result = ov_read(&file_, data, sizeof(data),
+ 0, 2, 1, §ion);
if (0 < result)
{
vorbis_info* info = ov_info(&file_, section);
alBufferData(buffer, get_audio_format(info),
- data, result, info->rate);
+ data, result, info->rate);
sample_ = sample = ov_pcm_tell(&file_);
return true;
}
- else if (result < 0) log_warning("vorbis playback error");
-
+ else if (result < 0)
+ {
+ log_warning("vorbis playback error");
+ }
return false;
}
-
- // determines the correct number of fixed-size buffers needed to hold a
- // given number of seconds of PCM audio.
+ // determines the correct number of fixed-size buffers needed to hold
+ // a given number of seconds of PCM audio.
int num_buffers(scalar seconds) const
{
vorbis_info* info = ov_info(&file_, -1);
int count = scalar(info->rate) * // sample rate
- scalar(info->channels) * // channels
- scalar(NUM_SAMPLE_BITS) * // sample size
- seconds * // time
- SCALAR(0.125) / // bits to bytes
- scalar(BUF_SIZE); // individual buffer size
+ scalar(info->channels) * // channels
+ scalar(NUM_SAMPLE_BITS) * // sample size
+ seconds * // time
+ SCALAR(0.125) / // bits to bytes
+ scalar(BUF_SIZE); // individual buffer size
return count;
}
-
static ALenum get_audio_format(const vorbis_info* info)
{
- if (info->channels == 1) return AL_FORMAT_MONO16;
- else if (info->channels == 2) return AL_FORMAT_STEREO16;
+ if (info->channels == 1)
+ return AL_FORMAT_MONO16;
+ else if (info->channels == 2)
+ return AL_FORMAT_STEREO16;
log_error("unsupported number of channels:", info->channels);
return 0;
}
-
private:
mutable OggVorbis_File file_;
- mutable ALuint buffer_;
- mutable uint64_t sample_;
+ mutable ALuint buffer_;
+ mutable uint64_t sample_;
- sound_backend backend_;
+ sound_backend backend_;
};
-/*] Sound class
- *************************************************************************/
-
class sound::impl
{
public:
alSourceUnqueueBuffers(source_, queued, buffers);
alDeleteBuffers(queued, buffers);
}
- else alSourcei(source_, AL_BUFFER, AL_NONE);
+ else
+ {
+ alSourcei(source_, AL_BUFFER, AL_NONE);
+ }
}
void play()
alGetSourcei(source_, AL_SOURCE_STATE, &state);
switch (state)
{
- case AL_INITIAL:
- case AL_STOPPED:
-
- if (is_streaming_)
- {
- start_update_timer();
- num_buffers_ = queue_.front()->num_buffers(buffer_size_);
- fill_stream();
- is_playing_ = true;
- alSourcei(source_, AL_LOOPING, false);
- }
- else
- {
- ALuint buffer = queue_.front()->read_all();
- alSourcei(source_, AL_BUFFER, buffer);
- alSourcei(source_, AL_LOOPING, is_looping_);
- }
- break;
+ case AL_INITIAL:
+ case AL_STOPPED:
+ if (is_streaming_)
+ {
+ start_update_timer();
+ num_buffers_ = queue_.front()->num_buffers(buffer_size_);
+ fill_stream();
+ is_playing_ = true;
+ alSourcei(source_, AL_LOOPING, false);
+ }
+ else
+ {
+ ALuint buffer = queue_.front()->read_all();
+ alSourcei(source_, AL_BUFFER, buffer);
+ alSourcei(source_, AL_LOOPING, is_looping_);
+ }
+ break;
- case AL_PAUSED:
-
- if (is_streaming_)
- {
- start_update_timer();
- is_playing_ = true;
- }
- break;
+ case AL_PAUSED:
+ if (is_streaming_)
+ {
+ start_update_timer();
+ is_playing_ = true;
+ }
+ break;
}
alSourcePlay(source_);
}
-
void start_update_timer()
{
- stream_timer_.init(boost::bind(&impl::stream_update, this, _1, _2),
- SCALAR(0.1), timer::repeat);
+ stream_timer_.init(boost::bind(&impl::stream_update,
+ this, _1, _2),
+ SCALAR(0.1), timer::repeat);
+
+ thread::main_runloop().add_timer(stream_timer_);
//thread thread;
//thread.runloop().add_timer(stream_timer_);
- if (!stream_thread_.is_valid())
- {
- stream_thread_ = thread::detach(stream_timer_);
- }
+ //if (!stream_thread_.is_valid())
+ //stream_thread_ = thread::detach(stream_timer_);
+ // FIXME: proper locking needs to be done; this is causing crashes
+ // on shutdown when sound resources are destroyed yet the stream
+ // thread is neither shutdown or notified.
}
void fill_stream()
alGetSourcei(source_, AL_BUFFERS_QUEUED, &queued);
alGetSourcei(source_, AL_BUFFERS_PROCESSED, &processed);
- int target_diff = num_buffers_ - queued + processed;
+ int target_diff = num_buffers_ - queued + processed;
ALuint bufs[processed];
alSourceUnqueueBuffers(source_, processed, bufs);
if (0 < target_diff)
{
- if (queue_buffer(buf)) --target_diff;
+ if (queue_buffer(buf))
+ {
+ --target_diff;
+ }
else
{
alDeleteBuffers(processed - i - 1, &bufs[i+1]);
}
}
+ // TODO: this function is ugly
bool queue_buffer(ALuint buffer)
{
if (buffer == AL_NONE) alGenBuffers(1, &buffer);
queue_.push_back(sound);
looped_once = true;
}
- else break;
+ else
+ {
+ break;
+ }
}
}
return false;
}
-
void stop()
{
alSourceStop(source_);
stream_timer_.invalidate();
}
-
void sample(const std::string& name)
{
stop();
is_streaming_ = true;
}
-
bool is_playing() const
{
ALenum state;
alGetSourcei(source_, AL_SOURCE_STATE, &state);
if (state == AL_PLAYING) return true;
- else return is_playing_;
+ else return is_playing_;
}
-
void loop(bool looping)
{
is_looping_ = looping;
ALenum type;
alGetSourcei(source_, AL_SOURCE_TYPE, &type);
if (type != AL_STREAMING)
- {
alSourcei(source_, AL_LOOPING, is_looping_);
- }
}
-
void stream_update(timer& timer, scalar t)
{
log_debug("blaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhrrrrrg");
fill_stream();
}
+ ALuint source_;
- ALuint source_;
-
- bool is_playing_;
- bool is_looping_;
- bool is_streaming_;
+ bool is_playing_;
+ bool is_looping_;
+ bool is_streaming_;
std::deque<sound_handle> queue_;
- uint64_t sample_;
- int num_buffers_;
- scalar buffer_size_;
+ uint64_t sample_;
+ int num_buffers_;
+ scalar buffer_size_;
- timer stream_timer_;
+ timer stream_timer_;
- sound_backend backend_;
+ sound_backend backend_;
};
// pass through
impl_(new sound::impl(path)) {}
-
void sound::sample(const std::string& path)
{
// pass through
impl_->queue(path);
}
-
void sound::play()
{
// pass through
impl_->buffer_size_ = seconds;
}
-
void sound::position(const vector3& position)
{
float vec[3] = {position[0], position[1], position[2]};
impl_->loop(looping);
}
-
void sound::listener_position(const vector3& position)
{
float vec[] = {position[0], position[1], position[2]};
}
void sound::listener_orientation(const vector3& forward,
- const vector3& up)
+ const vector3& up)
{
float vec[6];
vec[0] = float(forward[0]);
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_SOUND_HH_
#define _MOOF_SOUND_HH_
/**
* \file sound.hh
- * Load and play sounds, current supports ogg vorbis.
+ * Load and play sounds, currently supports ogg vorbis.
*/
#include <string>
namespace moof {
+// forward declarations
class script;
-
class sound
{
public:
void pitch(scalar pitch);
void loop(bool looping);
-
static void listener_position(const vector3& position);
static void listener_velocity(const vector3& velocity);
- static void listener_orientation(const vector3& forward,
- const vector3& up);
+ static void listener_orientation(const vector3& forward, const vector3& up);
static void import(script& script, const std::string& nspace = "");
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include "script.hh"
#include "sound.hh"
return 1;
}
-
void sound::import(script& script, const std::string& nspace)
{
script.check_stack(4);
script::slot parent = script.push_table(nspace);
script::slot meta = script.push_class<sound>(sound_new);
- meta.set_field("sample", sound_sample);
- meta.set_field("queue", sound_queue);
+ meta.set_field("is_playing", sound_is_playing);
+ meta.set_field("pause", sound_pause);
meta.set_field("play", sound_play);
+ meta.set_field("queue", sound_queue);
+ meta.set_field("sample", sound_sample);
meta.set_field("stop", sound_stop);
- meta.set_field("pause", sound_pause);
meta.set_field("toggle", sound_toggle);
- meta.set_field("is_playing", sound_is_playing);
parent.set_field("sound");
parent.pop();
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_SPHERE_HH_
#define _MOOF_SPHERE_HH_
vector point;
scalar radius;
-
sphere() {}
sphere(const vector& p, scalar r) :
point(p),
radius(r) {}
-
void init(const vector& p, scalar r)
{
point = p;
return true;
}
-
bool intersect(const sphere<D>& sphere, contact<D>& hit) const
{
vector n = sphere.point - point;
// a ray inside the sphere will not intersect on its way out
bool intersect(const ray<D>& ray,
- typename moof::ray<D>::contact& hit) const
+ typename moof::ray<D>::contact& hit) const
{
vector b = point - ray.point;
scalar z = dot(b, ray.direction);
}
};
+typedef sphere<2> circle;
+typedef sphere<2> sphere2;
+typedef sphere<3> sphere3;
+
template <>
-inline bool sphere<3>::is_visible(const frustum& frustum) const
+inline bool sphere3::is_visible(const frustum& frustum) const
{
return frustum.contains(*this);
}
template <>
-inline void sphere<2>::draw(scalar alpha) const
+inline void sphere2::draw(scalar alpha) const
{
GLUquadricObj* sphereObj = gluNewQuadric();
gluQuadricDrawStyle(sphereObj, GLU_LINE);
}
template <>
-inline void sphere<3>::draw(scalar alpha) const
+inline void sphere3::draw(scalar alpha) const
{
GLUquadricObj* sphereObj = gluNewQuadric();
gluQuadricDrawStyle(sphereObj, GLU_LINE);
}
-typedef sphere<2> sphere2;
-typedef sphere2 circle;
-typedef sphere<3> sphere3;
-
-
} // namespace moof
#endif // _MOOF_SPHERE_HH_
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <cstdio> // FILE
#include <cstring> // strncmp
image_ = sprite.image_;
}
-
void sprite::image(const std::string& name)
{
image_ = resource::load(name, "png");
if (image_) image_->tile_coordinates(tile, tile_);
}
-
void sprite::bind() const
{
if (image_) image_->bind();
image::reset_binding();
}
-
void sprite::draw(const vector3 vertices[4]) const
{
bind();
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
-
/*
void min_filter(GLuint filter)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT);
}
-
bool sprite::tile_coordinates(int index, scalar coords[8],
orientation orientation) const
{
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_SPRITE_HH_
#define _MOOF_SPRITE_HH_
void draw(const vector3 vertices[4]) const;
-
private:
image_handle image_;
- scalar tile_[8];
+ scalar tile_[8];
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include <stdexcept>
if (sizeof(wchar_t) == 2)
{
- size_t length = multi.length();
- buffer wide(new wchar_t[length + 1]);
- const UTF8* src1 = (const UTF8*)multi.c_str();
- const UTF8* src2 = src1 + length;
- UTF16* dst1 = (UTF16*)wide.get();
- UTF16* dst2 = dst1 + length+1;
+ size_t length = multi.length();
+ buffer wide(new wchar_t[length + 1]);
+ const UTF8* src1 = (const UTF8*)multi.c_str();
+ const UTF8* src2 = src1 + length;
+ UTF16* dst1 = (UTF16*)wide.get();
+ UTF16* dst2 = dst1 + length + 1;
if (ConvertUTF8toUTF16(&src1, src2,
- &dst1, dst2, lenientConversion) != conversionOK)
- {
+ &dst1, dst2,
+ lenientConversion) != conversionOK)
throw std::runtime_error("bad string conversion");
- }
*dst1 = 0;
wstring str(wide.get());
}
else if (sizeof(wchar_t) == 4)
{
- size_t length = multi.length();
- buffer wide(new wchar_t[length + 1]);
- const UTF8* src1 = (const UTF8*)multi.c_str();
- const UTF8* src2 = src1 + length;
- UTF32* dst1 = (UTF32*)wide.get();
- UTF32* dst2 = dst1 + length+1;
+ size_t length = multi.length();
+ buffer wide(new wchar_t[length + 1]);
+ const UTF8* src1 = (const UTF8*)multi.c_str();
+ const UTF8* src2 = src1 + length;
+ UTF32* dst1 = (UTF32*)wide.get();
+ UTF32* dst2 = dst1 + length + 1;
if (ConvertUTF8toUTF32(&src1, src2,
- &dst1, dst2, lenientConversion) != conversionOK)
- {
+ &dst1, dst2,
+ lenientConversion) != conversionOK)
throw std::runtime_error("bad string conversion");
- }
*dst1 = 0;
wstring str(wide.get());
if (sizeof(wchar_t) == 2)
{
- size_t length = wide.length();
- size_t multi_length = 3 * length + 1;
- buffer multi(new char[multi_length]);
+ size_t length = wide.length();
+ size_t multi_length = 3 * length + 1;
+ buffer multi(new char[multi_length]);
const UTF16* src1 = (const UTF16*)wide.c_str();
const UTF16* src2 = src1 + length;
- UTF8* dst1 = (UTF8*)multi.get();
- UTF8* dst2 = dst1 + multi_length;
+ UTF8* dst1 = (UTF8*)multi.get();
+ UTF8* dst2 = dst1 + multi_length;
if (ConvertUTF16toUTF8(&src1, src2,
- &dst1, dst2, lenientConversion) != conversionOK)
- {
+ &dst1, dst2,
+ lenientConversion) != conversionOK)
throw std::runtime_error("bad string conversion");
- }
*dst1 = 0;
string str(multi.get());
}
else if (sizeof(wchar_t) == 4)
{
- size_t length = wide.length();
- size_t multi_length = 4 * length + 1;
- buffer multi(new char[multi_length]);
+ size_t length = wide.length();
+ size_t multi_length = 4 * length + 1;
+ buffer multi(new char[multi_length]);
const UTF32* src1 = (const UTF32*)wide.c_str();
const UTF32* src2 = src1 + length;
- UTF8* dst1 = (UTF8*)multi.get();
- UTF8* dst2 = dst1 + multi_length;
+ UTF8* dst1 = (UTF8*)multi.get();
+ UTF8* dst2 = dst1 + multi_length;
if (ConvertUTF32toUTF8(&src1, src2,
- &dst1, dst2, lenientConversion) != conversionOK)
- {
+ &dst1, dst2,
+ lenientConversion) != conversionOK)
throw std::runtime_error("bad string conversion");
- }
*dst1 = 0;
string str(multi.get());
}
-static script& regex_script()
+static script& pattern_script()
{
static script script;
- static bool init = true;
+ static bool init = true;
if (init)
{
script.import_string_library();
return script;
}
-
-regex::regex(const string& pattern)
+pattern::pattern(const std::string& pattern)
{
- regex::pattern(pattern);
+ pattern::string(pattern);
}
-regex::regex(const string& pattern, const string& source)
+pattern::pattern(const std::string& pattern, const std::string& source)
{
- regex::pattern(pattern);
+ pattern::string(pattern);
match(source);
}
-regex::~regex()
+pattern::~pattern()
{
- script& script = regex_script();
-
+ script& script = pattern_script();
script.push_pointer(this);
script.push_nil();
script.globals().set_field();
script.registry().set_field();
}
-
-string regex::pattern() const
+std::string pattern::string() const
{
- script& script = regex_script();
+ script& script = pattern_script();
script.push_pointer(this);
script::slot saved = script.registry().push_field();
- string pattern;
+ std::string pattern;
saved.get(pattern);
saved.pop();
return pattern;
}
-void regex::pattern(const string& pattern)
+void pattern::string(const std::string& pattern)
{
- script& script = regex_script();
+ script& script = pattern_script();
script.push_pointer(this);
script.push(pattern);
script.registry().set_field();
}
-
-void regex::match(const string& source)
+void pattern::match(const std::string& source)
{
- script& script = regex_script();
+ script& script = pattern_script();
script.push_pointer(this);
script.globals().push_field("gmatch");
script.globals().set_field();
}
-bool regex::get(string& match)
+bool pattern::get(std::string& match)
{
- script& script = regex_script();
+ script& script = pattern_script();
script.push_pointer(this);
script::slot value = script.globals().push_field();
if (!value.is_function())
return result;
}
-bool regex::get(std::vector<string>& captures)
+bool pattern::get(std::vector<std::string>& captures)
{
- script& script = regex_script();
+ script& script = pattern_script();
script.push_pointer(this);
script::slot value = script.globals().push_field();
if (!value.is_function())
return 0 < captures.size();
}
-
-bool regex::match(string& match,
- const string& pattern,
- const string& source,
- int position)
+bool pattern::match(std::string& match,
+ const std::string& pattern, const std::string& source, int position)
{
- script& script = regex_script();
-
+ script& script = pattern_script();
script::slot value = script.globals().push_field("match");
script.push(source);
script.push(pattern);
- ++position; // Lua indices count from one.
+ ++position; // lua indices count from one
script.push(position);
script.call(3, 1);
return result;
}
-bool regex::match(std::vector<string>& captures,
- const string& pattern,
- const string& source,
- int position)
+bool pattern::match(std::vector<std::string>& captures,
+ const std::string& pattern, const std::string& source, int position)
{
- script& script = regex_script();
-
+ script& script = pattern_script();
script::slot value = script.globals().push_field("match");
script.push(source);
script.push(pattern);
- ++position; // Lua indices count from one.
+ ++position; // lua indices count from one
script.push(position);
script.call(3);
return 0 < captures.size();
}
-
-int regex::sub(string& substitution,
- const string& pattern,
- const string& source,
- const string& replacement)
+int pattern::sub(std::string& substitution,
+ const std::string& pattern,
+ const std::string& source, const std::string& replacement)
{
- script& script = regex_script();
-
+ script& script = pattern_script();
script::slot value = script.globals().push_field("gsub");
script.push(source);
script.push(pattern);
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_STRING_HH_
#define _MOOF_STRING_HH_
using std::string;
using std::wstring;
-
/**
* Convert a multi-byte (UTF-8) string to a wide string.
* \param multi The multi-byte string to convert.
* Class exposing the pattern-matching and substitution methods used in
* Lua.
*/
-class regex : public boost::noncopyable
+class pattern : public boost::noncopyable
{
public:
/**
- * Construct a regex object.
+ * Construct a pattern object.
*/
- regex() {}
+ pattern() {}
/**
- * Construct a regex object with a pattern.
+ * Construct a pattern object with a pattern.
* \param pattern The pattern.
*/
- regex(const string& pattern);
+ pattern(const std::string& pattern);
/**
- * Construct a regex object with a pattern and source to match.
+ * Construct a pattern object with a pattern and source to match.
* \param pattern The pattern.
* \param source The source string.
*/
- regex(const string& pattern, const string& source);
+ pattern(const std::string& pattern, const std::string& source);
/**
- * Deconstruct the regex.
+ * Deconstruct the pattern.
*/
- ~regex();
-
+ ~pattern();
/**
- * Get the regex pattern.
+ * Get the pattern pattern.
*/
- string pattern() const;
+ std::string string() const;
/**
- * Set the regex pattern.
+ * Set the pattern string.
*/
- void pattern(const string& pattern);
-
+ void string(const std::string& pattern);
/**
* Match a string against the pattern iteratively.
* \param source The source string.
*/
- void match(const string& source);
+ void match(const std::string& source);
/**
* Get the next match. If the pattern contains captures, this version
* \param match Reference to a string to be assigned the match.
* \return True if there was a match to get, false otherwise.
*/
- bool get(string& match);
+ bool get(std::string& match);
/**
* Get the next match. Use this version if the pattern contains more
* \param captures Reference to a vector of strings to hold the result.
* \return True if there was a match to get, false otherwise.
*/
- bool get(std::vector<string>& captures);
-
+ bool get(std::vector<std::string>& captures);
/**
* Match a string against a pattern all at one time.
* \param position The index of the first character of source to match.
* \return The match.
*/
- static string match(const string& pattern,
- const string& source,
- int position = 0)
+ static std::string
+ match(const std::string& pattern, const std::string& source,
+ int position = 0)
{
- string match;
- regex::match(match, pattern, source, position);
+ std::string match;
+ pattern::match(match, pattern, source, position);
return match;
}
* \param position The index of the first character of source to match.
* \return True if a match was made, false otherwise.
*/
- static bool match(string& match,
- const string& pattern,
- const string& source,
- int position = 0);
+ static bool match(std::string& match, const std::string& pattern,
+ const std::string& source, int position = 0);
/**
* Match a string against a pattern all at one time. If the pattern
* \param position The index of the first character of source to match.
* \return True if a match was made, false otherwise.
*/
- static bool match(std::vector<string>& captures,
- const string& pattern,
- const string& source,
- int position = 0);
-
+ static bool match(std::vector<std::string>& captures, const std::string& pattern,
+ const std::string& source, int position = 0);
/**
* Substitute a string using a pattern and replacement string.
* references to captures.
* \return The string with any substitutions made.
*/
- static string sub(const string& pattern,
- const string& source,
- const string& replacement)
+ static std::string sub(const std::string& pattern,
+ const std::string& source, const std::string& replacement)
{
- string substitution;
- regex::sub(substitution, pattern, source, replacement);
+ std::string substitution;
+ pattern::sub(substitution, pattern, source, replacement);
return substitution;
}
* references to captures.
* \return The number of substitutions made.
*/
- static int sub(string& substitution,
- const string& pattern,
- const string& source,
- const string& replacement);
+ static int sub(std::string& substitution, const std::string& pattern,
+ const std::string& source, const std::string& replacement);
};
} // namespace moof
-#endif // _MOOF_STRINGTOOLS_HH_
+#endif // _MOOF_STRING_HH_
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#include "runloop.hh"
#include "thread.hh"
thread_(0),
runloop_(new moof::runloop) {}
-
thread thread::detach(const function& function)
{
thread* thread = new moof::thread;
return *thread;
}
-
void thread::spawn(thread* thread)
{
thread->thread_ = SDL_CreateThread(&thread::run, (void*)thread);
return code;
}
-
void thread::kill()
{
if (thread_)
}
}
-
moof::runloop& thread::runloop() const
{
return *runloop_;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_THREAD_HH_
#define _MOOF_THREAD_HH_
namespace moof {
+// forward declarations
class runloop;
typedef boost::shared_ptr<runloop> runloop_ptr;
-
/**
* Represents a thread which may be running. You cannot instantiate a
* thread object directly; new threads are created by detaching functions
typedef boost::function<int(thread&)> function;
-
/**
* Construct an invalid thread object which has no association with any
* real thread.
*/
thread();
-
/**
* Execute a function in a new thread.
* \param function The function to execute.
*/
static thread detach(timer& timer);
-
/**
* Wait for the thread to terminate, getting its return value. The
* thread will be invalidated.
return thread_ != 0;
}
-
/**
* Get a unique identifier for this thread, if it is valid.
* \return The identifier.
return SDL_ThreadID();
}
-
/**
* Get the thread's runloop.
* \return The thread's runloop.
*/
static moof::runloop& main_runloop();
-
private:
static void spawn(thread* thread);
static int run(void* arg);
-
- function function_;
- SDL_Thread* thread_;
- runloop_ptr runloop_;
+ function function_;
+ SDL_Thread* thread_;
+ runloop_ptr runloop_;
};
virtual int wait() = 0;
};
+
/**
* An asynchronous task that is run to be executed in a separated thread.
*/
* Get the thread object the task is executing in.
* \return The thread.
*/
- const class thread& thread() const { return thread_; }
+ const class thread& thread() const
+ {
+ return thread_;
+ }
/**
* Block the current thread until the task thread is finished.
return thread_.wait();
}
-
protected:
class thread thread_;
/**
* Construct a mutex.
*/
- mutex() :
+ mutex() :
mutex_(SDL_CreateMutex()) {}
/**
* Deconstruct a mutex.
*/
- ~mutex()
+ ~mutex()
{
SDL_DestroyMutex(mutex_);
}
-
/**
* Block until the calling thread can secure exclusive access to the
* code protected by the mutex.
* \return True if the lock was acquired, false otherwise.
* \see lock
*/
- bool acquire_lock()
+ bool acquire_lock()
{
- return (SDL_LockMutex(mutex_) == 0);
+ return SDL_LockMutex(mutex_) == 0;
}
/**
* \return True if the mutex was unlocked, false otherwise.
* \see lock
*/
- bool release_lock()
+ bool release_lock()
{
- return (SDL_UnlockMutex(mutex_) == 0);
+ return SDL_UnlockMutex(mutex_) == 0;
}
-
/**
* As an alternative method for locking, objects of this class will
* automagically release the lock if it is still locked at
* deconstruction. Therefore, it's generally safer to use this method
* since it makes it much more difficult to forget to unlock a mutex.
*/
- class lock
- {
- public:
+ class lock
+ {
+ public:
/**
* Construct a lock.
* \param mutex The mutex.
*/
- explicit lock(mutex& mutex, bool lock = true) :
+ explicit lock(mutex& mutex, bool lock = true) :
mutex_(mutex),
is_locked_(false)
{
- if (lock) if (!acquire()) throw "mutex lock not acquired";
+ if (lock && !acquire()) throw "mutex lock not acquired";
}
/**
* Deconstruct a lock. The lock is automagically released if it is
* still locked.
*/
- ~lock()
+ ~lock()
{
if (is_locked_) release();
}
-
/**
* Try to acquire a lock on the mutex.
* \return True if the mutex was locked, false otherwise.
*/
- bool acquire()
+ bool acquire()
{
return (is_locked_ = mutex_.acquire_lock());
}
* Release the lock.
* \return True if the mutex was unlocked, false otherwise.
*/
- bool release()
+ bool release()
{
bool result = mutex_.release_lock();
is_locked_ = false;
return result;
}
-
/**
* Get whether or not the mutex is locked.
* \return True if the mutex is locked, false otherwise.
*/
- bool is_locked() const
+ bool is_locked() const
{
return is_locked_;
}
+ protected:
- protected:
-
- mutex& mutex_;
- bool is_locked_;
-
- friend class condition;
- };
+ mutex& mutex_;
+ bool is_locked_;
+ friend class condition;
+ };
private:
/**
* Construct a condition.
*/
- condition()
+ condition()
{
condition_ = SDL_CreateCond();
}
/**
* Deconstruct a condition.
*/
- ~condition()
+ ~condition()
{
SDL_DestroyCond(condition_);
}
-
/**
* Unlock the mutex and wait for another thread to notify the thread,
* at which point the mutex will be re-locked and the method will
*/
bool wait(mutex& mutex)
{
- return (SDL_CondWait(condition_, mutex.mutex_) == 0);
+ return SDL_CondWait(condition_, mutex.mutex_) == 0;
}
/**
* \param lock The lock.
* \return True if the thread was notified, false otherwise.
*/
- bool wait(mutex::lock& lock)
+ bool wait(mutex::lock& lock)
{
- return (SDL_CondWait(condition_, lock.mutex_.mutex_) == 0);
- }
+ return SDL_CondWait(condition_, lock.mutex_.mutex_) == 0;
+ }
/**
* Unlock the mutex and wait for another thread to notify the thread,
* \param timeout Number of seconds to wait.
* \return True if the thread was notified, false otherwise.
*/
- bool wait(mutex& mutex, scalar timeout)
+ bool wait(mutex& mutex, scalar timeout)
{
Uint32 ms = timeout * SCALAR(1000.0);
- return (SDL_CondWaitTimeout(condition_, mutex.mutex_, ms) == 0);
+ return SDL_CondWaitTimeout(condition_, mutex.mutex_, ms) == 0;
}
/**
* \param timeout Number of seconds to wait.
* \return True if the thread was notified, false otherwise.
*/
- bool wait(mutex::lock& lock, scalar timeout)
+ bool wait(mutex::lock& lock, scalar timeout)
{
Uint32 ms = timeout * SCALAR(1000.0);
- return (SDL_CondWaitTimeout(condition_,
- lock.mutex_.mutex_, ms) == 0);
+ return SDL_CondWaitTimeout(condition_,
+ lock.mutex_.mutex_, ms) == 0;
}
-
/**
* Notify one other thread that is waiting on the condition.
* \return True on success, false otherwise.
*/
- bool notify()
+ bool notify()
{
- return (SDL_CondSignal(condition_) == 0);
+ return SDL_CondSignal(condition_) == 0;
}
/**
* Notify all other threads that are waiting on the condition.
* \return True on success, false otherwise.
*/
- bool notify_all()
+ bool notify_all()
{
- return (SDL_CondBroadcast(condition_) == 0);
+ return SDL_CondBroadcast(condition_) == 0;
}
-
private:
SDL_cond* condition_;
* Construct a semaphore.
* \param value The initial value of the semaphore.
*/
- explicit semaphore(uint32_t value)
+ explicit semaphore(uint32_t value)
{
semaphore_ = SDL_CreateSemaphore(value);
}
/**
* Deconstruct a semaphore.
*/
- ~semaphore()
+ ~semaphore()
{
SDL_DestroySemaphore(semaphore_);
}
-
/**
* Block until the calling thread can secure exclusive access to the
* code protected by the semaphore.
* \return True if the lock was acquired, false otherwise.
* \see lock
*/
- bool acquire_lock()
+ bool acquire_lock()
{
- return (SDL_SemWait(semaphore_) == 0);
+ return SDL_SemWait(semaphore_) == 0;
}
/**
bool acquire_lock(scalar timeout)
{
Uint32 ms = timeout * SCALAR(1000.0);
- return (SDL_SemWaitTimeout(semaphore_, ms) == 0);
+ return SDL_SemWaitTimeout(semaphore_, ms) == 0;
}
/**
* \return True if the semaphore was unlocked, false otherwise.
* \see lock
*/
- bool release_lock()
+ bool release_lock()
{
- return (SDL_SemPost(semaphore_) == 0);
+ return SDL_SemPost(semaphore_) == 0;
}
/**
* immediately available.
* \return True if the semaphore was locked, false otherwise.
*/
- bool try_lock()
+ bool try_lock()
{
- return (SDL_SemTryWait(semaphore_) == 0);
+ return SDL_SemTryWait(semaphore_) == 0;
}
/**
* since it makes it much more difficult to forget to unlock a
* semaphore.
*/
- class lock
- {
- public:
+ class lock
+ {
+ public:
/**
* Construct a lock.
* \param semaphore The semaphore.
*/
- explicit lock(semaphore& semaphore, bool lock = true) :
+ explicit lock(semaphore& semaphore, bool lock = true) :
semaphore_(semaphore),
is_locked_(false)
{
- if (lock) if (!acquire()) throw "semaphore lock not acquired";
+ if (lock && !acquire()) throw "semaphore lock not acquired";
}
/**
* Deconstruct a lock. The lock is automagically released if it is
* still locked.
*/
- ~lock()
+ ~lock()
{
if (is_locked_) release();
}
-
/**
* Try to acquire a lock on the semaphore.
* \return True if the semaphore was locked, false otherwise.
*/
- bool acquire()
+ bool acquire()
{
return (is_locked_ = semaphore_.acquire_lock());
}
* Release the lock.
* \return True if the semaphore was unlocked, false otherwise.
*/
- bool release()
+ bool release()
{
bool result = semaphore_.release_lock();
is_locked_ = false;
* Get whether or not the semaphore is locked.
* \return True if the semaphore is locked, false otherwise.
*/
- bool is_locked() const
+ bool is_locked() const
{
return is_locked_;
}
-
-
- protected:
- semaphore& semaphore_;
- bool is_locked_;
- };
+ protected:
+ semaphore& semaphore_;
+ bool is_locked_;
+ };
private:
#if ENABLE_THREADS
-#define MOOF_DECLARE_MUTEX(M) moof::mutex M
+#define MOOF_DECLARE_MUTEX(M) moof::mutex M
#define MOOF_DECLARE_STATIC_MUTEX(M) static moof::mutex M
-#define MOOF_MUTEX_LOCK(M) moof::mutex::lock lock_##M(M)
+#define MOOF_MUTEX_LOCK(M) moof::mutex::lock lock_##M(M)
#else
#define MOOF_DECLARE_MUTEX(M)
#define MOOF_DECLARE_STATIC_MUTEX(M)
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
+#if HAVE_CONFIG_H
#include "config.h"
+#endif
#include <cerrno>
#include <ctime>
void timer::init(const function& function,
- scalar seconds,
- enum mode mode,
- timer_source& source)
+ scalar seconds, enum mode mode, timer_source& source)
{
source_ = &source;
absolute_ = SCALAR(0.0);
}
-
void timer::added_to_runloop(runloop& runloop)
{
detach_from_runloop();
}
}
-
void timer::fire(scalar t)
{
if (function_) function_(*this, t);
if (mode_ == repeat)
{
- if (is_equal(absolute_, t, 1.0)) absolute_ += interval_;
- else absolute_ = interval_ + t;
+ if (is_equal(absolute_, t, 1.0))
+ absolute_ += interval_;
+ else
+ absolute_ = interval_ + t;
+ // TODO error accumulates in absolute var
+ }
+ else
+ {
+ invalidate();
}
- else invalidate();
}
-
scalar timer::ticks()
{
return default_source().ticks();
}
-
-
#if ENABLE_CLOCK_GETTIME
-
class real_time : public timer_source
{
public:
reset();
}
-
scalar ticks() const
{
struct timespec ts;
ASSERT(result == 0 && "monotonic clock not available");
return reference_ +
- (scalar(ts.tv_sec - start_.tv_sec) +
- scalar(ts.tv_nsec - start_.tv_nsec) *
- SCALAR(0.000000001)) * scale_;
+ (scalar(ts.tv_sec - start_.tv_sec) +
+ scalar(ts.tv_nsec - start_.tv_nsec) *
+ SCALAR(0.000000001)) * scale_;
}
void reset()
scale_ = factor;
}
-
private:
- scalar reference_;
+ scalar reference_;
struct timespec start_;
- scalar scale_;
+ scalar scale_;
};
-
void timer::sleep(scalar seconds, enum mode mode)
{
if (mode == absolute) seconds -= ticks();
ts.tv_nsec = (seconds - scalar(ts.tv_sec)) * SCALAR(1000000000.0);
int ret;
- do ret = nanosleep(&ts, &ts); while (ret == -1 && errno == EINTR);
+ do ret = nanosleep(&ts, &ts);
+ while (ret == -1 && errno == EINTR);
}
-
#else // ! ENABLE_CLOCK_GETTIME
-
-
class real_time : public timer_source
{
public:
real_time() :
- scale_(SCALAR(1.0))
+ scale_(SCALAR(0.001))
{
reset();
}
-
scalar ticks() const
{
return reference_ + scalar(SDL_GetTicks() - start_) * scale_;
scale_ = factor * SCALAR(0.001);
}
-
private:
scalar reference_;
scalar scale_;
};
-
void timer::sleep(scalar seconds, enum mode mode)
{
if (mode == absolute) seconds -= ticks();
if (seconds < SCALAR(0.0)) return;
SDL_Delay(seconds * SCALAR(1000.0));
}
-
#endif // ENABLE_CLOCK_GETTIME
-
timer_source& timer::default_source()
{
static real_time t;
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_TIMER_HH_
#define _MOOF_TIMER_HH_
namespace moof {
+// forward declarations
+class runloop;
+
/**
* A timer source is an object that keeps track of increasing time in units
* of seconds. A timer source does not necessarily have to increment at
};
-class runloop;
-
-
/**
* A class to represent a timer for scheduled events. The timer events
* will be executed on or sometime after their schedculed time. The
invalid = 0, /// Timer is not scheduled.
relative = 1, /// Timer is scheduled by a relative time.
absolute = 2, /// Timer is scheduled by an absolute time.
- repeat = 3 /// Timer is scheduled by a periodic time.
+ repeat = 3 /// Timer is scheduled by a periodic time.
};
/**
* Function protocol for a timer event handler. A function matching
* this protocol will be called when the timer expires. The function
* takes two parameters: the timer object that just expired, and the
- * absolute time.
+ * absolute time of the time source which caused the timer to expire.
*/
typedef boost::function<void(timer&,scalar)> function;
-
/**
* Construct an invalid (uninitialized) timer.
*/
init(function, seconds, mode, source);
}
-
/**
* Deconstruct a timer. This will automagically invalidate the timer,
* so it will not expire or fire an event.
*/
~timer();
-
/**
* Initialize a timer with a scheduled time. If the timer is already
* scheduled, its prior schedule will be invalidated and replaced by
enum mode mode = relative,
timer_source& source = default_source());
-
/**
* Manually invalidated the timer, removing any schedule such that the
* timer will not expired and no event will be fired.
*/
void invalidate();
-
enum mode mode() const
{
return mode_;
}
-
/**
* Manually fire the timer event. Usually, the timer event will be
* fired when the timer expires, but this can be used to fire it
fire(source_->ticks());
}
-
/**
* Fire the timer event if it is expired.
* \param t The absolute time used as a reference to determine if the
* \return The absolute time of the next expiration (if repeating), or
* 0.0 otherwise.
*/
- scalar fire_if_expired(scalar t)
+ bool fire_if_expired(scalar t)
{
- if (is_expired(t)) fire(t);
- return absolute_;
+ if (is_expired(t))
+ {
+ fire(t);
+ return true;
+ }
+ return false;
}
- scalar fire_if_expired()
+ bool fire_if_expired()
{
return fire_if_expired(source_->ticks());
}
-
/**
* Get the absolute time of the next expiration of this timer.
* \return Seconds.
return remaining(source_->ticks());
}
-
/**
* Get whether or not the timer is expired. A timer on a repeating
* schedule will never be expired since it will always have a scheduled
return is_expired(source_->ticks());
}
-
static timer_source& default_source();
/**
*/
static scalar ticks();
-
/**
* Put the thread to sleep for a certain period of time. If absolute
* is true, then it will sleep until the default timer reaches the
*/
static void sleep(scalar seconds, enum mode mode = relative);
-
private:
void added_to_runloop(runloop& runloop);
void detach_from_runloop();
-
- function function_;
- enum mode mode_;
- scalar absolute_;
- scalar interval_;
+ function function_;
+ enum mode mode_;
+ scalar absolute_;
+ scalar interval_;
timer_source* source_;
- runloop* runloop_;
+ runloop* runloop_;
};
-
-
class game_time : public timer_source
{
public:
game_time(scalar timestep = SCALAR(1.0)) :
- scale_(timestep)
+ scale_(timestep),
+ scalefactor_(SCALAR(1.0))
{
reset(timestep);
}
{
reset();
timestep_ = timestep;
+ scale_ = timestep_ * scalefactor_;
}
void scale(scalar factor)
{
reference_ = ticks();
- ticks_ = 1;
+ ticks_ = 0;
scale_ = timestep_ * factor;
+ scalefactor_ = factor;
}
-
- unsigned step(unsigned step = 1)
+ scalar step(unsigned step = 1)
{
ticks_ += step;
- return ticks_;
+ return scale_;
}
-
private:
scalar reference_;
unsigned ticks_;
scalar timestep_;
scalar scale_;
+ scalar scalefactor_;
};
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
#include <sstream>
#include <stdexcept>
void video::set_opengl_attributes()
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE,
- attributes_.color_buffer[0]);
+ attributes_.color_buffer[0]);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,
- attributes_.color_buffer[1]);
+ attributes_.color_buffer[1]);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,
- attributes_.color_buffer[2]);
+ attributes_.color_buffer[2]);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,
- attributes_.color_buffer[3]);
+ attributes_.color_buffer[3]);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,
- attributes_.frame_buffer);
+ attributes_.frame_buffer);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,
- attributes_.is_double_buffer);
+ attributes_.is_double_buffer);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,
- attributes_.depth_buffer);
+ attributes_.depth_buffer);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,
- attributes_.stencil_buffer);
+ attributes_.stencil_buffer);
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,
- attributes_.accumulator_buffer[0]);
+ attributes_.accumulator_buffer[0]);
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,
- attributes_.accumulator_buffer[1]);
+ attributes_.accumulator_buffer[1]);
SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,
- attributes_.accumulator_buffer[2]);
+ attributes_.accumulator_buffer[2]);
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,
- attributes_.accumulator_buffer[3]);
+ attributes_.accumulator_buffer[3]);
SDL_GL_SetAttribute(SDL_GL_STEREO,
- attributes_.is_stereo);
+ attributes_.is_stereo);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,
- attributes_.multisample_buffers);
+ attributes_.multisample_buffers);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,
- attributes_.multisample_samples);
+ attributes_.multisample_samples);
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,
- attributes_.is_swap_control);
+ attributes_.is_swap_control);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,
- attributes_.is_hardware_only);
+ attributes_.is_hardware_only);
}
-
video::~video()
{
SDL_FreeSurface(context_);
-
if (current_ == this) current_ = 0;
}
-
class video::attributes video::attributes() const
{
return attributes_;
}
-
void video::mode(const int mode[3])
{
if (mode != attributes_.mode || !context_)
if (context_) SDL_FreeSurface(context_);
context_ = SDL_SetVideoMode(mode[0], mode[1], mode[2],
- SDL_OPENGL | flags_);
+ flags_);
if (context_)
{
attributes_.mode[1] = mode[1];
attributes_.mode[2] = mode[2];
-#if !defined(linux) && !defined(__linux) && !defined(__linux__)
+#if PLATFORM_WIN32
log_info("video context recreated");
dispatcher::global().dispatch("video.newcontext");
#endif
}
}
-
void video::resize(int width, int height)
{
int mode[] = {width, height, attributes_.mode[2]};
return SDL_WM_IconifyWindow();
}
-
void video::caption(const std::string& caption)
{
caption_ = caption;
const std::string& video::caption() const
{
return caption_;
- //char* caption;
- //SDL_WM_GetCaption(&caption, 0);
- //return std::string(caption);
}
-
void video::fullscreen(bool full)
{
if (full != fullscreen() || !context_)
{
flags_ ^= SDL_FULLSCREEN;
-#if defined(linux) || defined(__linux) || defined(__linux__)
+#if PLATFORM_POSIX
if (SDL_WM_ToggleFullScreen(context_) == 0)
#endif
recreate_context();
fullscreen(!fullscreen());
}
-
void video::resizable(bool is_resizable)
{
if (is_resizable != resizable() || !context_)
resizable(!resizable());
}
-
void video::cursor_visible(bool is_cursor_visible)
{
SDL_ShowCursor(is_cursor_visible? SDL_ENABLE : SDL_DISABLE);
cursor_visible(!cursor_visible());
}
-
bool video::cursor_captured() const
{
return (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON);
cursor_captured(!cursor_captured());
}
-
void video::swap(scalar t)
{
if (show_fps_)
++fps_counter_;
}
-
SDL_GL_SwapBuffers();
}
-
int video::width() const
{
return context_->w;
return context_->h;
}
-
void video::make_current() const
{
current_ = const_cast<video*>(this);
}
else if (is_fullscreen && backend::is_initialized())
{
- SDL_Rect** modes = SDL_ListModes(NULL,
- SDL_FULLSCREEN | SDL_HWSURFACE);
+ SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
if (modes == (SDL_Rect**)0)
{
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_VIDEO_HH_
#define _MOOF_VIDEO_HH_
namespace moof {
+// forward declarations
class settings;
class video;
typedef boost::shared_ptr<video> video_ptr;
-
class video
{
public:
struct attributes
{
- int color_buffer[4]; // rgba
- int frame_buffer;
- bool is_double_buffer;
- int depth_buffer;
- int stencil_buffer;
- int accumulator_buffer[4]; // rgba
- bool is_stereo;
- int multisample_buffers;
- int multisample_samples;
- bool is_swap_control;
- bool is_hardware_only;
- int mode[3]; // width, height, bpp
- bool is_fullscreen;
- bool is_resizable;
- bool is_cursor_visible;
- bool is_cursor_captured;
+ int color_buffer[4]; // rgba
+ int frame_buffer;
+ bool is_double_buffer;
+ int depth_buffer;
+ int stencil_buffer;
+ int accumulator_buffer[4]; // rgba
+ bool is_stereo;
+ int multisample_buffers;
+ int multisample_samples;
+ bool is_swap_control;
+ bool is_hardware_only;
+ int mode[3]; // width, height, bpp
+ bool is_fullscreen;
+ bool is_resizable;
+ bool is_cursor_visible;
+ bool is_cursor_captured;
attributes();
attributes(const settings& settings);
void init();
- backend mBackend;
+ backend backend_;
};
-
static video_ptr alloc(const attributes& attribs)
{
return video_ptr(new video(attribs));
explicit video(const std::string& caption = "Moof!!");
explicit video(const class attributes& attribs);
- video(const std::string& caption,
- const class attributes& attribs);
+ explicit video(const std::string& caption,
+ const class attributes& attribs);
~video();
class attributes attributes() const;
bool cursor_captured() const;
void toggle_cursor_captured();
-
/**
* Swap the video buffers if double-buffered.
*/
void swap(scalar t = timer::ticks());
-
/**
* Make this video context the current context which will be effected
* by future draw commands.
return current_;
}
-
/**
* Get the width of the video display.
* \return The pixel width.
*/
int height() const;
-
void show_fps(bool show)
{
show_fps_ = show;
return show_fps_;
}
-
private:
void init();
// TODO: this implementation is not well hidden
SDL_Surface* context_;
- int flags_;
+ int flags_;
class attributes attributes_;
- bool show_fps_;
- std::string caption_;
- scalar fps_accumulator_;
- int fps_counter_;
- scalar last_swap_;
+ bool show_fps_;
+ std::string caption_;
+ scalar fps_accumulator_;
+ int fps_counter_;
+ scalar last_swap_;
static video* current_;
};
# Define rules and targets for Yoink.
#
-$(call include,moof stlplus) # Recurse into subdirectories.
+$(call include,moof stlplus) # Recurse into subdirectories.
-objects = $(patsubst %.c,$(builddir)/%.o,$(patsubst %.cc,$(builddir)/%.o,$(wildcard $d/*.c $d/*.cc)))
+objects = $(patsubst %.c,$(builddir)/%.o,$(patsubst %.cc,$(builddir)/%.o,$(wildcard $d/*.c $d/*.cc)))
ifeq (win32,$(platform))
-objects += $b/win32.o # Also compile win32 resource file.
+objects += $b/win32.o # Also compile win32 resource file.
endif
ifeq (true,$(includeConfig))
-objects += $b/config.o # Also compile in the configuration.
-exec += $b/config.c # Make config.c a build target.
+objects += $b/config.o # Also compile in the configuration.
+exec += $b/config.c # Make config.c a build target.
$b/config.c: config.mk
$(Q)$(xxd)
endif
$(objects): TGT_CFLAGS := -I$d
$(objects): config.h $(this) | $b
-# Make all objects depend on config.h; it's excessive, but config.h won't
-# be remade otherwise if dependencies are not being generated. The
-# alternative is to maintain an accurate list of objects with a dependency
-# on config.h.
+# Make all objects depend on config.h; it's excessive, but config.h won't be
+# remade otherwise if dependencies are not being generated. The alternative
+# is to maintain an accurate list of objects with a dependency on config.h.
-exec += $(objects) # Make the objects build targets.
+exec += $(objects) # Make the objects build targets.
-bindir_$b := $b/$(projectName)$(EXEEXT) # Install executable to bindir.
+bindir_$b := $b/$(projectName)$(EXEEXT) # Install executable to bindir.
$(bindir_$b): $(objects) $b/moof/libmoof.a $b/stlplus/libstlplus.a
$(Q)$(link_cc)
objects = $(patsubst %.cpp,$(builddir)/%.o,$(shell find $d -name "*.cpp"))
$(objects): TGT_CFLAGS := -I$d -I$d/containers -I$d/portability
-$(objects): config.mk $(this) | $b/containers $b/portability $b/strings
+$(objects): config.mk $(this) | $b/containers $b/portability
library = $b/libstlplus.a
$(library): $(objects)
+++ /dev/null
-#ifndef STLPLUS_FORMAT_TYPES
-#define STLPLUS_FORMAT_TYPES
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// A Set of enumerations controlling the string formatting of numbers.
-
-////////////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////////////
-// Integer radix display representations:
-// There are three ways in which the radix is represented:
-// - none - the number is just printed as a number (e.g. 12345). Can be confusing for non-decimal radix
-// - C style - for binary, octal and hex, the C-style prefices 0b, 0 and 0x are used
-// note that this is an unsigned representation
-// - Hash style - in the form radix#value - the value may be signed, e.g. 10#-9
-
-enum radix_display_t
-{
- radix_none, // just print the number with no radix indicated
- radix_hash_style, // none for decimal, hash style for all others
- radix_hash_style_all, // hash style for all radices including decimal
- radix_c_style, // C style for hex and octal, none for others
- radix_c_style_or_hash // C style for hex and octal, none for decimal, hash style for others
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// Floating-point display representations:
-// There are three formats for the printout:
-// - fixed - formatted as a fixed-point number, so no mantissa is printed (equivalent to %f in printf)
-// - floating - formatted as a normalised floating-point number (equivalent to %e in printf)
-// - mixed - formatted as fixed-point if appropriate, otherwise the floating format (equivalent to %g in printf)
-
-enum real_display_t
-{
- display_fixed, // %f
- display_floating, // %e
- display_mixed // %g
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// Alignment:
-// There are three field alignments:
-// - left aligned - the value is to the left of the field which is padded to the right with spaces
-// - right aligned - the value is to the right of the field which is padded to the left with spaces
-// - centred - the value is in the centre of the field and spaces added to both left and right
-
-enum alignment_t
-{
- align_left,
- align_right,
- align_centre
-};
-
-////////////////////////////////////////////////////////////////////////////////
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// use the unsigned long representation for pointers
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_address.hpp"
-#include "print_int.hpp"
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- void print_address(std::ostream& device, const void* i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- print_unsigned_long(device, (unsigned long)i, radix, display, width);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_ADDRESS
-#define STLPLUS_PRINT_ADDRESS
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "format_types.hpp"
-#include <string>
-#include <iostream>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- void print_address(std::ostream& device,
- const void*,
- unsigned radix = 16,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_PRINT_BASIC
-#define STLPLUS_PRINT_BASIC
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Utilities for converting printing basic C types
-
-////////////////////////////////////////////////////////////////////////////////
-
-#include "print_address.hpp"
-#include "print_bool.hpp"
-#include "print_cstring.hpp"
-#include "print_float.hpp"
-#include "print_int.hpp"
-#include "print_pointer.hpp"
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_PRINT_BITSET
-#define STLPLUS_PRINT_BITSET
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a bitset
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <bitset>
-#include <string>
-#include <iostream>
-
-namespace stlplus
-{
-
- template<size_t N>
- void print_bitset(std::ostream& device, const std::bitset<N>& data);
-
-} // end namespace stlplus
-
-#include "print_bitset.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_bitset.hpp"
-
-namespace stlplus
-{
-
- template<size_t N>
- void print_bitset(std::ostream& device, const std::bitset<N>& data)
- {
- device << bitset_to_string(data);
- }
-
-} // end namespace stlplus
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// use the unsigned short representation for bool
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_bool.hpp"
-#include "print_int.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- void print_bool(std::ostream& device, bool i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- print_unsigned_short(device, (unsigned short)i, radix, display, width);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_BOOL
-#define STLPLUS_PRINT_BOOL
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Conversion of string to/from bool
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "format_types.hpp"
-#include <string>
-#include <iostream>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- void print_bool(std::ostream& device, bool i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_cstring.hpp"
-
-namespace stlplus
-{
-
- void print_cstring(std::ostream& device, const char* value)
- {
- device << value;
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_CSTRING
-#define STLPLUS_PRINT_CSTRING
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Functions for converting C/STL strings to string
-
-// This is necessary for completeness
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <iostream>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- void print_cstring(std::ostream& device, const char* value);
-
-}
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_PRINT_DIGRAPH
-#define STLPLUS_PRINT_DIGRAPH
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a digraph
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "digraph.hpp"
-#include <string>
-#include <iostream>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename NT, typename AT, typename NS, typename AS>
- void print_digraph(std::ostream& device,
- const digraph<NT,AT>& values,
- NS node_print_fn,
- AS arc_print_fn,
- const std::string& separator = ",");
-
-} // end namespace stlplus
-
-#include "print_digraph.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_sequence.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- template<typename NT, typename AT, typename NS, typename AS>
- void print_digraph(std::ostream& device, const digraph<NT,AT>& values,
- NS node_print_fn,
- AS arc_print_fn,
- const std::string& separator)
- {
- device << "nodes:";
- device << separator;
- print_sequence(device, values.begin(), values.end(), node_print_fn, separator);
- device << "arcs:";
- device << separator;
- print_sequence(device, values.arc_begin(), values.arc_end(), arc_print_fn, separator);
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_float.hpp"
-#include "string_float.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // floating-point types
-
- void print_float(std::ostream& device, float f, real_display_t display, unsigned width, unsigned precision)
- throw(std::invalid_argument)
- {
- device << float_to_string(f, display, width, precision);
- }
-
- void print_double(std::ostream& device, double f, real_display_t display, unsigned width, unsigned precision)
- throw(std::invalid_argument)
- {
- device << double_to_string(f, display, width, precision);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_FLOAT
-#define STLPLUS_PRINT_FLOAT
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Convert a float/double to/from string
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "format_types.hpp"
-#include <string>
-#include <iostream>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // convert a real type to string
- ////////////////////////////////////////////////////////////////////////////////
-
- // Only decimal radix is supported
-
- // The way in which the number is displayed is defined in radix_types.hpp
- // Using any other value for the display type causes std::invalid_argument to be thrown
-
- void print_float(std::ostream& device, float f,
- real_display_t display = display_mixed,
- unsigned width = 0,
- unsigned precision = 6)
- throw(std::invalid_argument);
-
- void print_double(std::ostream& device, double f,
- real_display_t display = display_mixed,
- unsigned width = 0,
- unsigned precision = 6)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_PRINT_FOURSOME
-#define STLPLUS_PRINT_FOURSOME
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a foursome
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "foursome.hpp"
-#include <string>
-#include <iostream>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T1, typename T2, typename T3, typename T4, typename S1, typename S2, typename S3, typename S4>
- void print_foursome(std::ostream& device,
- const foursome<T1,T2,T3,T4>& values,
- S1 print_fn1,
- S2 print_fn2,
- S3 print_fn3,
- S4 print_fn4,
- const std::string& separator = ":");
-
-} // end namespace stlplus
-
-#include "print_foursome.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T1, typename T2, typename T3, typename T4, typename S1, typename S2, typename S3, typename S4>
- void print_foursome(std::ostream& device,
- const foursome<T1,T2,T3,T4>& values,
- S1 print_fn1,
- S2 print_fn2,
- S3 print_fn3,
- S4 print_fn4,
- const std::string& separator)
- {
- print_fn1(device, values.first);
- device << separator;
- print_fn2(device, values.second);
- device << separator;
- print_fn3(device, values.third);
- device << separator;
- print_fn4(device, values.fourth);
- }
-
-
-} // end namespace stlplus
-
+++ /dev/null
-#ifndef STLPLUS_PRINT_HASH
-#define STLPLUS_PRINT_HASH
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a hash
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "hash.hpp"
-#include <string>
-#include <iostream>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename K, typename T, typename H, typename E, typename KS, typename TS>
- void print_hash(std::ostream& device,
- const hash<K,T,H,E>& values,
- KS key_print_fn,
- TS value_print_fn,
- const std::string& pair_separator = ":",
- const std::string& separator = ",");
-
-} // end namespace stlplus
-
-#include "print_hash.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_sequence.hpp"
-
-namespace stlplus
-{
-
- template<typename K, typename T, typename H, typename E, typename KS, typename TS>
- void print_hash(std::ostream& device,
- const hash<K,T,H,E>& values,
- KS key_print_fn,
- TS value_print_fn,
- const std::string& pair_separator,
- const std::string& separator)
- {
- print_pair_sequence(device,
- values.begin(), values.end(),
- key_print_fn, value_print_fn,
- pair_separator, separator);
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// String conversion functions for the infinite precision integer type inf
-
-////////////////////////////////////////////////////////////////////////////////
-
-// can be excluded from the build to break the dependency on the portability library
-#ifndef NO_STLPLUS_INF
-
-#include "print_inf.hpp"
-#include "string_inf.hpp"
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- void print_inf(std::ostream& device,
- const stlplus::inf& data,
- unsigned radix,
- radix_display_t display,
- unsigned width)
- throw(std::invalid_argument)
- {
- device << inf_to_string(data, radix, display, width);
- }
-
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_PRINT_INF
-#define STLPLUS_PRINT_INF
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// String conversion functions for the infinite precision integer type inf
-
-// The conversion supports all the formatting modes defined on format_types
-
-////////////////////////////////////////////////////////////////////////////////
-
-#include "strings_fixes.hpp"
-#include "inf.hpp"
-#include "format_types.hpp"
-#include <stdexcept>
-#include <iostream>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- void print_inf(std::ostream& device,
- const inf&,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
-////////////////////////////////////////////////////////////////////////////////
-} // end namespace stlplus
-
-
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_int.hpp"
-#include "string_int.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- void print_short(std::ostream& device, short i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- device << short_to_string(i, radix, display, width);
- }
-
- void print_unsigned_short(std::ostream& device, unsigned short i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- device << unsigned_short_to_string(i, radix, display, width);
- }
-
- void print_int(std::ostream& device, int i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- device << int_to_string(i, radix, display, width);
- }
-
- void print_unsigned(std::ostream& device, unsigned i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- device << unsigned_to_string(i, radix, display, width);
- }
-
- void print_long(std::ostream& device, long i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- device << long_to_string(i, radix, display, width);
- }
-
- void print_unsigned_long(std::ostream& device, unsigned long i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- device << unsigned_long_to_string(i, radix, display, width);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_INT
-#define STLPLUS_PRINT_INT
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Print integer types
-
-// This extends the formatting available from iostream
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "format_types.hpp"
-#include <iostream>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // Conversions of Integer types to string
- ////////////////////////////////////////////////////////////////////////////////
-
- // The radix (i.e. base) for these conversions can be any value from base 2 to base 36
- // specifying any other radix causes std::invalid_argument to be thrown
-
- // The way in which the radix is displayed is defined in radix_types.hpp
- // If any other value is used, std::invalid_argument is thrown
-
- // The width argument specifies the number of numerical digits to use in the result
- // This is a minimum - if the value requires more digits then it will be wider than the width argument
- // However, if it is smaller, then it will be extended to the specified width
- // Then, the radix display prefix is added to this width
-
- // For example, using the hash representation of 0 in hex with width=4 gives:
- // 16#0000 - so there's 4 digits in the number part
-
- void print_short(std::ostream& device, short i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- void print_unsigned_short(std::ostream& device, unsigned short i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- void print_int(std::ostream& device, int i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- void print_unsigned(std::ostream& device, unsigned i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- void print_long(std::ostream& device, long i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- void print_unsigned_long(std::ostream& device, unsigned long i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_PRINT_LIST
-#define STLPLUS_PRINT_LIST
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a list
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <iostream>
-#include <list>
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- void print_list(std::ostream& device,
- const std::list<T>& values,
- S print_fn,
- const std::string& separator = ",");
-
-} // end namespace stlplus
-
-#include "print_list.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// template implementations
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_sequence.hpp"
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- void print_list(std::ostream& device,
- const std::list<T>& values,
- S print_fn,
- const std::string& separator)
- {
- print_sequence(device, values.begin(), values.end(), print_fn, separator);
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_MAP
-#define STLPLUS_PRINT_MAP
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a map/multimap
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <iostream>
-#include <map>
-
-namespace stlplus
-{
-
- template<typename K, typename T, typename C, typename SK, typename ST>
- void print_map(std::ostream& device, const std::map<K,T,C>& values,
- SK key_print_fn,
- ST value_print_fn,
- const std::string& pair_separator = ":",
- const std::string& separator = ",");
-
- template<typename K, typename T, typename C, typename SK, typename ST>
- void print_multimap(std::ostream& device, const std::multimap<K,T,C>& values,
- SK key_print_fn,
- ST value_print_fn,
- const std::string& pair_separator = ":",
- const std::string& separator = ",");
-
-} // end namespace stlplus
-
-#include "print_map.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_sequence.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // map
-
- template<typename K, typename T, typename C, typename SK, typename ST>
- void print_map(std::ostream& device, const std::map<K,T,C>& values,
- SK key_print_fn,
- ST value_print_fn,
- const std::string& pair_separator,
- const std::string& separator)
- {
- print_pair_sequence(values.begin(), values.end(),
- key_print_fn, value_print_fn,
- pair_separator, separator);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // multimap
-
- template<typename K, typename T, typename C, typename SK, typename ST>
- void print_multimap(std::ostream& device, const std::multimap<K,T,C>& values,
- SK key_print_fn,
- ST value_print_fn,
- const std::string& pair_separator,
- const std::string& separator)
- {
- print_pair_sequence(device,
- values.begin(), values.end(),
- key_print_fn, value_print_fn,
- pair_separator, separator);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_MATRIX
-#define STLPLUS_PRINT_MATRIX
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a matrix
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "matrix.hpp"
-#include <string>
-#include <iostream>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- void print_matrix(std::ostream& device,
- const matrix<T>& values,
- S print_fn,
- const std::string& column_separator = "|",
- const std::string& row_separator = ",");
-
-} // end namespace stlplus
-
-#include "print_matrix.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- template<typename T, typename S>
- void print_matrix(std::ostream& device, const matrix<T>& values,
- S print_fn,
- const std::string& column_separator,
- const std::string& row_separator)
- {
- for (unsigned r = 0; r < values.rows(); r++)
- {
- if (r != 0) device << row_separator;
- for (unsigned c = 0; c < values.columns(); c++)
- {
- if (c != 0) device << column_separator;
- print_fn(device, values(r,c));
- }
- }
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-#ifndef STLPLUS_PRINT_NTREE
-#define STLPLUS_PRINT_NTREE
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of an ntree
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "ntree.hpp"
-#include <string>
-#include <iostream>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- void print_ntree(std::ostream& device,
- const ntree<T>& values,
- S print_fn,
- const std::string& separator = "|",
- const std::string& indent_string = " ");
-
-} // end namespace stlplus
-
-#include "print_ntree.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- void print_ntree(std::ostream& device,
- const ntree<T>& values,
- S print_fn,
- const std::string& separator,
- const std::string& indent_string)
- {
- for (TYPENAME ntree<T>::const_prefix_iterator i = values.prefix_begin(); i != values.prefix_end(); i++)
- {
- if (i != values.prefix_begin()) device << separator;
- for (unsigned indent = values.depth(i.simplify()); --indent; )
- device << indent_string;
- print_fn(device, *i);
- }
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-#ifndef STLPLUS_PRINT_PAIR
-#define STLPLUS_PRINT_PAIR
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a pair
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <map>
-#include <string>
-#include <iostream>
-
-namespace stlplus
-{
-
- template<typename V1, typename V2, typename S1, typename S2>
- void print_pair(std::ostream& device,
- const std::pair<V1,V2>& values,
- S1 print_fn1,
- S2 print_fn2,
- const std::string& separator = ":");
-
-} // end namespace stlplus
-
-#include "print_pair.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename V1, typename V2, typename S1, typename S2>
- void print_pair(std::ostream& device,
- const std::pair<V1,V2>& values,
- S1 print_fn1,
- S2 print_fn2,
- const std::string& separator)
- {
- print_fn1(device, values.first);
- device << separator;
- print__fn2(device, values.second);
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_POINTER
-#define STLPLUS_PRINT_POINTER
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of an object pointed to
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <iostream>
-
-namespace stlplus
-{
-
- template <typename T, typename S>
- void print_pointer(std::ostream& device,
- const T* value,
- S print_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
-
-}
-
-#include "print_pointer.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include <string>
-
-namespace stlplus
-{
-
- template <typename T, typename S>
- void print_pointer(std::ostream& device,
- const T* value,
- S print_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- if (value)
- {
- device << prefix;
- print_fn(device, *value);
- device << suffix;
- }
- else
- {
- device << null_string;
- }
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_SEQUENCE
-#define STLPLUS_PRINT_SEQUENCE
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate string representations of sequences represented by forward iterators
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <iostream>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // any forward iterator sequence
-
- template <typename I, typename S>
- void print_sequence(std::ostream& device,
- I begin, I end,
- S print_fn,
- const std::string& separator);
-
-
- ////////////////////////////////////////////////////////////////////////////////
- // any forward iterator sequence of pairs
-
- template <typename I, typename S1, typename S2>
- void print_pair_sequence(std::ostream& device,
- I begin, I end,
- S1 print_fn1,
- S2 print_fn2,
- const std::string& pair_separator,
- const std::string& separator);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#include "print_sequence.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_pair.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // any forward iterator sequence
-
- template <typename I, typename S>
- void print_sequence(std::ostream& device,
- I begin, I end,
- S print_fn,
- const std::string& separator)
- {
- for (I i = begin; i != end; i++)
- {
- if (i != begin) device << separator;
- print_fn(device, *i);
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // any sequence where the value is a pair
-
- template <typename I, typename S1, typename S2>
- void print_pair_sequence(std::ostream& device,
- I begin, I end,
- S1 print_fn1,
- S2 print_fn2,
- const std::string& pair_separator,
- const std::string& separator)
- {
- for (I i = begin; i != end; i++)
- {
- if (i != begin) device << separator;
- print_pair(device, *i, print_fn1, print_fn2, pair_separator);
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_SET
-#define STLPLUS_PRINT_SET
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a set/multiset
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <iostream>
-#include <set>
-
-namespace stlplus
-{
-
- template<typename K, typename C, typename S>
- void print_set(std::ostream& device,
- const std::set<K,C>& values,
- S print_fn,
- const std::string& separator = ",");
-
- template<typename K, typename C, typename S>
- void print_multiset(std::ostream& device,
- const std::multiset<K,C>& values,
- S print_fn,
- const std::string& separator = ",");
-
-} // end namespace stlplus
-
-#include "print_set.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// template implementations
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_sequence.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // set
-
- template<typename K, typename C, typename S>
- void print_set(std::ostream& device,
- const std::set<K,C>& values,
- S print_fn,
- const std::string& separator)
- {
- print_sequence(device, values.begin(), values.end(), print_fn, separator);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // multiset
-
- template<typename K, typename C, typename S>
- void print_multiset(std::ostream& device,
- const std::multiset<K,C>& values,
- S print_fn,
- const std::string& separator)
- {
- print_sequence(device, values.begin(), values.end(), print_fn, separator);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_SIMPLE_PTR
-#define STLPLUS_PRINT_SIMPLE_PTR
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a smart pointer
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "simple_ptr.hpp"
-#include <string>
-#include <iostream>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- void print_simple_ptr(std::ostream& device,
- const simple_ptr<T>& value,
- S print_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
- template<typename T, typename S>
- void print_simple_ptr_clone(std::ostream& device,
- const simple_ptr_clone<T>& value,
- S print_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
- template<typename T, typename S>
- void print_simple_ptr_nocopy(std::ostream& device,
- const simple_ptr_nocopy<T>& value,
- S print_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
-
-} // end namespace stlplus
-
-#include "print_simple_ptr.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- void print_simple_ptr(std::ostream& device,
- const simple_ptr<T>& value,
- S print_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- if (value)
- {
- device << prefix;
- print_fn(device, *value);
- device << suffix;
- }
- else
- {
- device << null_string;
- }
- }
-
- template<typename T, typename S>
- void print_simple_ptr_clone(std::ostream& device,
- const simple_ptr_clone<T>& value,
- S print_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- if (value)
- {
- device << prefix;
- print_fn(device, *value);
- device << suffix;
- }
- else
- {
- device << null_string;
- }
- }
-
- template<typename T, typename S>
- void print_simple_ptr_nocopy(std::ostream& device,
- const simple_ptr_nocopy<T>& value,
- S print_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- if (value)
- {
- device << prefix;
- print_fn(device, *value);
- device << suffix;
- }
- else
- {
- device << null_string;
- }
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-#ifndef STLPLUS_PRINT_SMART_PTR
-#define STLPLUS_PRINT_SMART_PTR
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a smart pointer
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "smart_ptr.hpp"
-#include <string>
-#include <iostream>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- void print_smart_ptr(std::ostream& device,
- const smart_ptr<T>& value,
- S print_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
- template<typename T, typename S>
- void print_smart_ptr_clone(std::ostream& device,
- const smart_ptr_clone<T>& value,
- S print_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
- template<typename T, typename S>
- void print_smart_ptr_nocopy(std::ostream& device,
- const smart_ptr_nocopy<T>& value,
- S print_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
-
-} // end namespace stlplus
-
-#include "print_smart_ptr.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- void print_smart_ptr(std::ostream& device,
- const smart_ptr<T>& value,
- S print_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- if (value)
- {
- device << prefix;
- print_fn(device, *value);
- device << suffix;
- }
- else
- {
- device << null_string;
- }
- }
-
- template<typename T, typename S>
- void print_smart_ptr_clone(std::ostream& device,
- const smart_ptr_clone<T>& value,
- S print_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- if (value)
- {
- device << prefix;
- print_fn(device, *value);
- device << suffix;
- }
- else
- {
- device << null_string;
- }
- }
-
- template<typename T, typename S>
- void print_smart_ptr_nocopy(std::ostream& device,
- const smart_ptr_nocopy<T>& value,
- S print_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- if (value)
- {
- device << prefix;
- print_fn(device, *value);
- device << suffix;
- }
- else
- {
- device << null_string;
- }
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-#ifndef STLPLUS_PRINT_STL
-#define STLPLUS_PRINT_STL
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Template string conversions for pointers and STL containers
-
-////////////////////////////////////////////////////////////////////////////////
-
-#include "print_bitset.hpp"
-#include "print_list.hpp"
-#include "print_map.hpp"
-#include "print_pair.hpp"
-#include "print_sequence.hpp"
-#include "print_set.hpp"
-#include "print_string.hpp"
-#include "print_vector.hpp"
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_PRINT_STLPLUS
-#define STLPLUS_PRINT_STLPLUS
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Template string conversions for the STLplus containers
-
-////////////////////////////////////////////////////////////////////////////////
-
-#ifndef NO_STLPLUS_CONTAINERS
-#include "print_digraph.hpp"
-#include "print_foursome.hpp"
-#include "print_hash.hpp"
-#include "print_matrix.hpp"
-#include "print_ntree.hpp"
-#include "print_smart_ptr.hpp"
-#include "print_triple.hpp"
-#endif
-
-#include "print_inf.hpp"
-
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_string.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // strings
-
- void print_string(std::ostream& device, const std::string& value)
- {
- device << value;
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_STRING
-#define STLPLUS_PRINT_STRING
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Functions for converting C/STL strings to string
-
-// This is necessary for completeness, e.g. for use in print_vector for vector<string>
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <iostream>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- void print_string(std::ostream& device, const std::string& value);
-}
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_PRINT_TRIPLE
-#define STLPLUS_PRINT_TRIPLE
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a triple
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "triple.hpp"
-#include <string>
-#include <iostream>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T1, typename T2, typename T3, typename S1, typename S2, typename S3>
- void print_triple(std::ostream& device,
- const triple<T1,T2,T3>& values,
- S1 print_fn1,
- S2 print_fn2,
- S3 print_fn3,
- const std::string& separator = ":");
-
-} // end namespace stlplus
-
-#include "print_triple.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T1, typename T2, typename T3, typename S1, typename S2, typename S3>
- void print_triple(std::ostream& device,
- const triple<T1,T2,T3>& values,
- S1 print_fn1,
- S2 print_fn2,
- S3 print_fn3,
- const std::string& separator)
- {
-
- print_fn1(device, values.first);
- device << separator;
- print_fn2(device, values.second);
- device << separator;
- print_fn3(device, values.third);
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_vector.hpp"
-#include "string_vector.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // special case of vector<bool>
-
- void print_bool_vector(std::ostream& device, const std::vector<bool>& values)
- {
- device << bool_vector_to_string(values);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_PRINT_VECTOR
-#define STLPLUS_PRINT_VECTOR
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a vector
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <iostream>
-#include <vector>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // vector
-
- template<typename T, typename S>
- void print_vector(std::ostream& device,
- const std::vector<T>& values,
- S print_fn,
- const std::string& separator);
-
- // specialisation for vector<bool> which has a different implementation
- void print_bool_vector(std::ostream& device, const std::vector<bool>& values);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#include "print_vector.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "print_sequence.hpp"
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- void print_vector(std::ostream& device, const std::vector<T>& values,
- S print_fn,
- const std::string& separator)
- {
- print_sequence(device, values.begin(), values.end(), print_fn, separator);
- }
-
-} // end namespace stlplus
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// use the unsigned long representation for pointers
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_address.hpp"
-#include "string_int.hpp"
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string address_to_string(const void* i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- return unsigned_long_to_string((unsigned long)i, radix, display, width);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- void* string_to_address(const std::string& str, unsigned radix)
- throw(std::invalid_argument)
- {
- return (void*)string_to_unsigned_long(str, radix);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_ADDRESS
-#define STLPLUS_STRING_ADDRESS
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Functions for converting addresses to/from strings
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "format_types.hpp"
-#include <string>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string address_to_string(const void*,
- unsigned radix = 16,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
-
- void* string_to_address(const std::string& value,
- unsigned radix = 0)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_STRING_BASIC
-#define STLPLUS_STRING_BASIC
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Utilities for converting basic C types to/from std::strings
-
-////////////////////////////////////////////////////////////////////////////////
-
-#include "string_address.hpp"
-#include "string_bool.hpp"
-#include "string_cstring.hpp"
-#include "string_float.hpp"
-#include "string_int.hpp"
-#include "string_pointer.hpp"
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_STRING_BITSET
-#define STLPLUS_STRING_BITSET
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a bitset
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <bitset>
-#include <string>
-
-namespace stlplus
-{
-
- template<size_t N>
- std::string bitset_to_string(const std::bitset<N>& data);
-
-} // end namespace stlplus
-
-#include "string_bitset.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<size_t N>
- std::string bitset_to_string(const std::bitset<N>& data)
- {
- std::string result;
- for (unsigned i = data.size(); i--; )
- result += data.test(i) ? '1' : '0';
- return result;
- }
-
-} // end namespace stlplus
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// use the unsigned short representation for bool
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_bool.hpp"
-#include "string_int.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string bool_to_string(bool i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- return unsigned_short_to_string((unsigned short)i, radix, display, width);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- bool string_to_bool(const std::string& str, unsigned radix)
- throw(std::invalid_argument)
- {
- return string_to_unsigned_short(str, radix) != 0;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_BOOL
-#define STLPLUS_STRING_BOOL
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Conversion of string to/from bool
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "format_types.hpp"
-#include <string>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string bool_to_string(bool i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
-
- bool string_to_bool(const std::string& value,
- unsigned radix = 0)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_cstring.hpp"
-
-namespace stlplus
-{
-
- std::string cstring_to_string(const char* value)
- {
- return std::string(value);
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_CSTRING
-#define STLPLUS_STRING_CSTRING
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Functions for converting C strings to string
-
-// This is necessary for completeness
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- std::string cstring_to_string(const char* value);
-
-}
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_STRING_DIGRAPH
-#define STLPLUS_STRING_DIGRAPH
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a digraph
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "digraph.hpp"
-#include <string>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename NT, typename AT, typename NS, typename AS>
- std::string digraph_to_string(const digraph<NT,AT>& values,
- NS node_to_string_fn,
- AS arc_to_string_fn,
- const std::string& separator = ",");
-
-} // end namespace stlplus
-
-#include "string_digraph.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_sequence.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- template<typename NT, typename AT, typename NS, typename AS>
- std::string digraph_to_string(const digraph<NT,AT>& values,
- NS node_to_string_fn,
- AS arc_to_string_fn,
- const std::string& separator)
- {
- std::string result;
- result += "nodes:";
- result += separator;
- result += sequence_to_string(values.begin(), values.end(), node_to_string_fn, separator);
- result += "arcs:";
- result += separator;
- result += sequence_to_string(values.arc_begin(), values.arc_end(), arc_to_string_fn, separator);
- return result;
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_float.hpp"
-#include <stdlib.h>
-#include <ctype.h>
-#include <stdarg.h>
-#include <stdio.h>
-
-namespace stlplus
-{
-
- // added as a local copy to break the dependency on the portability library
- static std::string local_dformat(const char* format, ...) throw(std::invalid_argument)
- {
- std::string formatted;
- va_list args;
- va_start(args, format);
-#ifdef MSWINDOWS
- int length = 0;
- char* buffer = 0;
- for(int buffer_length = 256; ; buffer_length*=2)
- {
- buffer = (char*)malloc(buffer_length);
- if (!buffer) throw std::invalid_argument("string_float");
- length = _vsnprintf(buffer, buffer_length-1, format, args);
- if (length >= 0)
- {
- buffer[length] = 0;
- formatted += std::string(buffer);
- free(buffer);
- break;
- }
- free(buffer);
- }
-#else
- char* buffer = 0;
- int length = vasprintf(&buffer, format, args);
- if (!buffer) throw std::invalid_argument("string_float");
- if (length >= 0)
- formatted += std::string(buffer);
- free(buffer);
-#endif
- va_end(args);
- if (length < 0) throw std::invalid_argument("string_float");
- return formatted;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // floating-point types
-
- std::string float_to_string(float f, real_display_t display, unsigned width, unsigned precision)
- throw(std::invalid_argument)
- {
- return double_to_string((double)f, display, width, precision);
- }
-
- std::string double_to_string(double f, real_display_t display, unsigned width, unsigned precision)
- throw(std::invalid_argument)
- {
- switch(display)
- {
- case display_fixed:
- return local_dformat("%*.*f", width, precision, f);
- case display_floating:
- return local_dformat("%*.*e", width, precision, f);
- case display_mixed:
- return local_dformat("%*.*g", width, precision, f);
- default:
- throw std::invalid_argument("invalid radix display value");
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- float string_to_float(const std::string& value)
- throw(std::invalid_argument)
- {
- return (float)string_to_double(value);
- }
-
- double string_to_double(const std::string& value)
- throw(std::invalid_argument)
- {
- // TODO - error checking
- return strtod(value.c_str(), 0);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_FLOAT
-#define STLPLUS_STRING_FLOAT
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Convert a float/double to/from string
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "format_types.hpp"
-#include <string>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // convert a real type to string
- ////////////////////////////////////////////////////////////////////////////////
-
- // Only decimal radix is supported
-
- // The way in which the number is displayed is defined in radix_types.hpp
- // Using any other value for the display type causes std::invalid_argument to be thrown
-
- std::string float_to_string(float f,
- real_display_t display = display_mixed,
- unsigned width = 0,
- unsigned precision = 6)
- throw(std::invalid_argument);
-
- std::string double_to_string(double f,
- real_display_t display = display_mixed,
- unsigned width = 0,
- unsigned precision = 6)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
- // Convert a string to a floating-point type
-
- float string_to_float(const std::string& value)
- throw(std::invalid_argument);
-
- double string_to_double(const std::string& value)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_STRING_FOURSOME
-#define STLPLUS_STRING_FOURSOME
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a foursome
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "foursome.hpp"
-#include <string>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T1, typename T2, typename T3, typename T4, typename S1, typename S2, typename S3, typename S4>
- std::string foursome_to_string(const foursome<T1,T2,T3,T4>& values,
- S1 to_string_fn1,
- S2 to_string_fn2,
- S3 to_string_fn3,
- S4 to_string_fn4,
- const std::string& separator = ":");
-
-} // end namespace stlplus
-
-#include "string_foursome.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T1, typename T2, typename T3, typename T4, typename S1, typename S2, typename S3, typename S4>
- std::string foursome_to_string(const foursome<T1,T2,T3,T4>& values,
- S1 to_string_fn1,
- S2 to_string_fn2,
- S3 to_string_fn3,
- S4 to_string_fn4,
- const std::string& separator)
- {
- return
- to_string_fn1(values.first) +
- separator +
- to_string_fn2(values.second) +
- separator +
- to_string_fn3(values.third) +
- separator +
- to_string_fn4(values.fourth);
- }
-
-
-} // end namespace stlplus
-
+++ /dev/null
-#ifndef STLPLUS_STRING_HASH
-#define STLPLUS_STRING_HASH
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a hash
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "hash.hpp"
-#include <string>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename K, typename T, typename H, typename E, typename KS, typename TS>
- std::string hash_to_string(const hash<K,T,H,E>& values,
- KS key_to_string_fn,
- TS value_to_string_fn,
- const std::string& pair_separator = ":",
- const std::string& separator = ",");
-
-} // end namespace stlplus
-
-#include "string_hash.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_sequence.hpp"
-
-namespace stlplus
-{
-
- template<typename K, typename T, typename H, typename E, typename KS, typename TS>
- std::string hash_to_string(const hash<K,T,H,E>& values,
- KS key_to_string_fn,
- TS value_to_string_fn,
- const std::string& pair_separator,
- const std::string& separator)
- {
- return pair_sequence_to_string(values.begin(), values.end(),
- key_to_string_fn, value_to_string_fn,
- pair_separator, separator);
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// String conversion functions for the infinite precision integer type inf
-
-////////////////////////////////////////////////////////////////////////////////
-
-// can be excluded from the build to break the dependency on the portability library
-#ifndef NO_STLPLUS_INF
-
-#include "string_inf.hpp"
-#include "string_basic.hpp"
-#include <ctype.h>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- static char to_char [] = "0123456789abcdefghijklmnopqrstuvwxyz";
- static int from_char [] =
- {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
- };
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string inf_to_string(const stlplus::inf& data, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- std::string result;
- if (radix < 2 || radix > 36)
- throw std::invalid_argument("invalid radix value");
- inf local_i = data;
- // untangle all the options
- bool hashed = false;
- bool binary = false;
- bool octal = false;
- bool hex = false;
- switch(display)
- {
- case radix_none:
- break;
- case radix_hash_style:
- hashed = radix != 10;
- break;
- case radix_hash_style_all:
- hashed = true;
- break;
- case radix_c_style:
- if (radix == 16)
- hex = true;
- else if (radix == 8)
- octal = true;
- else if (radix == 2)
- binary = true;
- break;
- case radix_c_style_or_hash:
- if (radix == 16)
- hex = true;
- else if (radix == 8)
- octal = true;
- else if (radix == 2)
- binary = true;
- else if (radix != 10)
- hashed = true;
- break;
- default:
- throw std::invalid_argument("invalid radix display value");
- }
- // create constants of the same type as the template parameter to avoid type mismatches
- const inf t_zero(0);
- const inf t_radix(radix);
- // the C representations for binary, octal and hex use 2's-complement representation
- // all other represenations use sign-magnitude
- if (hex || octal || binary)
- {
- // bit-pattern representation
- // this is the binary representation optionally shown in octal or hex
- // first generate the binary by masking the bits
- for (unsigned j = local_i.bits(); j--; )
- result += (local_i.bit(j) ? '1' : '0');
- // the result is now the full width of the type - e.g. int will give a 32-bit result
- // now interpret this as either binary, octal or hex and add the prefix
- if (binary)
- {
- // the result is already binary - but the width may be wrong
- // if this is still smaller than the width field, sign extend
- // otherwise trim down to either the width or the smallest string that preserves the value
- while (result.size() < width)
- result.insert((std::string::size_type)0, 1, result[0]);
- while (result.size() > width)
- {
- // do not trim to less than 1 bit (sign only)
- if (result.size() <= 1) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != result[1]) break;
- result.erase(0,1);
- }
- // add the prefix
- result.insert((std::string::size_type)0, "0b");
- }
- else if (octal)
- {
- // the result is currently binary - but before converting get the width right
- // the width is expressed in octal digits so make the binary 3 times this
- // if this is still smaller than the width field, sign extend
- // otherwise trim down to either the width or the smallest string that preserves the value
- // also ensure that the binary is a multiple of 3 bits to make the conversion to octal easier
- while (result.size() < 3*width)
- result.insert((std::string::size_type)0, 1, result[0]);
- while (result.size() > 3*width)
- {
- // do not trim to less than 2 bits (sign plus 1-bit magnitude)
- if (result.size() <= 2) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != result[1]) break;
- result.erase(0,1);
- }
- while (result.size() % 3 != 0)
- result.insert((std::string::size_type)0, 1, result[0]);
- // now convert to octal
- std::string octal_result;
- for (unsigned i = 0; i < result.size()/3; i++)
- {
- // yuck - ugly or what?
- if (result[i*3] == '0')
- {
- if (result[i*3+1] == '0')
- {
- if (result[i*3+2] == '0')
- octal_result += '0';
- else
- octal_result += '1';
- }
- else
- {
- if (result[i*3+2] == '0')
- octal_result += '2';
- else
- octal_result += '3';
- }
- }
- else
- {
- if (result[i*3+1] == '0')
- {
- if (result[i*3+2] == '0')
- octal_result += '4';
- else
- octal_result += '5';
- }
- else
- {
- if (result[i*3+2] == '0')
- octal_result += '6';
- else
- octal_result += '7';
- }
- }
- }
- result = octal_result;
- // add the prefix
- result.insert((std::string::size_type)0, "0");
- }
- else
- {
- // similar to octal
- while (result.size() < 4*width)
- result.insert((std::string::size_type)0, 1, result[0]);
- while (result.size() > 4*width)
- {
- // do not trim to less than 2 bits (sign plus 1-bit magnitude)
- if (result.size() <= 2) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != result[1]) break;
- result.erase(0,1);
- }
- while (result.size() % 4 != 0)
- result.insert((std::string::size_type)0, 1, result[0]);
- // now convert to hex
- std::string hex_result;
- for (unsigned i = 0; i < result.size()/4; i++)
- {
- // yuck - ugly or what?
- if (result[i*4] == '0')
- {
- if (result[i*4+1] == '0')
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '0';
- else
- hex_result += '1';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += '2';
- else
- hex_result += '3';
- }
- }
- else
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '4';
- else
- hex_result += '5';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += '6';
- else
- hex_result += '7';
- }
- }
- }
- else
- {
- if (result[i*4+1] == '0')
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '8';
- else
- hex_result += '9';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += 'a';
- else
- hex_result += 'b';
- }
- }
- else
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += 'c';
- else
- hex_result += 'd';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += 'e';
- else
- hex_result += 'f';
- }
- }
- }
- }
- result = hex_result;
- // add the prefix
- result.insert((std::string::size_type)0, "0x");
- }
- }
- else
- {
- // convert to sign-magnitude
- // the representation is:
- // [radix#][sign]magnitude
- bool negative = local_i.negative();
- local_i.abs();
- // create a representation of the magnitude by successive division
- do
- {
- std::pair<inf,inf> divided = local_i.divide(t_radix);
- unsigned remainder = divided.second.to_unsigned();
- char digit = to_char[remainder];
- result.insert((std::string::size_type)0, 1, digit);
- local_i = divided.first;
- }
- while(!local_i.zero() || result.size() < width);
- // add the prefixes
- // add a sign only for negative values
- if (negative)
- result.insert((std::string::size_type)0, 1, '-');
- // then prefix everything with the radix if the hashed representation was requested
- if (hashed)
- result.insert((std::string::size_type)0, unsigned_to_string(radix) + "#");
- }
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // Conversions FROM string
-
- inf string_to_inf(const std::string& str, unsigned radix) throw(std::invalid_argument)
- {
- inf result;
- if (radix != 0 && (radix < 2 || radix > 36))
- throw std::invalid_argument("invalid radix value " + unsigned_to_string(radix));
- unsigned i = 0;
- // the radix passed as a parameter is just the default - it can be
- // overridden by either the C prefix or the hash prefix
- // Note: a leading zero is the C-style prefix for octal - I only make this
- // override the default when the default radix is not specified
- // first check for a C-style prefix
- bool c_style = false;
- if (i < str.size() && str[i] == '0')
- {
- // binary or hex
- if (i+1 < str.size() && tolower(str[i+1]) == 'x')
- {
- c_style = true;
- radix = 16;
- i += 2;
- }
- else if (i+1 < str.size() && tolower(str[i+1]) == 'b')
- {
- c_style = true;
- radix = 2;
- i += 2;
- }
- else if (radix == 0)
- {
- c_style = true;
- radix = 8;
- i += 1;
- }
- }
- // now check for a hash-style prefix if a C-style prefix was not found
- if (i == 0)
- {
- // scan for the sequence {digits}#
- bool hash_found = false;
- unsigned j = i;
- for (; j < str.size(); j++)
- {
- if (!isdigit(str[j]))
- {
- if (str[j] == '#')
- hash_found = true;
- break;
- }
- }
- if (hash_found)
- {
- // use the hash prefix to define the radix
- // i points to the start of the radix and j points to the # character
- std::string slice = str.substr(i, j-i);
- radix = string_to_unsigned(slice);
- i = j+1;
- }
- }
- if (radix == 0)
- radix = 10;
- if (radix < 2 || radix > 36)
- throw std::invalid_argument("invalid radix value");
- if (c_style)
- {
- // the C style formats are bit patterns not integer values - these need
- // to be sign-extended to get the right value
- std::string binary;
- if (radix == 2)
- {
- for (unsigned j = i; j < str.size(); j++)
- {
- switch(str[j])
- {
- case '0':
- binary += '0';
- break;
- case '1':
- binary += '1';
- break;
- default:
- throw std::invalid_argument("invalid binary character in string " + str);
- }
- }
- }
- else if (radix == 8)
- {
- for (unsigned j = i; j < str.size(); j++)
- {
- switch(str[j])
- {
- case '0':
- binary += "000";
- break;
- case '1':
- binary += "001";
- break;
- case '2':
- binary += "010";
- break;
- case '3':
- binary += "011";
- break;
- case '4':
- binary += "100";
- break;
- case '5':
- binary += "101";
- break;
- case '6':
- binary += "110";
- break;
- case '7':
- binary += "111";
- break;
- default:
- throw std::invalid_argument("invalid octal character in string " + str);
- }
- }
- }
- else
- {
- for (unsigned j = i; j < str.size(); j++)
- {
- switch(tolower(str[j]))
- {
- case '0':
- binary += "0000";
- break;
- case '1':
- binary += "0001";
- break;
- case '2':
- binary += "0010";
- break;
- case '3':
- binary += "0011";
- break;
- case '4':
- binary += "0100";
- break;
- case '5':
- binary += "0101";
- break;
- case '6':
- binary += "0110";
- break;
- case '7':
- binary += "0111";
- break;
- case '8':
- binary += "1000";
- break;
- case '9':
- binary += "1001";
- break;
- case 'a':
- binary += "1010";
- break;
- case 'b':
- binary += "1011";
- break;
- case 'c':
- binary += "1100";
- break;
- case 'd':
- binary += "1101";
- break;
- case 'e':
- binary += "1110";
- break;
- case 'f':
- binary += "1111";
- break;
- default:
- throw std::invalid_argument("invalid hex character in string " + str);
- }
- }
- }
- // now convert the value
- result.resize(binary.size());
- for (unsigned j = 0; j < binary.size(); j++)
- result.preset(binary.size() - j - 1, binary[j] == '1');
- }
- else
- {
- // now scan for a sign and find whether this is a negative number
- bool negative = false;
- if (i < str.size())
- {
- switch (str[i])
- {
- case '-':
- negative = true;
- i++;
- break;
- case '+':
- i++;
- break;
- }
- }
- for (; i < str.size(); i++)
- {
- result *= inf(radix);
- int ch = from_char[(unsigned char)str[i]] ;
- if (ch == -1)
- throw std::invalid_argument("invalid character in string " + str + " for radix " + unsigned_to_string(radix));
- result += inf(ch);
- }
- if (negative)
- result.negate();
- }
- return result;
- }
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_STRING_INF
-#define STLPLUS_STRING_INF
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// String conversion functions for the infinite precision integer type inf
-
-// The conversion supports all the formatting modes defined on format_types
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "inf.hpp"
-#include "format_types.hpp"
-#include <string>
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- // conversion TO string
- std::string inf_to_string(const inf&,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- // conversion FROM string
- inf string_to_inf(const std::string&,
- unsigned radix = 0)
- throw(std::invalid_argument);
-
-////////////////////////////////////////////////////////////////////////////////
-} // end namespace stlplus
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_int.hpp"
-#include <ctype.h>
-#include <stdlib.h>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // character mappings
-
- static char to_char [] = "0123456789abcdefghijklmnopqrstuvwxyz";
- static int from_char [] =
- {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
- };
-
- ////////////////////////////////////////////////////////////////////////////////
- // Conversions to string
- // Local generic routines
-
- // signed version of the generic image generation function for all integer types
- template<typename T>
- static std::string simage (T i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- if (radix < 2 || radix > 36)
- throw std::invalid_argument("invalid radix value " + unsigned_to_string(radix));
- // untangle all the options
- bool hashed = false;
- bool binary = false;
- bool octal = false;
- bool hex = false;
- switch(display)
- {
- case radix_none:
- break;
- case radix_hash_style:
- hashed = radix != 10;
- break;
- case radix_hash_style_all:
- hashed = true;
- break;
- case radix_c_style:
- if (radix == 16)
- hex = true;
- else if (radix == 8)
- octal = true;
- else if (radix == 2)
- binary = true;
- break;
- case radix_c_style_or_hash:
- if (radix == 16)
- hex = true;
- else if (radix == 8)
- octal = true;
- else if (radix == 2)
- binary = true;
- else if (radix != 10)
- hashed = true;
- break;
- default:
- throw std::invalid_argument("invalid radix display value");
- }
- // create constants of the same type as the template parameter to avoid type mismatches
- const T t_zero(0);
- const T t_radix(radix);
- // the C representations for binary, octal and hex use 2's-complement representation
- // all other represenations use sign-magnitude
- std::string result;
- if (hex || octal || binary)
- {
- // bit-pattern representation
- // this is the binary representation optionally shown in octal or hex
- // first generate the binary by masking the bits
- // ensure that it has at least one bit!
- for (T mask(1); ; mask <<= 1)
- {
- result.insert((std::string::size_type)0, 1, i & mask ? '1' : '0');
- if (mask == t_zero) break;
- }
- // the result is now the full width of the type - e.g. int will give a 32-bit result
- // now interpret this as either binary, octal or hex and add the prefix
- if (binary)
- {
- // the result is already binary - but the width may be wrong
- // if this is still smaller than the width field, sign extend
- // otherwise trim down to either the width or the smallest string that preserves the value
- while (result.size() < width)
- result.insert((std::string::size_type)0, 1, result[0]);
- while (result.size() > width)
- {
- // do not trim to less than 2 bits (sign plus 1-bit magnitude)
- if (result.size() <= 2) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != result[1]) break;
- result.erase(0,1);
- }
- // add the prefix
- result.insert((std::string::size_type)0, "0b");
- }
- else if (octal)
- {
- // the result is currently binary - but before converting get the width right
- // the width is expressed in octal digits so make the binary 3 times this
- // if this is still smaller than the width field, sign extend
- // otherwise trim down to either the width or the smallest string that preserves the value
- // also ensure that the binary is a multiple of 3 bits to make the conversion to octal easier
- while (result.size() < 3*width)
- result.insert((std::string::size_type)0, 1, result[0]);
- while (result.size() > 3*width)
- {
- // do not trim to less than 2 bits (sign plus 1-bit magnitude)
- if (result.size() <= 2) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != result[1]) break;
- result.erase(0,1);
- }
- while (result.size() % 3 != 0)
- result.insert((std::string::size_type)0, 1, result[0]);
- // now convert to octal
- std::string octal_result;
- for (unsigned i = 0; i < result.size()/3; i++)
- {
- // yuck - ugly or what?
- if (result[i*3] == '0')
- {
- if (result[i*3+1] == '0')
- {
- if (result[i*3+2] == '0')
- octal_result += '0';
- else
- octal_result += '1';
- }
- else
- {
- if (result[i*3+2] == '0')
- octal_result += '2';
- else
- octal_result += '3';
- }
- }
- else
- {
- if (result[i*3+1] == '0')
- {
- if (result[i*3+2] == '0')
- octal_result += '4';
- else
- octal_result += '5';
- }
- else
- {
- if (result[i*3+2] == '0')
- octal_result += '6';
- else
- octal_result += '7';
- }
- }
- }
- result = octal_result;
- // add the prefix
- result.insert((std::string::size_type)0, "0");
- }
- else
- {
- // hex - similar to octal
- while (result.size() < 4*width)
- result.insert((std::string::size_type)0, 1, result[0]);
- while (result.size() > 4*width)
- {
- // do not trim to less than 2 bits (sign plus 1-bit magnitude)
- if (result.size() <= 2) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != result[1]) break;
- result.erase(0,1);
- }
- while (result.size() % 4 != 0)
- result.insert((std::string::size_type)0, 1, result[0]);
- // now convert to hex
- std::string hex_result;
- for (unsigned i = 0; i < result.size()/4; i++)
- {
- // yuck - ugly or what?
- if (result[i*4] == '0')
- {
- if (result[i*4+1] == '0')
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '0';
- else
- hex_result += '1';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += '2';
- else
- hex_result += '3';
- }
- }
- else
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '4';
- else
- hex_result += '5';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += '6';
- else
- hex_result += '7';
- }
- }
- }
- else
- {
- if (result[i*4+1] == '0')
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '8';
- else
- hex_result += '9';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += 'a';
- else
- hex_result += 'b';
- }
- }
- else
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += 'c';
- else
- hex_result += 'd';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += 'e';
- else
- hex_result += 'f';
- }
- }
- }
- }
- result = hex_result;
- // add the prefix
- result.insert((std::string::size_type)0, "0x");
- }
- }
- else
- {
- // convert to sign-magnitude
- // the representation is:
- // [radix#][sign]magnitude
- bool negative = i < t_zero;
- // create a representation of the magnitude by successive division
- do
- {
- T ch = abs(i % t_radix);
- i /= t_radix;
- result.insert((std::string::size_type)0, 1, to_char[ch]);
- }
- while(i != t_zero || result.size() < width);
- // add the prefixes
- // add a sign only for negative values
- if (negative)
- result.insert((std::string::size_type)0, 1, '-');
- // then prefix everything with the radix if the hashed representation was requested
- if (hashed)
- result.insert((std::string::size_type)0, unsigned_to_string(radix) + "#");
- }
- return result;
- }
-
- // unsigned version
- template<typename T>
- static std::string uimage (T i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- if (radix < 2 || radix > 36)
- throw std::invalid_argument("invalid radix value " + unsigned_to_string(radix));
- // untangle all the options
- bool hashed = false;
- bool binary = false;
- bool octal = false;
- bool hex = false;
- switch(display)
- {
- case radix_none:
- break;
- case radix_hash_style:
- hashed = radix != 10;
- break;
- case radix_hash_style_all:
- hashed = true;
- break;
- case radix_c_style:
- if (radix == 16)
- hex = true;
- else if (radix == 8)
- octal = true;
- else if (radix == 2)
- binary = true;
- break;
- case radix_c_style_or_hash:
- if (radix == 16)
- hex = true;
- else if (radix == 8)
- octal = true;
- else if (radix == 2)
- binary = true;
- else if (radix != 10)
- hashed = true;
- break;
- default:
- throw std::invalid_argument("invalid radix display value");
- }
- // create constants of the same type as the template parameter to avoid type mismatches
- const T t_zero(0);
- const T t_radix(radix);
- // the C representations for binary, octal and hex use 2's-complement representation
- // all other represenations use sign-magnitude
- std::string result;
- if (hex || octal || binary)
- {
- // bit-pattern representation
- // this is the binary representation optionally shown in octal or hex
- // first generate the binary by masking the bits
- // ensure at least one bit
- for (T mask(1); ; mask <<= 1)
- {
- result.insert((std::string::size_type)0, 1, i & mask ? '1' : '0');
- if (mask == t_zero) break;
- }
- // the result is now the full width of the type - e.g. int will give a 32-bit result
- // now interpret this as either binary, octal or hex and add the prefix
- if (binary)
- {
- // the result is already binary - but the width may be wrong
- // if this is still smaller than the width field, zero extend
- // otherwise trim down to either the width or the smallest string that preserves the value
- while (result.size() < width)
- result.insert((std::string::size_type)0, 1, '0');
- while (result.size() > width)
- {
- // do not trim to less than 1 bit (1-bit magnitude)
- if (result.size() <= 1) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != '0') break;
- result.erase(0,1);
- }
- // add the prefix
- result.insert((std::string::size_type)0, "0b");
- }
- else if (octal)
- {
- // the result is currently binary - but before converting get the width right
- // the width is expressed in octal digits so make the binary 3 times this
- // if this is still smaller than the width field, sign extend
- // otherwise trim down to either the width or the smallest string that preserves the value
- // also ensure that the binary is a multiple of 3 bits to make the conversion to octal easier
- while (result.size() < 3*width)
- result.insert((std::string::size_type)0, 1, '0');
- while (result.size() > 3*width)
- {
- // do not trim to less than 1 bit (1-bit magnitude)
- if (result.size() <= 1) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != '0') break;
- result.erase(0,1);
- }
- while (result.size() % 3 != 0)
- result.insert((std::string::size_type)0, 1, '0');
- // now convert to octal
- std::string octal_result;
- for (unsigned i = 0; i < result.size()/3; i++)
- {
- // yuck - ugly or what?
- if (result[i*3] == '0')
- {
- if (result[i*3+1] == '0')
- {
- if (result[i*3+2] == '0')
- octal_result += '0';
- else
- octal_result += '1';
- }
- else
- {
- if (result[i*3+2] == '0')
- octal_result += '2';
- else
- octal_result += '3';
- }
- }
- else
- {
- if (result[i*3+1] == '0')
- {
- if (result[i*3+2] == '0')
- octal_result += '4';
- else
- octal_result += '5';
- }
- else
- {
- if (result[i*3+2] == '0')
- octal_result += '6';
- else
- octal_result += '7';
- }
- }
- }
- result = octal_result;
- // add the prefix if the leading digit is not already 0
- if (result.empty() || result[0] != '0') result.insert((std::string::size_type)0, "0");
- }
- else
- {
- // similar to octal
- while (result.size() < 4*width)
- result.insert((std::string::size_type)0, 1, '0');
- while (result.size() > 4*width)
- {
- // do not trim to less than 1 bit (1-bit magnitude)
- if (result.size() <= 1) break;
- // only trim if it doesn't change the sign and therefore the value
- if (result[0] != '0') break;
- result.erase(0,1);
- }
- while (result.size() % 4 != 0)
- result.insert((std::string::size_type)0, 1, '0');
- // now convert to hex
- std::string hex_result;
- for (unsigned i = 0; i < result.size()/4; i++)
- {
- // yuck - ugly or what?
- if (result[i*4] == '0')
- {
- if (result[i*4+1] == '0')
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '0';
- else
- hex_result += '1';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += '2';
- else
- hex_result += '3';
- }
- }
- else
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '4';
- else
- hex_result += '5';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += '6';
- else
- hex_result += '7';
- }
- }
- }
- else
- {
- if (result[i*4+1] == '0')
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += '8';
- else
- hex_result += '9';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += 'a';
- else
- hex_result += 'b';
- }
- }
- else
- {
- if (result[i*4+2] == '0')
- {
- if (result[i*4+3] == '0')
- hex_result += 'c';
- else
- hex_result += 'd';
- }
- else
- {
- if (result[i*4+3] == '0')
- hex_result += 'e';
- else
- hex_result += 'f';
- }
- }
- }
- }
- result = hex_result;
- // add the prefix
- result.insert((std::string::size_type)0, "0x");
- }
- }
- else
- {
- // convert to sign-magnitude
- // the representation is:
- // [radix#]magnitude
- // create a representation of the magnitude by successive division
- do
- {
- T ch = i % t_radix;
- i /= t_radix;
- result.insert((std::string::size_type)0, 1, to_char[(int)ch]);
- }
- while(i != t_zero || result.size() < width);
- // prefix everything with the radix if the hashed representation was requested
- if (hashed)
- result.insert((std::string::size_type)0, unsigned_to_string(radix) + "#");
- }
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // exported conversions to string
-
- std::string short_to_string(short i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- return simage(i, radix, display, width);
- }
-
- std::string unsigned_short_to_string(unsigned short i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- return uimage(i, radix, display, width);
- }
-
- std::string int_to_string(int i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- return simage(i, radix, display, width);
- }
-
- std::string unsigned_to_string(unsigned i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- return uimage(i, radix, display, width);
- }
-
- std::string long_to_string(long i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- return simage(i, radix, display, width);
- }
-
- std::string unsigned_long_to_string(unsigned long i, unsigned radix, radix_display_t display, unsigned width)
- throw(std::invalid_argument)
- {
- return uimage(i, radix, display, width);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // Conversions FROM string
- // local template function
- // Note: this has been copied and modified for the inf class - so any changes here must be made there too
-
- // signed version
- template<typename T>
- static T svalue(const std::string& str, unsigned radix)
- throw(std::invalid_argument)
- {
- if (radix != 0 && (radix < 2 || radix > 36))
- throw std::invalid_argument("invalid radix value " + unsigned_to_string(radix));
- std::string::size_type i = 0;
- // the radix passed as a parameter is just the default - it can be
- // overridden by either the C prefix or the hash prefix. Note: a leading zero
- // is the C-style prefix for octal - I only make this override the default
- // when the default prefix is not specified
- // First check for a C-style prefix
- bool c_style = false;
- if (i < str.size() && str[i] == '0')
- {
- // octal, binary or hex
- if (i+1 < str.size() && tolower(str[i+1]) == 'x')
- {
- radix = 16;
- i += 2;
- c_style = true;
- }
- else if (i+1 < str.size() && tolower(str[i+1]) == 'b')
- {
- radix = 2;
- i += 2;
- c_style = true;
- }
- else if (radix == 0)
- {
- radix = 8;
- i += 1;
- c_style = true;
- }
- }
- // now check for a hash-style prefix if a C-style prefix was not found
- if (i == 0)
- {
- // scan for the sequence {digits}#
- bool hash_found = false;
- std::string::size_type j = i;
- for (; j < str.size(); j++)
- {
- if (!isdigit(str[j]))
- {
- if (str[j] == '#')
- hash_found = true;
- break;
- }
- }
- if (hash_found)
- {
- // use the hash prefix to define the radix
- // i points to the start of the radix and j points to the # character
- std::string slice = str.substr(i, j-i);
- radix = string_to_unsigned(slice);
- i = j+1;
- }
- }
- if (radix == 0)
- radix = 10;
- if (radix < 2 || radix > 36)
- throw std::invalid_argument("invalid radix value " + unsigned_to_string(radix));
- T val(0);
- if (c_style)
- {
- // the C style formats are bit patterns not integer values - these need
- // to be sign-extended to get the right value
- std::string binary;
- if (radix == 2)
- {
- for (std::string::size_type j = i; j < str.size(); j++)
- {
- switch(str[j])
- {
- case '0':
- binary += '0';
- break;
- case '1':
- binary += '1';
- break;
- default:
- throw std::invalid_argument("invalid binary character in string " + str);
- break;
- }
- }
- }
- else if (radix == 8)
- {
- for (std::string::size_type j = i; j < str.size(); j++)
- {
- switch(str[j])
- {
- case '0':
- binary += "000";
- break;
- case '1':
- binary += "001";
- break;
- case '2':
- binary += "010";
- break;
- case '3':
- binary += "011";
- break;
- case '4':
- binary += "100";
- break;
- case '5':
- binary += "101";
- break;
- case '6':
- binary += "110";
- break;
- case '7':
- binary += "111";
- break;
- default:
- throw std::invalid_argument("invalid octal character in string " + str);
- break;
- }
- }
- }
- else
- {
- for (std::string::size_type j = i; j < str.size(); j++)
- {
- switch(tolower(str[j]))
- {
- case '0':
- binary += "0000";
- break;
- case '1':
- binary += "0001";
- break;
- case '2':
- binary += "0010";
- break;
- case '3':
- binary += "0011";
- break;
- case '4':
- binary += "0100";
- break;
- case '5':
- binary += "0101";
- break;
- case '6':
- binary += "0110";
- break;
- case '7':
- binary += "0111";
- break;
- case '8':
- binary += "1000";
- break;
- case '9':
- binary += "1001";
- break;
- case 'a':
- binary += "1010";
- break;
- case 'b':
- binary += "1011";
- break;
- case 'c':
- binary += "1100";
- break;
- case 'd':
- binary += "1101";
- break;
- case 'e':
- binary += "1110";
- break;
- case 'f':
- binary += "1111";
- break;
- default:
- throw std::invalid_argument("invalid hex character in string " + str);
- break;
- }
- }
- }
- // now sign-extend to the right number of bits for the type
- while (binary.size() < sizeof(T)*8)
- binary.insert((std::string::size_type)0, 1, binary.empty() ? '0' : binary[0]);
- // now convert the value
- for (std::string::size_type j = 0; j < binary.size(); j++)
- {
- val *= 2;
- int ch = from_char[(unsigned char)binary[j]] ;
- val += T(ch);
- }
- }
- else
- {
- // now scan for a sign and find whether this is a negative number
- bool negative = false;
- if (i < str.size())
- {
- switch (str[i])
- {
- case '-':
- negative = true;
- i++;
- break;
- case '+':
- i++;
- break;
- }
- }
- for (; i < str.size(); i++)
- {
- val *= T(radix);
- int ch = from_char[(unsigned char)str[i]] ;
- if (ch == -1 || (unsigned)ch >= radix)
- throw std::invalid_argument("invalid character in string " + str);
- val += T(ch);
- }
- if (negative)
- val = -val;
- }
- return val;
- }
-
- // unsigned version
- template<typename T>
- static T uvalue(const std::string& str, unsigned radix)
- throw(std::invalid_argument)
- {
- if (radix != 0 && (radix < 2 || radix > 36))
- throw std::invalid_argument("invalid radix value " + unsigned_to_string(radix));
- unsigned i = 0;
- // the radix passed as a parameter is just the default - it can be
- // overridden by either the C prefix or the hash prefix. Note: a leading
- // zero is the C-style prefix for octal - I only make this override the
- // default when the default prefix is not specified
- // First check for a C-style prefix
- bool c_style = false;
- if (i < str.size() && str[i] == '0')
- {
- // binary or hex
- if (i+1 < str.size() && tolower(str[i+1]) == 'x')
- {
- radix = 16;
- i += 2;
- c_style = true;
- }
- else if (i+1 < str.size() && tolower(str[i+1]) == 'b')
- {
- radix = 2;
- i += 2;
- c_style = true;
- }
- else if (radix == 0)
- {
- radix = 8;
- i += 1;
- c_style = true;
- }
- }
- // now check for a hash-style prefix if a C-style prefix was not found
- if (i == 0)
- {
- // scan for the sequence {digits}#
- bool hash_found = false;
- unsigned j = i;
- for (; j < str.size(); j++)
- {
- if (!isdigit(str[j]))
- {
- if (str[j] == '#')
- hash_found = true;
- break;
- }
- }
- if (hash_found)
- {
- // use the hash prefix to define the radix
- // i points to the start of the radix and j points to the # character
- std::string slice = str.substr(i, j-i);
- radix = string_to_unsigned(slice);
- i = j+1;
- }
- }
- if (radix == 0)
- radix = 10;
- if (radix < 2 || radix > 36)
- throw std::invalid_argument("invalid radix value " + unsigned_to_string(radix));
- T val(0);
- if (c_style)
- {
- // the C style formats are bit patterns not integer values - these need
- // to be sign-extended to get the right value
- std::string binary;
- if (radix == 2)
- {
- for (unsigned j = i; j < str.size(); j++)
- {
- switch(str[j])
- {
- case '0':
- binary += '0';
- break;
- case '1':
- binary += '1';
- break;
- default:
- throw std::invalid_argument("invalid hex character in string " + str);
- break;
- }
- }
- }
- else if (radix == 8)
- {
- for (unsigned j = i; j < str.size(); j++)
- {
- switch(str[j])
- {
- case '0':
- binary += "000";
- break;
- case '1':
- binary += "001";
- break;
- case '2':
- binary += "010";
- break;
- case '3':
- binary += "011";
- break;
- case '4':
- binary += "100";
- break;
- case '5':
- binary += "101";
- break;
- case '6':
- binary += "110";
- break;
- case '7':
- binary += "111";
- break;
- default:
- throw std::invalid_argument("invalid octal character in string " + str);
- break;
- }
- }
- }
- else
- {
- for (unsigned j = i; j < str.size(); j++)
- {
- switch(tolower(str[j]))
- {
- case '0':
- binary += "0000";
- break;
- case '1':
- binary += "0001";
- break;
- case '2':
- binary += "0010";
- break;
- case '3':
- binary += "0011";
- break;
- case '4':
- binary += "0100";
- break;
- case '5':
- binary += "0101";
- break;
- case '6':
- binary += "0110";
- break;
- case '7':
- binary += "0111";
- break;
- case '8':
- binary += "1000";
- break;
- case '9':
- binary += "1001";
- break;
- case 'a':
- binary += "1010";
- break;
- case 'b':
- binary += "1011";
- break;
- case 'c':
- binary += "1100";
- break;
- case 'd':
- binary += "1101";
- break;
- case 'e':
- binary += "1110";
- break;
- case 'f':
- binary += "1111";
- break;
- default:
- throw std::invalid_argument("invalid hex character in string " + str);
- break;
- }
- }
- }
- // now zero-extend to the right number of bits for the type
- while (binary.size() < sizeof(T)*8)
- binary.insert((std::string::size_type)0, 1, '0');
- // now convert the value
- for (unsigned j = 0; j < binary.size(); j++)
- {
- val *= 2;
- int ch = from_char[(unsigned char)binary[j]] ;
- val += T(ch);
- }
- }
- else
- {
- // now scan for a sign and find whether this is a negative number
- if (i < str.size())
- {
- switch (str[i])
- {
- case '-':
- throw std::invalid_argument("invalid sign character in string " + str + " for unsigned value");
- i++;
- break;
- case '+':
- i++;
- break;
- }
- }
- for (; i < str.size(); i++)
- {
- val *= T(radix);
- int ch = from_char[(unsigned char)str[i]] ;
- if (ch == -1 || (unsigned)ch >= radix)
- {
- throw std::invalid_argument("invalid character in string " + str);
- }
- val += T(ch);
- }
- }
- return val;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // exported functions
-
- short string_to_short(const std::string& str, unsigned radix)
- throw(std::invalid_argument)
- {
- return svalue<short>(str, radix);
- }
-
- unsigned short string_to_unsigned_short(const std::string& str, unsigned radix)
- throw(std::invalid_argument)
- {
- return uvalue<unsigned short>(str, radix);
- }
-
- int string_to_int(const std::string& str, unsigned radix)
- throw(std::invalid_argument)
- {
- return svalue<int>(str, radix);
- }
-
- unsigned string_to_unsigned(const std::string& str, unsigned radix)
- throw(std::invalid_argument)
- {
- return uvalue<unsigned>(str, radix);
- }
-
- long string_to_long(const std::string& str, unsigned radix)
- throw(std::invalid_argument)
- {
- return svalue<long>(str, radix);
- }
-
- unsigned long string_to_unsigned_long(const std::string& str, unsigned radix)
- throw(std::invalid_argument)
- {
- return uvalue<unsigned long>(str, radix);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_INT
-#define STLPLUS_STRING_INT
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Convert integer types to/from string
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "format_types.hpp"
-#include <string>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // Conversions of Integer types to string
- ////////////////////////////////////////////////////////////////////////////////
-
- // The radix (i.e. base) for these conversions can be any value from base 2 to base 36
- // specifying any other radix causes std::invalid_argument to be thrown
-
- // The way in which the radix is displayed is defined in radix_types.hpp
- // If any other value is used, std::invalid_argument is thrown
-
- // The width argument specifies the number of numerical digits to use in the result
- // This is a minimum - if the value requires more digits then it will be wider than the width argument
- // However, if it is smaller, then it will be extended to the specified width
- // Then, the radix display prefix is added to this width
-
- // For example, using the hash representation of 0 in hex with width=4 gives:
- // 16#0000 - so there's 4 digits in the number part
-
- std::string short_to_string(short i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- std::string unsigned_short_to_string(unsigned short i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- std::string int_to_string(int i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- std::string unsigned_to_string(unsigned i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- std::string long_to_string(long i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- std::string unsigned_long_to_string(unsigned long i,
- unsigned radix = 10,
- radix_display_t display = radix_c_style_or_hash,
- unsigned width = 0)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
- // Convert a string to an integer type
- ////////////////////////////////////////////////////////////////////////////////
- // supports all the formats described above for the reverse conversion
- // If the radix is set to zero, the conversions deduce the radix from the string representation
- // So,
- // 0b prefix is binary,
- // 0 prefix is octal,
- // 0x is hex
- // <base># prefix is my hash format
- // The radix must be either zero as explained above, or in the range 2 to 16
- // A non-zero radix should be used when the string value has no radix information and is non-decimal
- // e.g. the hex value FEDCBA has no indication that it is hex, so specify radix 16
- // Any other value of radix will cause std::invalid_argument to be thrown
-
- short string_to_short(const std::string& value,
- unsigned radix = 0)
- throw(std::invalid_argument);
-
- unsigned short string_to_unsigned_short(const std::string& value,
- unsigned radix = 0)
- throw(std::invalid_argument);
-
- int string_to_int(const std::string& value,
- unsigned radix = 0)
- throw(std::invalid_argument);
-
- unsigned string_to_unsigned(const std::string& value,
- unsigned radix = 0)
- throw(std::invalid_argument);
-
- long string_to_long(const std::string& value,
- unsigned radix = 0)
- throw(std::invalid_argument);
-
- unsigned long string_to_unsigned_long(const std::string& value,
- unsigned radix = 0)
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_STRING_LIST
-#define STLPLUS_STRING_LIST
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a list
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <list>
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- std::string list_to_string(const std::list<T>& values,
- S to_string_fn,
- const std::string& separator = ",");
-
-} // end namespace stlplus
-
-#include "string_list.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// template implementations
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_sequence.hpp"
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- std::string list_to_string(const std::list<T>& values,
- S to_string_fn,
- const std::string& separator)
- {
- return sequence_to_string(values.begin(), values.end(), to_string_fn, separator);
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_MAP
-#define STLPLUS_STRING_MAP
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a map/multimap
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <map>
-
-namespace stlplus
-{
-
- template<typename K, typename T, typename C, typename SK, typename ST>
- std::string map_to_string(const std::map<K,T,C>& values,
- SK key_to_string_fn,
- ST value_to_string_fn,
- const std::string& pair_separator = ":",
- const std::string& separator = ",");
-
- template<typename K, typename T, typename C, typename SK, typename ST>
- std::string multimap_to_string(const std::multimap<K,T,C>& values,
- SK key_to_string_fn,
- ST value_to_string_fn,
- const std::string& pair_separator = ":",
- const std::string& separator = ",");
-
-} // end namespace stlplus
-
-#include "string_map.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_sequence.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // map
-
- template<typename K, typename T, typename C, typename SK, typename ST>
- std::string map_to_string(const std::map<K,T,C>& values,
- SK key_to_string_fn,
- ST value_to_string_fn,
- const std::string& pair_separator,
- const std::string& separator)
- {
- return pair_sequence_to_string(values.begin(), values.end(),
- key_to_string_fn, value_to_string_fn,
- pair_separator, separator);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // multimap
-
- template<typename K, typename T, typename C, typename SK, typename ST>
- std::string multimap_to_string(const std::multimap<K,T,C>& values,
- SK key_to_string_fn,
- ST value_to_string_fn,
- const std::string& pair_separator,
- const std::string& separator)
- {
- return pair_sequence_to_string(values.begin(), values.end(),
- key_to_string_fn, value_to_string_fn,
- pair_separator, separator);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_MATRIX
-#define STLPLUS_STRING_MATRIX
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a matrix
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "matrix.hpp"
-#include <string>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- std::string matrix_to_string(const matrix<T>& values,
- S to_string_fn,
- const std::string& column_separator = "|",
- const std::string& row_separator = ",");
-
-} // end namespace stlplus
-
-#include "string_matrix.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
-
- template<typename T, typename S>
- std::string matrix_to_string(const matrix<T>& values,
- S to_string_fn,
- const std::string& column_separator,
- const std::string& row_separator)
- {
- std::string result;
- for (unsigned r = 0; r < values.rows(); r++)
- {
- if (r != 0) result += row_separator;
- for (unsigned c = 0; c < values.columns(); c++)
- {
- if (c != 0) result += column_separator;
- result += to_string_fn(values(r,c));
- }
- }
- return result;
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-#ifndef STLPLUS_STRING_NTREE
-#define STLPLUS_STRING_NTREE
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of an ntree
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "ntree.hpp"
-#include <string>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- std::string ntree_to_string(const ntree<T>& values,
- S to_string_fn,
- const std::string& separator = "|",
- const std::string& indent_string = " ");
-
-} // end namespace stlplus
-
-#include "string_ntree.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- std::string ntree_to_string(const ntree<T>& values,
- S to_string_fn,
- const std::string& separator,
- const std::string& indent_string)
- {
- std::string result;
- for (TYPENAME ntree<T>::const_prefix_iterator i = values.prefix_begin(); i != values.prefix_end(); i++)
- {
- if (i != values.prefix_begin()) result += separator;
- for (unsigned indent = values.depth(i.simplify()); --indent; )
- result += indent_string;
- result += to_string_fn(*i);
- }
- return result;
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-#ifndef STLPLUS_STRING_PAIR
-#define STLPLUS_STRING_PAIR
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a pair
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <map>
-#include <string>
-
-namespace stlplus
-{
-
- template<typename V1, typename V2, typename S1, typename S2>
- std::string pair_to_string(const std::pair<V1,V2>& values,
- S1 to_string_fn1,
- S2 to_string_fn2,
- const std::string& separator = ":");
-
-} // end namespace stlplus
-
-#include "string_pair.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename V1, typename V2, typename S1, typename S2>
- std::string pair_to_string(const std::pair<V1,V2>& values,
- S1 to_string_fn1,
- S2 to_string_fn2,
- const std::string& separator)
- {
- return to_string_fn1(values.first) + separator + to_string_fn2(values.second);
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_POINTER
-#define STLPLUS_STRING_POINTER
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of an object pointed to
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-
-namespace stlplus
-{
-
- template <typename T, typename S>
- std::string pointer_to_string(const T* value,
- S to_string_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
-
-}
-
-#include "string_pointer.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include <string>
-
-namespace stlplus
-{
-
- template <typename T, typename S>
- std::string pointer_to_string(const T* value,
- S to_string_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- return value ? (prefix + to_string_fn(*value) + suffix) : null_string;
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_SEQUENCE
-#define STLPLUS_STRING_SEQUENCE
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate string representations of sequences represented by forward iterators
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // any forward iterator sequence
-
- template <typename I, typename S>
- std::string sequence_to_string(I begin,
- I end,
- S to_string,
- const std::string& separator);
-
-
- ////////////////////////////////////////////////////////////////////////////////
- // any forward iterator sequence of pairs
-
- template <typename I, typename S1, typename S2>
- std::string pair_sequence_to_string(I begin,
- I end,
- S1 to_string_fn1,
- S2 to_string_fn2,
- const std::string& pair_separator,
- const std::string& separator);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#include "string_sequence.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_pair.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // any forward iterator sequence
-
- template <typename I, typename S>
- std::string sequence_to_string(I begin,
- I end,
- S to_string,
- const std::string& separator)
- {
- std::string result;
- for (I i = begin; i != end; i++)
- {
- if (i != begin) result += separator;
- result += to_string(*i);
- }
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // any sequence where the value is a pair
-
- template <typename I, typename S1, typename S2>
- std::string pair_sequence_to_string(I begin,
- I end,
- S1 to_string_fn1,
- S2 to_string_fn2,
- const std::string& pair_separator,
- const std::string& separator)
- {
- std::string result;
- for (I i = begin; i != end; i++)
- {
- if (i != begin) result += separator;
- result += pair_to_string(*i, to_string_fn1, to_string_fn2, pair_separator);
- }
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_SET
-#define STLPLUS_STRING_SET
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a set/multiset
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <set>
-
-namespace stlplus
-{
-
- template<typename K, typename C, typename S>
- std::string set_to_string(const std::set<K,C>& values,
- S to_string_fn,
- const std::string& separator = ",");
-
- template<typename K, typename C, typename S>
- std::string multiset_to_string(const std::multiset<K,C>& values,
- S to_string_fn,
- const std::string& separator = ",");
-
-} // end namespace stlplus
-
-#include "string_set.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// template implementations
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_sequence.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // set
-
- template<typename K, typename C, typename S>
- std::string set_to_string(const std::set<K,C>& values,
- S to_string_fn,
- const std::string& separator)
- {
- return sequence_to_string(values.begin(), values.end(), to_string_fn, separator);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // multiset
-
- template<typename K, typename C, typename S>
- std::string multiset_to_string(const std::multiset<K,C>& values,
- S to_string_fn,
- const std::string& separator)
- {
- return sequence_to_string(values.begin(), values.end(), to_string_fn, separator);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_SIMPLE_PTR
-#define STLPLUS_STRING_SIMPLE_PTR
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a smart pointer
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "simple_ptr.hpp"
-#include <string>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- std::string simple_ptr_to_string(const simple_ptr<T>& value,
- S to_string_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
- template<typename T, typename S>
- std::string simple_ptr_clone_to_string(const simple_ptr_clone<T>& value,
- S to_string_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
- template<typename T, typename S>
- std::string simple_ptr__nocopy_to_string(const simple_ptr_nocopy<T>& value,
- S to_string_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
-
-} // end namespace stlplus
-
-#include "string_simple_ptr.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- std::string simple_ptr_to_string(const simple_ptr<T>& value,
- S to_string_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- return value ? (prefix + to_string_fn(*value) + suffix) : null_string;
- }
-
- template<typename T, typename S>
- std::string simple_ptr_clone_to_string(const simple_ptr_clone<T>& value,
- S to_string_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- return value ? (prefix + to_string_fn(*value) + suffix) : null_string;
- }
-
- template<typename T, typename S>
- std::string simple_ptr_nocopy_to_string(const simple_ptr_nocopy<T>& value,
- S to_string_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- return value ? (prefix + to_string_fn(*value) + suffix) : null_string;
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-#ifndef STLPLUS_STRING_SMART_PTR
-#define STLPLUS_STRING_SMART_PTR
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a smart pointer
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "smart_ptr.hpp"
-#include <string>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- std::string smart_ptr_to_string(const smart_ptr<T>& value,
- S to_string_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
- template<typename T, typename S>
- std::string smart_ptr_clone_to_string(const smart_ptr_clone<T>& value,
- S to_string_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
- template<typename T, typename S>
- std::string smart_ptr__nocopy_to_string(const smart_ptr_nocopy<T>& value,
- S to_string_fn,
- const std::string& null_string = "<null>",
- const std::string& prefix = "(",
- const std::string& suffix = ")");
-
-
-} // end namespace stlplus
-
-#include "string_smart_ptr.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- std::string smart_ptr_to_string(const smart_ptr<T>& value,
- S to_string_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- return value ? (prefix + to_string_fn(*value) + suffix) : null_string;
- }
-
- template<typename T, typename S>
- std::string smart_ptr_clone_to_string(const smart_ptr_clone<T>& value,
- S to_string_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- return value ? (prefix + to_string_fn(*value) + suffix) : null_string;
- }
-
- template<typename T, typename S>
- std::string smart_ptr_nocopy_to_string(const smart_ptr_nocopy<T>& value,
- S to_string_fn,
- const std::string& null_string,
- const std::string& prefix,
- const std::string& suffix)
- {
- return value ? (prefix + to_string_fn(*value) + suffix) : null_string;
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-#ifndef STLPLUS_STRING_STL
-#define STLPLUS_STRING_STL
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Template string conversions for pointers and STL containers
-
-////////////////////////////////////////////////////////////////////////////////
-
-#include "string_bitset.hpp"
-#include "string_list.hpp"
-#include "string_map.hpp"
-#include "string_pair.hpp"
-#include "string_sequence.hpp"
-#include "string_set.hpp"
-#include "string_string.hpp"
-#include "string_vector.hpp"
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_STRING_STLPLUS
-#define STLPLUS_STRING_STLPLUS
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Template string conversions for the STLplus containers
-
-////////////////////////////////////////////////////////////////////////////////
-
-// can be excluded to break the dependency on the containers library
-#ifndef NO_STLPLUS_CONTAINERS
-#include "string_digraph.hpp"
-#include "string_foursome.hpp"
-#include "string_hash.hpp"
-#include "string_matrix.hpp"
-#include "string_ntree.hpp"
-#include "string_smart_ptr.hpp"
-#include "string_triple.hpp"
-#endif
-
-// can be excluded to break the dependency on the portability library
-#ifndef NO_STLPLUS_INF
-#include "string_inf.hpp"
-#endif
-
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_string.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // strings
-
- std::string string_to_string(const std::string& value)
- {
- return value;
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_STRING
-#define STLPLUS_STRING_STRING
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Functions for converting C/STL strings to string
-
-// This is necessary for completeness, e.g. for use in vector_to_string for vector<string>
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <stdexcept>
-
-namespace stlplus
-{
-
- std::string string_to_string(const std::string& value);
-
-}
-
-#endif
+++ /dev/null
-#ifndef STLPLUS_STRING_TRIPLE
-#define STLPLUS_STRING_TRIPLE
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a triple
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "triple.hpp"
-#include <string>
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T1, typename T2, typename T3, typename S1, typename S2, typename S3>
- std::string triple_to_string(const triple<T1,T2,T3>& values,
- S1 to_string_fn1,
- S2 to_string_fn2,
- S3 to_string_fn3,
- const std::string& separator = ":");
-
-} // end namespace stlplus
-
-#include "string_triple.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-
-namespace stlplus
-{
-
- template<typename T1, typename T2, typename T3, typename S1, typename S2, typename S3>
- std::string triple_to_string(const triple<T1,T2,T3>& values,
- S1 to_string_fn1,
- S2 to_string_fn2,
- S3 to_string_fn3,
- const std::string& separator)
- {
- return
- to_string_fn1(values.first) +
- separator +
- to_string_fn2(values.second) +
- separator +
- to_string_fn3(values.third);
- }
-
-} // end namespace stlplus
-
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_utilities.hpp"
-#include "string_basic.hpp"
-#include <stdlib.h>
-#include <ctype.h>
-#include <stdarg.h>
-#include <stdio.h>
-
-namespace stlplus
-{
-
- // added as a local copy to break the dependency on the portability library
- static std::string local_dformat(const char* format, ...) throw(std::invalid_argument)
- {
- std::string formatted;
- va_list args;
- va_start(args, format);
-#ifdef MSWINDOWS
- int length = 0;
- char* buffer = 0;
- for(int buffer_length = 256; ; buffer_length*=2)
- {
- buffer = (char*)malloc(buffer_length);
- if (!buffer) throw std::invalid_argument("string_utilities");
- length = _vsnprintf(buffer, buffer_length-1, format, args);
- if (length >= 0)
- {
- buffer[length] = 0;
- formatted += std::string(buffer);
- free(buffer);
- break;
- }
- free(buffer);
- }
-#else
- char* buffer = 0;
- int length = vasprintf(&buffer, format, args);
- if (!buffer) throw std::invalid_argument("string_utilities");
- if (length >= 0)
- formatted += std::string(buffer);
- free(buffer);
-#endif
- va_end(args);
- if (length < 0) throw std::invalid_argument("string_utilities");
- return formatted;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string pad(const std::string& str, alignment_t alignment, unsigned width, char padch)
- throw(std::invalid_argument)
- {
- std::string result = str;
- switch(alignment)
- {
- case align_left:
- {
- unsigned padding = width>str.size() ? width - str.size() : 0;
- unsigned i = 0;
- while (i++ < padding)
- result.insert(result.end(), padch);
- break;
- }
- case align_right:
- {
- unsigned padding = width>str.size() ? width - str.size() : 0;
- unsigned i = 0;
- while (i++ < padding)
- result.insert(result.begin(), padch);
- break;
- }
- case align_centre:
- {
- unsigned padding = width>str.size() ? width - str.size() : 0;
- unsigned i = 0;
- while (i++ < padding/2)
- result.insert(result.end(), padch);
- i--;
- while (i++ < padding)
- result.insert(result.begin(), padch);
- break;
- }
- default:
- throw std::invalid_argument("invalid alignment value");
- }
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string trim_left(const std::string& val)
- {
- std::string result = val;
- while (!result.empty() && isspace(result[0]))
- result.erase(result.begin());
- return result;
- }
-
- std::string trim_right(const std::string& val)
- {
- std::string result = val;
- while (!result.empty() && isspace(result[result.size()-1]))
- result.erase(result.end()-1);
- return result;
- }
-
- std::string trim(const std::string& val)
- {
- std::string result = val;
- while (!result.empty() && isspace(result[0]))
- result.erase(result.begin());
- while (!result.empty() && isspace(result[result.size()-1]))
- result.erase(result.end()-1);
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string lowercase(const std::string& val)
- {
- std::string text = val;
- for (unsigned i = 0; i < text.size(); i++)
- text[i] = tolower(text[i]);
- return text;
- }
-
- std::string uppercase(const std::string& val)
- {
- std::string text = val;
- for (unsigned i = 0; i < text.size(); i++)
- text[i] = toupper(text[i]);
- return text;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string translate(const std::string& input, const std::string& from_set, const std::string& to_set)
- {
- std::string result;
- for (unsigned i = 0; i < input.size(); i++)
- {
- char ch = input[i];
- // check to see if the character is in the from set
- std::string::size_type found = from_set.find(ch);
- if (found == std::string::npos)
- {
- // not found so just copy across
- result += ch;
- }
- else if (found < to_set.size())
- {
- // found and in range so translate
- result += to_set[found];
- }
- }
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- // WARNING: wheel re-invention follows
- // Given that all shells perform wildcard matching, why don't the library writers put it in the C run-time????????
- // The problem:
- // * matches any number of characters - this is achieved by matching 1 and seeing if the remainder matches
- // if not, try 2 characters and see if the remainder matches etc.
- // this must be recursive, not iterative, so that multiple *s can appear in the same wildcard expression
- // ? matches exactly one character so doesn't need the what-if approach
- // \ escapes special characters such as *, ? and [
- // [] matches exactly one character in the set - the difficulty is the set can contain ranges, e.g [a-zA-Z0-9]
- // a set cannot be empty and the ] character can be included by making it the first character
-
- // function for testing whether a character matches a set
- // I can't remember the exact rules and I have no definitive references but:
- // a set contains characters, escaped characters (I think) and ranges in the form a-z
- // The character '-' can only appear at the start of the set where it is not interpreted as a range
- // This is a horrible mess - blame the Unix folks for making a hash of wildcards
-
- static bool match_set (const std::string& set, char match)
- {
- // first expand any ranges and remove escape characters to make life more palatable
- std::string simple_set;
- for (std::string::const_iterator i = set.begin(); i != set.end(); ++i)
- {
- switch(*i)
- {
- case '-':
- {
- if (i == set.begin())
- {
- simple_set += *i;
- }
- else if (i+1 == set.end())
- {
- return false;
- }
- else
- {
- // found a set. The first character is already in the result, so first remove it (the set might be empty)
- simple_set.erase(simple_set.end()-1);
- char last = *++i;
- for (char ch = *(i-2); ch <= last; ch++)
- {
- simple_set += ch;
- }
- }
- break;
- }
- case '\\':
- if (i+1 == set.end()) {return false;}
- simple_set += *++i;
- break;
- default:
- simple_set += *i;
- break;
- }
- }
- std::string::size_type result = simple_set.find(match);
- return result != std::string::npos;
- }
-
- // the recursive bit - basically whenever a * is found you recursively call this for each candidate substring match
- // until either it succeeds or you run out of string to match
- // for each * in the wildcard another level of recursion is created
-
- static bool match_remainder (const std::string& wild, std::string::const_iterator wildi,
- const std::string& match, std::string::const_iterator matchi)
- {
- //cerr << "match_remainder called at " << *matchi << " with wildcard " << *wildi << endl;
- while (wildi != wild.end() && matchi != match.end())
- {
- //cerr << "trying to match " << *matchi << " with wildcard " << *wildi << endl;
- switch(*wildi)
- {
- case '*':
- {
- ++wildi;
- ++matchi;
- for (std::string::const_iterator i = matchi; i != match.end(); ++i)
- {
- // deal with * at the end of the wildcard - there is no remainder then
- if (wildi == wild.end())
- {
- if (i == match.end()-1)
- return true;
- }
- else if (match_remainder(wild, wildi, match, i))
- {
- return true;
- }
- }
- return false;
- }
- case '[':
- {
- // scan for the end of the set using a similar method for avoiding escaped characters
- bool found = false;
- std::string::const_iterator end = wildi + 1;
- for (; !found && end != wild.end(); ++end)
- {
- switch(*end)
- {
- case ']':
- {
- // found the set, now match with its contents excluding the brackets
- if (!match_set(wild.substr(wildi - wild.begin() + 1, end - wildi - 1), *matchi))
- return false;
- found = true;
- break;
- }
- case '\\':
- if (end == wild.end()-1)
- return false;
- ++end;
- break;
- default:
- break;
- }
- }
- if (!found)
- return false;
- ++matchi;
- wildi = end;
- break;
- }
- case '?':
- ++wildi;
- ++matchi;
- break;
- case '\\':
- if (wildi == wild.end()-1)
- return false;
- ++wildi;
- if (*wildi != *matchi)
- return false;
- ++wildi;
- ++matchi;
- break;
- default:
- if (*wildi != *matchi)
- return false;
- ++wildi;
- ++matchi;
- break;
- }
- }
- bool result = wildi == wild.end() && matchi == match.end();
- return result;
- }
-
- // like all recursions the exported function has a simpler interface than the
- // recursive function and is just a 'seed' to the recursion itself
-
- bool match_wildcard(const std::string& wild, const std::string& match)
- {
- return match_remainder(wild, wild.begin(), match, match.begin());
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::vector<std::string> split(const std::string& str, const std::string& splitter)
- {
- std::vector<std::string> result;
- if (!str.empty())
- {
- for(std::string::size_type offset = 0;;)
- {
- std::string::size_type found = str.find(splitter, offset);
- if (found != std::string::npos)
- {
- result.push_back(str.substr(offset, found-offset));
- offset = found + splitter.size();
- }
- else
- {
- result.push_back(str.substr(offset, str.size()-offset));
- break;
- }
- }
- }
- return result;
- }
-
- std::string join (const std::vector<std::string>& str,
- const std::string& joiner,
- const std::string& prefix,
- const std::string& suffix)
- {
- std::string result = prefix;
- for (unsigned i = 0; i < str.size(); i++)
- {
- if (i) result += joiner;
- result += str[i];
- }
- result += suffix;
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string display_bytes(long bytes)
- {
- std::string result;
- if (bytes < 0)
- {
- result += '-';
- bytes = -bytes;
- }
- static const long kB = 1024l;
- static const long MB = kB * kB;
- static const long GB = MB * kB;
- if (bytes < kB)
- result += local_dformat("%i", bytes);
- else if (bytes < (10l * kB))
- result += local_dformat("%.2fk", ((float)bytes / (float)kB));
- else if (bytes < (100l * kB))
- result += local_dformat("%.1fk", ((float)bytes / (float)kB));
- else if (bytes < MB)
- result += local_dformat("%.0fk", ((float)bytes / (float)kB));
- else if (bytes < (10l * MB))
- result += local_dformat("%.2fM", ((float)bytes / (float)MB));
- else if (bytes < (100l * MB))
- result += local_dformat("%.1fM", ((float)bytes / (float)MB));
- else if (bytes < GB)
- result += local_dformat("%.0fM", ((float)bytes / (float)MB));
- else
- result += local_dformat("%.2fG", ((float)bytes / (float)GB));
- return result;
- }
-
- std::string display_time(time_t seconds)
- {
- unsigned minutes = (unsigned)seconds / 60;
- seconds %= 60;
- unsigned hours = minutes / 60;
- minutes %= 60;
- unsigned days = hours / 24;
- hours %= 24;
- unsigned weeks = days / 7;
- days %= 7;
- std::string result;
- if (weeks > 0)
- {
- result += unsigned_to_string(weeks, 10, radix_none, 1);
- result += "w ";
- }
- if (!result.empty() || days > 0)
- {
- result += unsigned_to_string(days, 10, radix_none, 1);
- result += "d ";
- }
- if (!result.empty() || hours > 0)
- {
- result += unsigned_to_string(hours, 10, radix_none, 1);
- result += ":";
- }
- if (!result.empty() || minutes > 0)
- {
- if (!result.empty())
- result += unsigned_to_string(minutes, 10, radix_none, 2);
- else
- result += unsigned_to_string(minutes, 10, radix_none, 1);
- result += ":";
- }
- if (!result.empty())
- result += unsigned_to_string((unsigned)seconds, 10, radix_none, 2);
- else
- {
- result += unsigned_to_string((unsigned)seconds, 10, radix_none, 1);
- result += "s";
- }
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_UTILITIES
-#define STLPLUS_STRING_UTILITIES
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Utilities for manipulating std::strings
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include "format_types.hpp"
-#include <vector>
-#include <string>
-#include <stdexcept>
-#include <time.h>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // Padding function allows a string to be printed in a fixed-width field
- ////////////////////////////////////////////////////////////////////////////////
-
- // The definitions for the alignment are declared in format_types.hpp
- // Any other value will cause std::invalid_argument to be thrown
-
- std::string pad(const std::string& str,
- alignment_t alignment,
- unsigned width,
- char padch = ' ')
- throw(std::invalid_argument);
-
- ////////////////////////////////////////////////////////////////////////////////
- // whitespace trimming
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string trim_left(const std::string& val);
- std::string trim_right(const std::string& val);
- std::string trim(const std::string& val);
-
- ////////////////////////////////////////////////////////////////////////////////
- // case conversion for std::strings
- ////////////////////////////////////////////////////////////////////////////////
-
- std::string lowercase(const std::string& val);
- std::string uppercase(const std::string& val);
-
- ////////////////////////////////////////////////////////////////////////////////
- // character translation - inspired by Unix 'tr' command
- ////////////////////////////////////////////////////////////////////////////////
-
- // convert characters represented in from_set to the characters in the same position in to_set
- // for example:
- // filename = translate(filename,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ");
- // converts the filename to uppercase and returns the result (Note that the
- // uppercase function does this more easily). If the from_set is longer than
- // the to_set, then the overlap represents characters to delete (i.e. they map
- // to nothing)
-
- std::string translate(const std::string& input,
- const std::string& from_set,
- const std::string& to_set = std::string());
-
- ////////////////////////////////////////////////////////////////////////////////
- // wildcard matching
- ////////////////////////////////////////////////////////////////////////////////
-
- // this function does wildcard matching of the wildcard expression against the candidate std::string
- // wildcards are NOT regular expressions
- // the wildcard characters are * and ? where * matches 1 or more characters and ? matches only one
- // there are also character sets [a-z] [qwertyuiop] etc. which match 1 character
- // TODO: character sets like [:alpha:]
- // TODO eventually: regular expression matching and substitution (3rd party library?)
-
- bool match_wildcard(const std::string& wild,
- const std::string& match);
-
- ////////////////////////////////////////////////////////////////////////////////
- // Perl-inspired split/join functions
- ////////////////////////////////////////////////////////////////////////////////
-
- // splits the string at every occurance of splitter and adds it as a separate string to the return value
- // the splitter is removed
- // a string with no splitter in it will give a single-value vector
- // an empty string gives an empty vector
-
- std::vector<std::string> split (const std::string& str,
- const std::string& splitter = "\n");
-
- // the reverse of the above
- // joins the string vector to create a single string with the joiner inserted between the joins
- // Note: the joiner will not be added at the beginning or the end
- // However, there are optional fields to add such prefix and suffix strings
-
- std::string join (const std::vector<std::string>&,
- const std::string& joiner = "\n",
- const std::string& prefix = "",
- const std::string& suffix = "");
-
- ////////////////////////////////////////////////////////////////////////////////
- // special displays
- ////////////////////////////////////////////////////////////////////////////////
-
- // display the parameter as a number in bytes, kbytes, Mbytes, Gbytes depending on range
-
- std::string display_bytes(long bytes);
-
- // display the parameter in seconds as a string representation in weeks, days, hours, minutes, seconds
- // e.g. "1d 1:01:01" means 1 day, 1 hour, 1 minute and 1 second
-
- std::string display_time(time_t seconds);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_vector.hpp"
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // special case of vector<bool>
-
- std::string bool_vector_to_string(const std::vector<bool>& values)
- {
- std::string result;
- for (size_t i = 0; i < values.size(); i++)
- result.append(1, values[i] ? '1' : '0');
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRING_VECTOR
-#define STLPLUS_STRING_VECTOR
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Generate a string representation of a vector
-
-////////////////////////////////////////////////////////////////////////////////
-#include "strings_fixes.hpp"
-#include <string>
-#include <vector>
-
-namespace stlplus
-{
-
- ////////////////////////////////////////////////////////////////////////////////
- // vector
-
- template<typename T, typename S>
- std::string vector_to_string(const std::vector<T>& values,
- S to_string_fn,
- const std::string& separator = ",");
-
- // specialisation for vector<bool> which has a different implementation
- std::string bool_vector_to_string(const std::vector<bool>& values);
-
- ////////////////////////////////////////////////////////////////////////////////
-
-} // end namespace stlplus
-
-#include "string_vector.tpp"
-#endif
+++ /dev/null
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-////////////////////////////////////////////////////////////////////////////////
-#include "string_sequence.hpp"
-
-namespace stlplus
-{
-
- template<typename T, typename S>
- std::string vector_to_string(const std::vector<T>& values,
- S to_string_fn,
- const std::string& separator)
- {
- return sequence_to_string(values.begin(), values.end(), to_string_fn, separator);
- }
-
-} // end namespace stlplus
+++ /dev/null
-#ifndef STLPLUS_STRINGS
-#define STLPLUS_STRINGS
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Header for including the whole strings library in one go
-
-// The strings library prints C and C++ types into a std::string
-
-// - it extends the numeric presentation of integers to include any radix from 2 - 36
-// - it allows the printing of data structures - useful for diagnostic dumps
-
-////////////////////////////////////////////////////////////////////////////////
-
-#include "string_utilities.hpp"
-
-#include "string_basic.hpp"
-#include "string_stl.hpp"
-#include "string_stlplus.hpp"
-
-#include "print_basic.hpp"
-#include "print_stl.hpp"
-#include "print_stlplus.hpp"
-
-////////////////////////////////////////////////////////////////////////////////
-#endif
+++ /dev/null
-#ifndef STLPLUS_STRINGS_FIXES
-#define STLPLUS_STRINGS_FIXES
-////////////////////////////////////////////////////////////////////////////////
-
-// Author: Andy Rushton
-// Copyright: (c) Southampton University 1999-2004
-// (c) Andy Rushton 2004-2009
-// License: BSD License, see ../docs/license.html
-
-// Contains work arounds for OS or Compiler specific problems
-
-////////////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////////////
-// Problem with MicroSoft defining two different macros to identify Windows
-////////////////////////////////////////////////////////////////////////////////
-
-#if defined(_WIN32) || defined(_WIN32_WCE)
-#define MSWINDOWS
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// Unnecessary compiler warnings
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef _MSC_VER
-// Microsoft Visual Studio
-// shut up the following irritating warnings
-// 4786 - VC6, identifier string exceeded maximum allowable length and was truncated (only affects debugger)
-// 4305 - VC6, identifier type was converted to a smaller type
-// 4503 - VC6, decorated name was longer than the maximum the compiler allows (only affects debugger)
-// 4309 - VC6, type conversion operation caused a constant to exceeded the space allocated for it
-// 4290 - VC6, C++ exception specification ignored
-// 4800 - VC6, forcing value to bool 'true' or 'false' (performance warning)
-// 4675 - VC7.1, "change" in function overload resolution _might_ have altered program
-// 4996 - VC8, 'xxxx' was declared deprecated
-#pragma warning(disable: 4786 4305 4503 4309 4290 4800 4675 4996)
-#endif
-
-#ifdef __BORLANDC__
-// Borland
-// Shut up the following irritating warnings
-// 8026 - Functions with exception specifications are not expanded inline
-// 8027 - Functions with xxx are not expanded inline
-// 8066 - Unreachable code.
-// A break, continue, goto, or return statement was not followed by a
-// label or the end of a loop or function. The compiler checks while,
-// do, and for loops with a constant test condition, and attempts to
-// recognize loops that can't fall through.
-#pragma warn -8026
-#pragma warn -8027
-#pragma warn -8066
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-#endif
// Compile this file with windres and link with the executable.
//
-#include <winver.h>
#include "config.h"
+#include <winver.h>
1 VERSIONINFO
FILEVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION,0
-PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION,0
-FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION,0
+FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#if NDEBUG
FILEFLAGS 0
#else
BEGIN
BLOCK "040904b0"
BEGIN
- VALUE "CompanyName", ""
- VALUE "FileDescription", "Alien-smashing action game"
- VALUE "FileVersion", PACKAGE_VERSION
- VALUE "InternalName", "Yoink"
- VALUE "LegalCopyright", "Copyright 2010 Charles McGarvey et al."
- VALUE "OriginalFilename", "yoink.exe"
- VALUE "ProductName", "Yoink"
- VALUE "ProductVersion", PACKAGE_VERSION
+ VALUE "CompanyName", ""
+ VALUE "FileDescription", "Alien-smashing action game"
+ VALUE "FileVersion", PACKAGE_VERSION
+ VALUE "InternalName", PACKAGE
+ VALUE "LegalCopyright", "Copyright 2011 Charles McGarvey et al."
+ VALUE "OriginalFilename", "yoink.exe"
+ VALUE "ProductName", PACKAGE_NAME
+ VALUE "ProductVersion", PACKAGE_VERSION
END
END
BLOCK "VarFileInfo"
END
END
-1000 ICON "../arch/win32/yoink.ico"
+1000 ICON "../build/arch/win32/yoink.ico"
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
+#if HAVE_CONFIG_H
#include "config.h"
+#endif
#include <stdexcept>
//bool isMute = false;
//settings().get("nomusic", isMute);
- //music_.play();
+ music_.play();
load_scene_loader();
advance_scene(); // load the first scene
-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _YOINK_HH_
#define _YOINK_HH_
void projection();
void projection(moof::scalar width, moof::scalar height);
- mutable GameState state_;
+ mutable GameState state_;
HudP mHud;
- moof::sound punch_sound_;
+ moof::sound punch_sound_;
moof::sound music_;
moof::ray2 mRay;
moof::line2 mLine;
- moof::circle mCircle;
+ moof::circle mCircle;
moof::timer mRayTimer;
void rayTimer();