diff --git a/qse/include/qse/xli/Makefile.am b/qse/include/qse/xli/Makefile.am index 57f629a7..12acd92c 100644 --- a/qse/include/qse/xli/Makefile.am +++ b/qse/include/qse/xli/Makefile.am @@ -2,3 +2,9 @@ pkgincludedir= $(includedir)/qse/xli pkginclude_HEADERS = xli.h stdxli.h + +if ENABLE_CXX +pkginclude_HEADERS += SkvEnv.hpp +endif + + diff --git a/qse/include/qse/xli/Makefile.in b/qse/include/qse/xli/Makefile.in index 683510da..7da92dd2 100644 --- a/qse/include/qse/xli/Makefile.in +++ b/qse/include/qse/xli/Makefile.in @@ -87,6 +87,7 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ +@ENABLE_CXX_TRUE@am__append_1 = SkvEnv.hpp subdir = include/qse/xli ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ @@ -98,7 +99,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ $(top_srcdir)/m4/lx_find_mpi.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) -DIST_COMMON = $(srcdir)/Makefile.am $(pkginclude_HEADERS) \ +DIST_COMMON = $(srcdir)/Makefile.am $(am__pkginclude_HEADERS_DIST) \ $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/include/qse/config.h @@ -123,6 +124,7 @@ am__can_run_installinfo = \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac +am__pkginclude_HEADERS_DIST = xli.h stdxli.h SkvEnv.hpp am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -339,7 +341,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -pkginclude_HEADERS = xli.h stdxli.h +pkginclude_HEADERS = xli.h stdxli.h $(am__append_1) all: all-am .SUFFIXES: diff --git a/qse/include/qse/xli/SkvEnv.hpp b/qse/include/qse/xli/SkvEnv.hpp new file mode 100644 index 00000000..a7aa7996 --- /dev/null +++ b/qse/include/qse/xli/SkvEnv.hpp @@ -0,0 +1,46 @@ +/* + * $Id$ + * + Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _QSE_LIB_XLI_SKVENV_CLASS_ +#define _QSE_LIB_XLI_SKVENV_CLASS_ + +QSE_BEGIN_NAMESPACE(QSE) + +class SkvEnv +{ +public: + typedef int (SkvEnv::*ProbeProc) (const xp_char_t* val); + + int addItem (const qse_char_t* name, const qse_char_t* dval, ProbeProc probe); + int removeItem (const qse_char_t* name); + + const qse_char_t* setItemValue (const qse_char_t* name, const qse_char_t* val); + +protected: + int split_name (const qse_char_t* name, qse_char_t** sctn, qse_size_t* sctn_len, qse_char_t** key, qse_size_t* key_len); +}; + +QSE_END_NAMESPACE(QSE) diff --git a/qse/lib/xli/Makefile.am b/qse/lib/xli/Makefile.am index 36ce7c42..7157f700 100644 --- a/qse/lib/xli/Makefile.am +++ b/qse/lib/xli/Makefile.am @@ -12,3 +12,12 @@ libqsexli_la_SOURCES = xli.h xli.c err.c \ libqsexli_la_LDFLAGS = -L../cmn -L../si -version-info 1:0:0 -no-undefined libqsexli_la_LIBADD = -lqsesi -lqsecmn + +if ENABLE_CXX +lib_LTLIBRARIES += libqsexlixx.la +libqsexlixx_la_SOURCES = SkvEnv.cpp +libqsexlixx_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) +libqsexlixx_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) +libqsexlixx_la_LIBADD = -lqsexli -lqsecmnxx -lqsexli -lqsesi -lqsecmn $(LIBADD_LIB_COMMON) +endif + diff --git a/qse/lib/xli/Makefile.in b/qse/lib/xli/Makefile.in index 61c65183..39a54c92 100644 --- a/qse/lib/xli/Makefile.in +++ b/qse/lib/xli/Makefile.in @@ -88,6 +88,7 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ +@ENABLE_CXX_TRUE@am__append_1 = libqsexlixx.la subdir = lib/xli ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ @@ -144,6 +145,15 @@ am__v_lt_1 = libqsexli_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(libqsexli_la_LDFLAGS) $(LDFLAGS) -o $@ +libqsexlixx_la_DEPENDENCIES = +am__libqsexlixx_la_SOURCES_DIST = SkvEnv.cpp +@ENABLE_CXX_TRUE@am_libqsexlixx_la_OBJECTS = libqsexlixx_la-SkvEnv.lo +libqsexlixx_la_OBJECTS = $(am_libqsexlixx_la_OBJECTS) +libqsexlixx_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ + $(AM_CXXFLAGS) $(CXXFLAGS) $(libqsexlixx_la_LDFLAGS) \ + $(LDFLAGS) -o $@ +@ENABLE_CXX_TRUE@am_libqsexlixx_la_rpath = -rpath $(libdir) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -178,8 +188,27 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(libqsexli_la_SOURCES) -DIST_SOURCES = $(libqsexli_la_SOURCES) +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +AM_V_CXX = $(am__v_CXX_@AM_V@) +am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@) +am__v_CXX_0 = @echo " CXX " $@; +am__v_CXX_1 = +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CXXLD = $(am__v_CXXLD_@AM_V@) +am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) +am__v_CXXLD_0 = @echo " CXXLD " $@; +am__v_CXXLD_1 = +SOURCES = $(libqsexli_la_SOURCES) $(libqsexlixx_la_SOURCES) +DIST_SOURCES = $(libqsexli_la_SOURCES) \ + $(am__libqsexlixx_la_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -376,7 +405,7 @@ AM_CPPFLAGS = \ -I$(top_builddir)/include \ -I$(top_srcdir)/include -lib_LTLIBRARIES = libqsexli.la +lib_LTLIBRARIES = libqsexli.la $(am__append_1) libqsexli_la_SOURCES = xli.h xli.c err.c \ read.c read-ini.c read-json.c \ write.c write-ini.c write-json.c \ @@ -384,10 +413,14 @@ libqsexli_la_SOURCES = xli.h xli.c err.c \ libqsexli_la_LDFLAGS = -L../cmn -L../si -version-info 1:0:0 -no-undefined libqsexli_la_LIBADD = -lqsesi -lqsecmn +@ENABLE_CXX_TRUE@libqsexlixx_la_SOURCES = SkvEnv.cpp +@ENABLE_CXX_TRUE@libqsexlixx_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) +@ENABLE_CXX_TRUE@libqsexlixx_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) +@ENABLE_CXX_TRUE@libqsexlixx_la_LIBADD = -lqsexli -lqsecmnxx -lqsexli -lqsesi -lqsecmn $(LIBADD_LIB_COMMON) all: all-am .SUFFIXES: -.SUFFIXES: .c .lo .o .obj +.SUFFIXES: .c .cpp .lo .o .obj $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -456,6 +489,9 @@ clean-libLTLIBRARIES: libqsexli.la: $(libqsexli_la_OBJECTS) $(libqsexli_la_DEPENDENCIES) $(EXTRA_libqsexli_la_DEPENDENCIES) $(AM_V_CCLD)$(libqsexli_la_LINK) -rpath $(libdir) $(libqsexli_la_OBJECTS) $(libqsexli_la_LIBADD) $(LIBS) +libqsexlixx.la: $(libqsexlixx_la_OBJECTS) $(libqsexlixx_la_DEPENDENCIES) $(EXTRA_libqsexlixx_la_DEPENDENCIES) + $(AM_V_CXXLD)$(libqsexlixx_la_LINK) $(am_libqsexlixx_la_rpath) $(libqsexlixx_la_OBJECTS) $(libqsexlixx_la_LIBADD) $(LIBS) + mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -463,6 +499,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/err.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsexlixx_la-SkvEnv.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/read-ini.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/read-json.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/read.Plo@am__quote@ @@ -493,6 +530,34 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< +.cpp.o: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $< + +.cpp.obj: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cpp.lo: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $< + +libqsexlixx_la-SkvEnv.lo: SkvEnv.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libqsexlixx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libqsexlixx_la-SkvEnv.lo -MD -MP -MF $(DEPDIR)/libqsexlixx_la-SkvEnv.Tpo -c -o libqsexlixx_la-SkvEnv.lo `test -f 'SkvEnv.cpp' || echo '$(srcdir)/'`SkvEnv.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libqsexlixx_la-SkvEnv.Tpo $(DEPDIR)/libqsexlixx_la-SkvEnv.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SkvEnv.cpp' object='libqsexlixx_la-SkvEnv.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libqsexlixx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libqsexlixx_la-SkvEnv.lo `test -f 'SkvEnv.cpp' || echo '$(srcdir)/'`SkvEnv.cpp + mostlyclean-libtool: -rm -f *.lo diff --git a/qse/lib/xli/SkvEnv.cpp b/qse/lib/xli/SkvEnv.cpp new file mode 100644 index 00000000..2af43175 --- /dev/null +++ b/qse/lib/xli/SkvEnv.cpp @@ -0,0 +1,84 @@ +/* + * $Id$ + * + Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include +#include + +#define SCTN_KEY_SPLITTER QSE_T('*') + +QSE_BEGIN_NAMESPACE(QSE) + +const qse_char_t* SkvEnv::setItemValue (const qse_char_t* name, const qse_char_t* val) +{ + qse_char_t* sctn, * key; + qse_size_t sctn_len, key_len; + + if (this->split_name(name, &sctn, &sctn_len, &key, &key_len) == -1) return QSE_NULL; + + for (ItemList::Node* np = item_list.head(); np; np = np->forward()) + { + Item& item = np->value; + if (qse_strxcmp(sctn, sctn_len, item.sctn) == 0 && + qse_strxcmp(key, key_len, item.key) == 0) + { + if ((this->*item.probe)(val) == -1) return QSE_NULL; + this->setValue (item.sctn, item.key, val); + return val; + } + } + + return QSE_NULL; +} + + + +int SkvEnv::split_name (const qse_char_t* name, qse_char_t** sctn, qse_size_t* sctn_len, qse_char_t** key, qse_size_t* key_len) +{ + QSE_ASSERT (name != QSE_NULL); + QSE_ASSERT (sctn != QSE_NULL); + QSE_ASSERT (sctn_len != QSE_NULL); + QSE_ASSERT (key != QSE_NULL); + QSE_ASSERT (key_len != QSE_NULL); + + qse_char_t* s, * k, * p; + qse_size_t sl, kl; + + qse_char_t spr[] = { SCTN_KEY_SPLITTER, QSE_CHAR('\0') }; + p = qse_strtok(name, spr, &s, &sl); + if (!p || sl == 0) return -1; + qse_strtok(p, QSE_NULL, &k, &kl); + if (kl == 0) return -1; + + *sctn = s; + *sctn_len = sl; + *key = k; + *key_len = kl; + + return 0; +} + +QSE_END_NAMESPACE(QSE)