├── .gitignore ├── .gitmodules ├── .travis.yml ├── Build ├── Makefile ├── catch_test.make ├── catch_test.vcxproj ├── catch_test.vcxproj.filters ├── hiberlite.make ├── hiberlite.sln ├── hiberlite.vcxproj ├── hiberlite.vcxproj.filters ├── hiberlite_test.make ├── hiberlite_test.vcxproj ├── hiberlite_test.vcxproj.filters ├── sample.make ├── sample.vcxproj ├── sample.vcxproj.filters ├── sqlite.make ├── sqlite.vcxproj └── sqlite.vcxproj.filters ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README ├── README.md ├── catch_tests.cpp ├── include ├── BeanLoader.h ├── BeanLoader_impl.hpp ├── BeanUpdater.h ├── BeanUpdater_impl.hpp ├── ChildKiller.h ├── ChildKiller_impl.hpp ├── CppModel.h ├── Database.h ├── Database_tmpl_impl.hpp ├── ModelExtractor.h ├── ModelExtractor_impl.hpp ├── Registry.h ├── Registry_impl.hpp ├── SQLiteStmt.h ├── UpdateVisitor_tmpl.hpp ├── Visitor.h ├── Visitor_tmpl_impl.hpp ├── bean_ptr.h ├── bean_ptr_impl.hpp ├── common.h ├── db_error.h ├── hiberdefs.h ├── hiberlite.h ├── nvp.h ├── shared_res.h └── some_types.h ├── make_vs2013.bat ├── premake5.lua ├── sample.cpp ├── src ├── BeanLoader.cpp ├── BeanUpdater.cpp ├── ChildKiller.cpp ├── CppModel.cpp ├── Database.cpp ├── ModelExtractor.cpp ├── Registry.cpp ├── SQLiteStmt.cpp ├── Visitor.cpp └── shared_res.cpp └── tests.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | [Bb]in/ 50 | [Oo]bj/ 51 | 52 | # MSTest test Results 53 | [Tt]est[Rr]esult*/ 54 | [Bb]uild[Ll]og.* 55 | 56 | *_i.c 57 | *_p.c 58 | *.ilk 59 | *.meta 60 | *.obj 61 | *.pch 62 | *.pdb 63 | *.pgc 64 | *.pgd 65 | *.rsp 66 | *.sbr 67 | *.tlb 68 | *.tli 69 | *.tlh 70 | *.tmp 71 | *.tmp_proj 72 | *.log 73 | *.vspscc 74 | *.vssscc 75 | .builds 76 | *.pidb 77 | *.log 78 | *.scc 79 | 80 | # Visual C++ cache files 81 | ipch/ 82 | *.aps 83 | *.ncb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | 88 | # Visual Studio profiler 89 | *.psess 90 | *.vsp 91 | *.vspx 92 | 93 | # Guidance Automation Toolkit 94 | *.gpState 95 | 96 | # ReSharper is a .NET coding add-in 97 | _ReSharper*/ 98 | *.[Rr]e[Ss]harper 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | *.ncrunch* 108 | .*crunch*.local.xml 109 | 110 | # Installshield output folder 111 | [Ee]xpress/ 112 | 113 | # DocProject is a documentation generator add-in 114 | DocProject/buildhelp/ 115 | DocProject/Help/*.HxT 116 | DocProject/Help/*.HxC 117 | DocProject/Help/*.hhc 118 | DocProject/Help/*.hhk 119 | DocProject/Help/*.hhp 120 | DocProject/Help/Html2 121 | DocProject/Help/html 122 | 123 | # Click-Once directory 124 | publish/ 125 | 126 | # Publish Web Output 127 | *.Publish.xml 128 | *.pubxml 129 | 130 | # NuGet Packages Directory 131 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 132 | #packages/ 133 | 134 | # Windows Azure Build Output 135 | csx 136 | *.build.csdef 137 | 138 | # Windows Store app package directory 139 | AppPackages/ 140 | 141 | # Others 142 | sql/ 143 | *.Cache 144 | ClientBin/ 145 | [Ss]tyle[Cc]op.* 146 | ~$* 147 | *~ 148 | *.dbmdl 149 | *.[Pp]ublish.xml 150 | *.pfx 151 | *.publishsettings 152 | 153 | # RIA/Silverlight projects 154 | Generated_Code/ 155 | 156 | # Backup & report files from converting an old project file to a newer 157 | # Visual Studio version. Backup files are not needed, because we have git ;-) 158 | _UpgradeReport_Files/ 159 | Backup*/ 160 | UpgradeLog*.XML 161 | UpgradeLog*.htm 162 | 163 | # SQL Server files 164 | App_Data/*.mdf 165 | App_Data/*.ldf 166 | 167 | ############# 168 | ## Windows detritus 169 | ############# 170 | 171 | # Windows image file caches 172 | Thumbs.db 173 | ehthumbs.db 174 | 175 | # Folder config file 176 | Desktop.ini 177 | 178 | # Recycle Bin used on file shares 179 | $RECYCLE.BIN/ 180 | 181 | # Mac crap 182 | .DS_Store 183 | 184 | 185 | ############# 186 | ## Python 187 | ############# 188 | 189 | *.py[co] 190 | 191 | # Packages 192 | *.egg 193 | *.egg-info 194 | dist/ 195 | eggs/ 196 | parts/ 197 | var/ 198 | sdist/ 199 | develop-eggs/ 200 | .installed.cfg 201 | 202 | # Installer logs 203 | pip-log.txt 204 | 205 | # Unit test / coverage reports 206 | .coverage 207 | .tox 208 | 209 | #Translations 210 | *.mo 211 | 212 | #Mr Developer 213 | .mr.developer.cfg 214 | 215 | *.db 216 | *.idb 217 | *.lib 218 | *.exe 219 | !premake4.exe 220 | *.a 221 | *.opendb 222 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Catch"] 2 | path = Catch 3 | url = https://github.com/philsquared/Catch.git 4 | [submodule "sqlite-amalgamation"] 5 | path = sqlite-amalgamation 6 | url = https://github.com/sqlg/sqlite-amalgamation.git 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | sudo: false 4 | 5 | script: 6 | - make -C Build 7 | -------------------------------------------------------------------------------- /Build/Makefile: -------------------------------------------------------------------------------- 1 | # GNU Make solution makefile autogenerated by Premake 2 | # Type "make help" for usage help 3 | 4 | ifndef config 5 | config=debug 6 | endif 7 | export config 8 | 9 | PROJECTS := hiberlite sqlite sample catch_test hiberlite_test 10 | 11 | .PHONY: all clean help $(PROJECTS) 12 | 13 | all: $(PROJECTS) 14 | 15 | hiberlite: 16 | @echo "==== Building hiberlite ($(config)) ====" 17 | @${MAKE} --no-print-directory -C . -f hiberlite.make 18 | 19 | sqlite: 20 | @echo "==== Building sqlite ($(config)) ====" 21 | @${MAKE} --no-print-directory -C . -f sqlite.make 22 | 23 | sample: hiberlite sqlite 24 | @echo "==== Building sample ($(config)) ====" 25 | @${MAKE} --no-print-directory -C . -f sample.make 26 | 27 | catch_test: hiberlite sqlite 28 | @echo "==== Building catch_test ($(config)) ====" 29 | @${MAKE} --no-print-directory -C . -f catch_test.make 30 | 31 | hiberlite_test: hiberlite sqlite 32 | @echo "==== Building hiberlite_test ($(config)) ====" 33 | @${MAKE} --no-print-directory -C . -f hiberlite_test.make 34 | 35 | clean: 36 | @${MAKE} --no-print-directory -C . -f hiberlite.make clean 37 | @${MAKE} --no-print-directory -C . -f sqlite.make clean 38 | @${MAKE} --no-print-directory -C . -f sample.make clean 39 | @${MAKE} --no-print-directory -C . -f catch_test.make clean 40 | @${MAKE} --no-print-directory -C . -f hiberlite_test.make clean 41 | 42 | help: 43 | @echo "Usage: make [config=name] [target]" 44 | @echo "" 45 | @echo "CONFIGURATIONS:" 46 | @echo " debug" 47 | @echo " release" 48 | @echo " debug32" 49 | @echo " release32" 50 | @echo " debug64" 51 | @echo " release64" 52 | @echo "" 53 | @echo "TARGETS:" 54 | @echo " all (default)" 55 | @echo " clean" 56 | @echo " hiberlite" 57 | @echo " sqlite" 58 | @echo " sample" 59 | @echo " catch_test" 60 | @echo " hiberlite_test" 61 | @echo "" 62 | @echo "For more information, see http://industriousone.com/premake/quick-start" 63 | -------------------------------------------------------------------------------- /Build/catch_test.make: -------------------------------------------------------------------------------- 1 | # GNU Make project makefile autogenerated by Premake 2 | ifndef config 3 | config=debug 4 | endif 5 | 6 | ifndef verbose 7 | SILENT = @ 8 | endif 9 | 10 | ifndef CC 11 | CC = gcc 12 | endif 13 | 14 | ifndef CXX 15 | CXX = g++ 16 | endif 17 | 18 | ifndef AR 19 | AR = ar 20 | endif 21 | 22 | ifndef RESCOMP 23 | ifdef WINDRES 24 | RESCOMP = $(WINDRES) 25 | else 26 | RESCOMP = windres 27 | endif 28 | endif 29 | 30 | ifeq ($(config),debug) 31 | OBJDIR = obj/Debug/catch_test 32 | TARGETDIR = .. 33 | TARGET = $(TARGETDIR)/catch_test 34 | DEFINES += -DDEBUG -D_DEBUG 35 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 36 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 37 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -v -std=c++0x 38 | CXXFLAGS += $(CFLAGS) 39 | LDFLAGS += -L.. 40 | RESFLAGS += $(DEFINES) $(INCLUDES) 41 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 42 | LDDEPS += ../libhiberlite.a ../libsqlite.a 43 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 44 | define PREBUILDCMDS 45 | endef 46 | define PRELINKCMDS 47 | endef 48 | define POSTBUILDCMDS 49 | @echo Running post-build commands 50 | $(TARGET) 51 | endef 52 | endif 53 | 54 | ifeq ($(config),release) 55 | OBJDIR = obj/Release/catch_test 56 | TARGETDIR = .. 57 | TARGET = $(TARGETDIR)/catch_test 58 | DEFINES += -DRELEASE 59 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 60 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 61 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -v -std=c++0x 62 | CXXFLAGS += $(CFLAGS) 63 | LDFLAGS += -L.. -s 64 | RESFLAGS += $(DEFINES) $(INCLUDES) 65 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 66 | LDDEPS += ../libhiberlite.a ../libsqlite.a 67 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 68 | define PREBUILDCMDS 69 | endef 70 | define PRELINKCMDS 71 | endef 72 | define POSTBUILDCMDS 73 | @echo Running post-build commands 74 | $(TARGET) 75 | endef 76 | endif 77 | 78 | ifeq ($(config),debug32) 79 | OBJDIR = obj/x32/Debug/catch_test 80 | TARGETDIR = .. 81 | TARGET = $(TARGETDIR)/catch_test 82 | DEFINES += -DDEBUG -D_DEBUG 83 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 84 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 85 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -m32 -v -std=c++0x 86 | CXXFLAGS += $(CFLAGS) 87 | LDFLAGS += -L.. -m32 -L/usr/lib32 88 | RESFLAGS += $(DEFINES) $(INCLUDES) 89 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 90 | LDDEPS += ../libhiberlite.a ../libsqlite.a 91 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 92 | define PREBUILDCMDS 93 | endef 94 | define PRELINKCMDS 95 | endef 96 | define POSTBUILDCMDS 97 | @echo Running post-build commands 98 | $(TARGET) 99 | endef 100 | endif 101 | 102 | ifeq ($(config),release32) 103 | OBJDIR = obj/x32/Release/catch_test 104 | TARGETDIR = .. 105 | TARGET = $(TARGETDIR)/catch_test 106 | DEFINES += -DRELEASE 107 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 108 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 109 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -m32 -v -std=c++0x 110 | CXXFLAGS += $(CFLAGS) 111 | LDFLAGS += -L.. -s -m32 -L/usr/lib32 112 | RESFLAGS += $(DEFINES) $(INCLUDES) 113 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 114 | LDDEPS += ../libhiberlite.a ../libsqlite.a 115 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 116 | define PREBUILDCMDS 117 | endef 118 | define PRELINKCMDS 119 | endef 120 | define POSTBUILDCMDS 121 | @echo Running post-build commands 122 | $(TARGET) 123 | endef 124 | endif 125 | 126 | ifeq ($(config),debug64) 127 | OBJDIR = obj/x64/Debug/catch_test 128 | TARGETDIR = .. 129 | TARGET = $(TARGETDIR)/catch_test 130 | DEFINES += -DDEBUG -D_DEBUG 131 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 132 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 133 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -m64 -v -std=c++0x 134 | CXXFLAGS += $(CFLAGS) 135 | LDFLAGS += -L.. -m64 -L/usr/lib64 136 | RESFLAGS += $(DEFINES) $(INCLUDES) 137 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 138 | LDDEPS += ../libhiberlite.a ../libsqlite.a 139 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 140 | define PREBUILDCMDS 141 | endef 142 | define PRELINKCMDS 143 | endef 144 | define POSTBUILDCMDS 145 | @echo Running post-build commands 146 | $(TARGET) 147 | endef 148 | endif 149 | 150 | ifeq ($(config),release64) 151 | OBJDIR = obj/x64/Release/catch_test 152 | TARGETDIR = .. 153 | TARGET = $(TARGETDIR)/catch_test 154 | DEFINES += -DRELEASE 155 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 156 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 157 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -m64 -v -std=c++0x 158 | CXXFLAGS += $(CFLAGS) 159 | LDFLAGS += -L.. -s -m64 -L/usr/lib64 160 | RESFLAGS += $(DEFINES) $(INCLUDES) 161 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 162 | LDDEPS += ../libhiberlite.a ../libsqlite.a 163 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 164 | define PREBUILDCMDS 165 | endef 166 | define PRELINKCMDS 167 | endef 168 | define POSTBUILDCMDS 169 | @echo Running post-build commands 170 | $(TARGET) 171 | endef 172 | endif 173 | 174 | OBJECTS := \ 175 | $(OBJDIR)/catch_tests.o \ 176 | 177 | RESOURCES := \ 178 | 179 | SHELLTYPE := msdos 180 | ifeq (,$(ComSpec)$(COMSPEC)) 181 | SHELLTYPE := posix 182 | endif 183 | ifeq (/bin,$(findstring /bin,$(SHELL))) 184 | SHELLTYPE := posix 185 | endif 186 | 187 | .PHONY: clean prebuild prelink 188 | 189 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) 190 | @: 191 | 192 | $(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES) 193 | @echo Linking catch_test 194 | $(SILENT) $(LINKCMD) 195 | $(POSTBUILDCMDS) 196 | 197 | $(TARGETDIR): 198 | @echo Creating $(TARGETDIR) 199 | ifeq (posix,$(SHELLTYPE)) 200 | $(SILENT) mkdir -p $(TARGETDIR) 201 | else 202 | $(SILENT) mkdir $(subst /,\\,$(TARGETDIR)) 203 | endif 204 | 205 | $(OBJDIR): 206 | @echo Creating $(OBJDIR) 207 | ifeq (posix,$(SHELLTYPE)) 208 | $(SILENT) mkdir -p $(OBJDIR) 209 | else 210 | $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) 211 | endif 212 | 213 | clean: 214 | @echo Cleaning catch_test 215 | ifeq (posix,$(SHELLTYPE)) 216 | $(SILENT) rm -f $(TARGET) 217 | $(SILENT) rm -rf $(OBJDIR) 218 | else 219 | $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) 220 | $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR)) 221 | endif 222 | 223 | prebuild: 224 | $(PREBUILDCMDS) 225 | 226 | prelink: 227 | $(PRELINKCMDS) 228 | 229 | ifneq (,$(PCH)) 230 | $(GCH): $(PCH) 231 | @echo $(notdir $<) 232 | ifeq (posix,$(SHELLTYPE)) 233 | -$(SILENT) cp $< $(OBJDIR) 234 | else 235 | $(SILENT) xcopy /D /Y /Q "$(subst /,\,$<)" "$(subst /,\,$(OBJDIR))" 1>nul 236 | endif 237 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 238 | endif 239 | 240 | $(OBJDIR)/catch_tests.o: ../catch_tests.cpp 241 | @echo $(notdir $<) 242 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 243 | 244 | -include $(OBJECTS:%.o=%.d) 245 | -------------------------------------------------------------------------------- /Build/catch_test.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug native 6 | Win32 7 | 8 | 9 | Debug native 10 | x64 11 | 12 | 13 | Debug 14 | Win32 15 | 16 | 17 | Debug 18 | x64 19 | 20 | 21 | Release native 22 | Win32 23 | 24 | 25 | Release native 26 | x64 27 | 28 | 29 | Release 30 | Win32 31 | 32 | 33 | Release 34 | x64 35 | 36 | 37 | 38 | {27B715B5-136F-5702-7C76-305E684DF2F2} 39 | true 40 | Win32Proj 41 | catch_test 42 | 43 | 44 | 45 | Application 46 | true 47 | MultiByte 48 | v120 49 | 50 | 51 | Application 52 | true 53 | MultiByte 54 | v120 55 | 56 | 57 | Application 58 | true 59 | MultiByte 60 | v120 61 | 62 | 63 | Application 64 | false 65 | MultiByte 66 | v120 67 | 68 | 69 | Application 70 | false 71 | MultiByte 72 | v120 73 | 74 | 75 | Application 76 | false 77 | MultiByte 78 | v120 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | true 104 | ..\bin\catch_test\Debug\ 105 | ..\obj\catch_test\Debug\native\ 106 | catch_test 107 | .exe 108 | 109 | 110 | true 111 | ..\bin\catch_test\Debug\ 112 | ..\obj\catch_test\Debug\x32\ 113 | catch_test 114 | .exe 115 | 116 | 117 | true 118 | ..\bin\catch_test\Debug\ 119 | ..\obj\catch_test\Debug\x64\ 120 | catch_test 121 | .exe 122 | 123 | 124 | false 125 | ..\bin\catch_test\Release\ 126 | ..\obj\catch_test\Release\native\ 127 | catch_test 128 | .exe 129 | 130 | 131 | false 132 | ..\bin\catch_test\Release\ 133 | ..\obj\catch_test\Release\x32\ 134 | catch_test 135 | .exe 136 | 137 | 138 | false 139 | ..\bin\catch_test\Release\ 140 | ..\obj\catch_test\Release\x64\ 141 | catch_test 142 | .exe 143 | 144 | 145 | 146 | NotUsing 147 | Level3 148 | DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 149 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 150 | EditAndContinue 151 | Disabled 152 | 153 | 154 | Console 155 | true 156 | mainCRTStartup 157 | 158 | 159 | "$(TargetPath)" 160 | 161 | 162 | 163 | 164 | NotUsing 165 | Level3 166 | DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 167 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 168 | EditAndContinue 169 | Disabled 170 | 171 | 172 | Console 173 | true 174 | mainCRTStartup 175 | 176 | 177 | "$(TargetPath)" 178 | 179 | 180 | 181 | 182 | NotUsing 183 | Level3 184 | DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 185 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 186 | ProgramDatabase 187 | Disabled 188 | 189 | 190 | Console 191 | true 192 | mainCRTStartup 193 | 194 | 195 | "$(TargetPath)" 196 | 197 | 198 | 199 | 200 | NotUsing 201 | Level3 202 | RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 203 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 204 | Full 205 | true 206 | true 207 | false 208 | true 209 | 210 | 211 | Console 212 | false 213 | true 214 | true 215 | mainCRTStartup 216 | 217 | 218 | "$(TargetPath)" 219 | 220 | 221 | 222 | 223 | NotUsing 224 | Level3 225 | RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 226 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 227 | Full 228 | true 229 | true 230 | false 231 | true 232 | 233 | 234 | Console 235 | false 236 | true 237 | true 238 | mainCRTStartup 239 | 240 | 241 | "$(TargetPath)" 242 | 243 | 244 | 245 | 246 | NotUsing 247 | Level3 248 | RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 249 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 250 | Full 251 | true 252 | true 253 | false 254 | true 255 | 256 | 257 | Console 258 | false 259 | true 260 | true 261 | mainCRTStartup 262 | 263 | 264 | "$(TargetPath)" 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62} 273 | 274 | 275 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43} 276 | 277 | 278 | 279 | 280 | 281 | -------------------------------------------------------------------------------- /Build/catch_test.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {89565304-F535-D29F-FE4D-5D766AAC3801} 6 | 7 | 8 | 9 | 10 | Sources 11 | 12 | 13 | -------------------------------------------------------------------------------- /Build/hiberlite.make: -------------------------------------------------------------------------------- 1 | # GNU Make project makefile autogenerated by Premake 2 | ifndef config 3 | config=debug 4 | endif 5 | 6 | ifndef verbose 7 | SILENT = @ 8 | endif 9 | 10 | ifndef CC 11 | CC = gcc 12 | endif 13 | 14 | ifndef CXX 15 | CXX = g++ 16 | endif 17 | 18 | ifndef AR 19 | AR = ar 20 | endif 21 | 22 | ifndef RESCOMP 23 | ifdef WINDRES 24 | RESCOMP = $(WINDRES) 25 | else 26 | RESCOMP = windres 27 | endif 28 | endif 29 | 30 | ifeq ($(config),debug) 31 | OBJDIR = obj/Debug/hiberlite 32 | TARGETDIR = .. 33 | TARGET = $(TARGETDIR)/libhiberlite.a 34 | DEFINES += -DDEBUG -D_DEBUG 35 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 36 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 37 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -v -std=c++0x 38 | CXXFLAGS += $(CFLAGS) 39 | LDFLAGS += 40 | RESFLAGS += $(DEFINES) $(INCLUDES) 41 | LIBS += 42 | LDDEPS += 43 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 44 | define PREBUILDCMDS 45 | endef 46 | define PRELINKCMDS 47 | endef 48 | define POSTBUILDCMDS 49 | endef 50 | endif 51 | 52 | ifeq ($(config),release) 53 | OBJDIR = obj/Release/hiberlite 54 | TARGETDIR = .. 55 | TARGET = $(TARGETDIR)/libhiberlite.a 56 | DEFINES += -DRELEASE 57 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 58 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 59 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -v -std=c++0x 60 | CXXFLAGS += $(CFLAGS) 61 | LDFLAGS += -s 62 | RESFLAGS += $(DEFINES) $(INCLUDES) 63 | LIBS += 64 | LDDEPS += 65 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 66 | define PREBUILDCMDS 67 | endef 68 | define PRELINKCMDS 69 | endef 70 | define POSTBUILDCMDS 71 | endef 72 | endif 73 | 74 | ifeq ($(config),debug32) 75 | OBJDIR = obj/x32/Debug/hiberlite 76 | TARGETDIR = .. 77 | TARGET = $(TARGETDIR)/libhiberlite.a 78 | DEFINES += -DDEBUG -D_DEBUG 79 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 80 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 81 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -m32 -v -std=c++0x 82 | CXXFLAGS += $(CFLAGS) 83 | LDFLAGS += -m32 -L/usr/lib32 84 | RESFLAGS += $(DEFINES) $(INCLUDES) 85 | LIBS += 86 | LDDEPS += 87 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 88 | define PREBUILDCMDS 89 | endef 90 | define PRELINKCMDS 91 | endef 92 | define POSTBUILDCMDS 93 | endef 94 | endif 95 | 96 | ifeq ($(config),release32) 97 | OBJDIR = obj/x32/Release/hiberlite 98 | TARGETDIR = .. 99 | TARGET = $(TARGETDIR)/libhiberlite.a 100 | DEFINES += -DRELEASE 101 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 102 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 103 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -m32 -v -std=c++0x 104 | CXXFLAGS += $(CFLAGS) 105 | LDFLAGS += -s -m32 -L/usr/lib32 106 | RESFLAGS += $(DEFINES) $(INCLUDES) 107 | LIBS += 108 | LDDEPS += 109 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 110 | define PREBUILDCMDS 111 | endef 112 | define PRELINKCMDS 113 | endef 114 | define POSTBUILDCMDS 115 | endef 116 | endif 117 | 118 | ifeq ($(config),debug64) 119 | OBJDIR = obj/x64/Debug/hiberlite 120 | TARGETDIR = .. 121 | TARGET = $(TARGETDIR)/libhiberlite.a 122 | DEFINES += -DDEBUG -D_DEBUG 123 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 124 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 125 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -m64 -v -std=c++0x 126 | CXXFLAGS += $(CFLAGS) 127 | LDFLAGS += -m64 -L/usr/lib64 128 | RESFLAGS += $(DEFINES) $(INCLUDES) 129 | LIBS += 130 | LDDEPS += 131 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 132 | define PREBUILDCMDS 133 | endef 134 | define PRELINKCMDS 135 | endef 136 | define POSTBUILDCMDS 137 | endef 138 | endif 139 | 140 | ifeq ($(config),release64) 141 | OBJDIR = obj/x64/Release/hiberlite 142 | TARGETDIR = .. 143 | TARGET = $(TARGETDIR)/libhiberlite.a 144 | DEFINES += -DRELEASE 145 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 146 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 147 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -m64 -v -std=c++0x 148 | CXXFLAGS += $(CFLAGS) 149 | LDFLAGS += -s -m64 -L/usr/lib64 150 | RESFLAGS += $(DEFINES) $(INCLUDES) 151 | LIBS += 152 | LDDEPS += 153 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 154 | define PREBUILDCMDS 155 | endef 156 | define PRELINKCMDS 157 | endef 158 | define POSTBUILDCMDS 159 | endef 160 | endif 161 | 162 | OBJECTS := \ 163 | $(OBJDIR)/Visitor.o \ 164 | $(OBJDIR)/Database.o \ 165 | $(OBJDIR)/CppModel.o \ 166 | $(OBJDIR)/BeanLoader.o \ 167 | $(OBJDIR)/BeanUpdater.o \ 168 | $(OBJDIR)/ChildKiller.o \ 169 | $(OBJDIR)/ModelExtractor.o \ 170 | $(OBJDIR)/shared_res.o \ 171 | $(OBJDIR)/Registry.o \ 172 | $(OBJDIR)/SQLiteStmt.o \ 173 | 174 | RESOURCES := \ 175 | 176 | SHELLTYPE := msdos 177 | ifeq (,$(ComSpec)$(COMSPEC)) 178 | SHELLTYPE := posix 179 | endif 180 | ifeq (/bin,$(findstring /bin,$(SHELL))) 181 | SHELLTYPE := posix 182 | endif 183 | 184 | .PHONY: clean prebuild prelink 185 | 186 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) 187 | @: 188 | 189 | $(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES) 190 | @echo Linking hiberlite 191 | $(SILENT) $(LINKCMD) 192 | $(POSTBUILDCMDS) 193 | 194 | $(TARGETDIR): 195 | @echo Creating $(TARGETDIR) 196 | ifeq (posix,$(SHELLTYPE)) 197 | $(SILENT) mkdir -p $(TARGETDIR) 198 | else 199 | $(SILENT) mkdir $(subst /,\\,$(TARGETDIR)) 200 | endif 201 | 202 | $(OBJDIR): 203 | @echo Creating $(OBJDIR) 204 | ifeq (posix,$(SHELLTYPE)) 205 | $(SILENT) mkdir -p $(OBJDIR) 206 | else 207 | $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) 208 | endif 209 | 210 | clean: 211 | @echo Cleaning hiberlite 212 | ifeq (posix,$(SHELLTYPE)) 213 | $(SILENT) rm -f $(TARGET) 214 | $(SILENT) rm -rf $(OBJDIR) 215 | else 216 | $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) 217 | $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR)) 218 | endif 219 | 220 | prebuild: 221 | $(PREBUILDCMDS) 222 | 223 | prelink: 224 | $(PRELINKCMDS) 225 | 226 | ifneq (,$(PCH)) 227 | $(GCH): $(PCH) 228 | @echo $(notdir $<) 229 | ifeq (posix,$(SHELLTYPE)) 230 | -$(SILENT) cp $< $(OBJDIR) 231 | else 232 | $(SILENT) xcopy /D /Y /Q "$(subst /,\,$<)" "$(subst /,\,$(OBJDIR))" 1>nul 233 | endif 234 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 235 | endif 236 | 237 | $(OBJDIR)/Visitor.o: ../src/Visitor.cpp 238 | @echo $(notdir $<) 239 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 240 | $(OBJDIR)/Database.o: ../src/Database.cpp 241 | @echo $(notdir $<) 242 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 243 | $(OBJDIR)/CppModel.o: ../src/CppModel.cpp 244 | @echo $(notdir $<) 245 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 246 | $(OBJDIR)/BeanLoader.o: ../src/BeanLoader.cpp 247 | @echo $(notdir $<) 248 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 249 | $(OBJDIR)/BeanUpdater.o: ../src/BeanUpdater.cpp 250 | @echo $(notdir $<) 251 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 252 | $(OBJDIR)/ChildKiller.o: ../src/ChildKiller.cpp 253 | @echo $(notdir $<) 254 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 255 | $(OBJDIR)/ModelExtractor.o: ../src/ModelExtractor.cpp 256 | @echo $(notdir $<) 257 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 258 | $(OBJDIR)/shared_res.o: ../src/shared_res.cpp 259 | @echo $(notdir $<) 260 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 261 | $(OBJDIR)/Registry.o: ../src/Registry.cpp 262 | @echo $(notdir $<) 263 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 264 | $(OBJDIR)/SQLiteStmt.o: ../src/SQLiteStmt.cpp 265 | @echo $(notdir $<) 266 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 267 | 268 | -include $(OBJECTS:%.o=%.d) 269 | -------------------------------------------------------------------------------- /Build/hiberlite.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 2013 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "catch_test", "catch_test.vcxproj", "{27B715B5-136F-5702-7C76-305E684DF2F2}" 4 | EndProject 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hiberlite", "hiberlite.vcxproj", "{1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}" 6 | EndProject 7 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hiberlite_test", "hiberlite_test.vcxproj", "{FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}" 8 | EndProject 9 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample", "sample.vcxproj", "{073E391B-F3DF-63F1-DC9A-7745C8DBEA41}" 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sqlite", "sqlite.vcxproj", "{F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|native = Debug|native 16 | Debug|Win32 = Debug|Win32 17 | Debug|x64 = Debug|x64 18 | Release|native = Release|native 19 | Release|Win32 = Release|Win32 20 | Release|x64 = Release|x64 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Debug|native.ActiveCfg = Debug native|Win32 24 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Debug|native.Build.0 = Debug native|Win32 25 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Debug|Win32.ActiveCfg = Debug|Win32 26 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Debug|Win32.Build.0 = Debug|Win32 27 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Debug|x64.ActiveCfg = Debug|x64 28 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Debug|x64.Build.0 = Debug|x64 29 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Release|native.ActiveCfg = Release native|Win32 30 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Release|native.Build.0 = Release native|Win32 31 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Release|Win32.ActiveCfg = Release|Win32 32 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Release|Win32.Build.0 = Release|Win32 33 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Release|x64.ActiveCfg = Release|x64 34 | {27B715B5-136F-5702-7C76-305E684DF2F2}.Release|x64.Build.0 = Release|x64 35 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Debug|native.ActiveCfg = Debug native|Win32 36 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Debug|native.Build.0 = Debug native|Win32 37 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Debug|Win32.ActiveCfg = Debug|Win32 38 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Debug|Win32.Build.0 = Debug|Win32 39 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Debug|x64.ActiveCfg = Debug|x64 40 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Debug|x64.Build.0 = Debug|x64 41 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Release|native.ActiveCfg = Release native|Win32 42 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Release|native.Build.0 = Release native|Win32 43 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Release|Win32.ActiveCfg = Release|Win32 44 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Release|Win32.Build.0 = Release|Win32 45 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Release|x64.ActiveCfg = Release|x64 46 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Release|x64.Build.0 = Release|x64 47 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Debug|native.ActiveCfg = Debug native|Win32 48 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Debug|native.Build.0 = Debug native|Win32 49 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Debug|Win32.ActiveCfg = Debug|Win32 50 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Debug|Win32.Build.0 = Debug|Win32 51 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Debug|x64.ActiveCfg = Debug|x64 52 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Debug|x64.Build.0 = Debug|x64 53 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Release|native.ActiveCfg = Release native|Win32 54 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Release|native.Build.0 = Release native|Win32 55 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Release|Win32.ActiveCfg = Release|Win32 56 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Release|Win32.Build.0 = Release|Win32 57 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Release|x64.ActiveCfg = Release|x64 58 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Release|x64.Build.0 = Release|x64 59 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Debug|native.ActiveCfg = Debug native|Win32 60 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Debug|native.Build.0 = Debug native|Win32 61 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Debug|Win32.ActiveCfg = Debug|Win32 62 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Debug|Win32.Build.0 = Debug|Win32 63 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Debug|x64.ActiveCfg = Debug|x64 64 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Debug|x64.Build.0 = Debug|x64 65 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Release|native.ActiveCfg = Release native|Win32 66 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Release|native.Build.0 = Release native|Win32 67 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Release|Win32.ActiveCfg = Release|Win32 68 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Release|Win32.Build.0 = Release|Win32 69 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Release|x64.ActiveCfg = Release|x64 70 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Release|x64.Build.0 = Release|x64 71 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Debug|native.ActiveCfg = Debug native|Win32 72 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Debug|native.Build.0 = Debug native|Win32 73 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Debug|Win32.ActiveCfg = Debug|Win32 74 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Debug|Win32.Build.0 = Debug|Win32 75 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Debug|x64.ActiveCfg = Debug|x64 76 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Debug|x64.Build.0 = Debug|x64 77 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Release|native.ActiveCfg = Release native|Win32 78 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Release|native.Build.0 = Release native|Win32 79 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Release|Win32.ActiveCfg = Release|Win32 80 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Release|Win32.Build.0 = Release|Win32 81 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Release|x64.ActiveCfg = Release|x64 82 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Release|x64.Build.0 = Release|x64 83 | EndGlobalSection 84 | GlobalSection(SolutionProperties) = preSolution 85 | HideSolutionNode = FALSE 86 | EndGlobalSection 87 | EndGlobal 88 | -------------------------------------------------------------------------------- /Build/hiberlite.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {C196CD9C-2D76-4C38-368E-D70EA2ECB299} 6 | 7 | 8 | {89565304-F535-D29F-FE4D-5D766AAC3801} 9 | 10 | 11 | 12 | 13 | Headers 14 | 15 | 16 | Headers 17 | 18 | 19 | Headers 20 | 21 | 22 | Headers 23 | 24 | 25 | Headers 26 | 27 | 28 | Headers 29 | 30 | 31 | Headers 32 | 33 | 34 | Headers 35 | 36 | 37 | Headers 38 | 39 | 40 | Headers 41 | 42 | 43 | Headers 44 | 45 | 46 | Headers 47 | 48 | 49 | Headers 50 | 51 | 52 | Headers 53 | 54 | 55 | Headers 56 | 57 | 58 | Headers 59 | 60 | 61 | Headers 62 | 63 | 64 | Headers 65 | 66 | 67 | Headers 68 | 69 | 70 | Headers 71 | 72 | 73 | Headers 74 | 75 | 76 | Headers 77 | 78 | 79 | Headers 80 | 81 | 82 | Headers 83 | 84 | 85 | Headers 86 | 87 | 88 | Headers 89 | 90 | 91 | 92 | 93 | Sources 94 | 95 | 96 | Sources 97 | 98 | 99 | Sources 100 | 101 | 102 | Sources 103 | 104 | 105 | Sources 106 | 107 | 108 | Sources 109 | 110 | 111 | Sources 112 | 113 | 114 | Sources 115 | 116 | 117 | Sources 118 | 119 | 120 | Sources 121 | 122 | 123 | -------------------------------------------------------------------------------- /Build/hiberlite_test.make: -------------------------------------------------------------------------------- 1 | # GNU Make project makefile autogenerated by Premake 2 | ifndef config 3 | config=debug 4 | endif 5 | 6 | ifndef verbose 7 | SILENT = @ 8 | endif 9 | 10 | ifndef CC 11 | CC = gcc 12 | endif 13 | 14 | ifndef CXX 15 | CXX = g++ 16 | endif 17 | 18 | ifndef AR 19 | AR = ar 20 | endif 21 | 22 | ifndef RESCOMP 23 | ifdef WINDRES 24 | RESCOMP = $(WINDRES) 25 | else 26 | RESCOMP = windres 27 | endif 28 | endif 29 | 30 | ifeq ($(config),debug) 31 | OBJDIR = obj/Debug/hiberlite_test 32 | TARGETDIR = .. 33 | TARGET = $(TARGETDIR)/hiberlite_test 34 | DEFINES += -DDEBUG -D_DEBUG 35 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 36 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 37 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -v -std=c++0x 38 | CXXFLAGS += $(CFLAGS) 39 | LDFLAGS += -L.. 40 | RESFLAGS += $(DEFINES) $(INCLUDES) 41 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 42 | LDDEPS += ../libhiberlite.a ../libsqlite.a 43 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 44 | define PREBUILDCMDS 45 | endef 46 | define PRELINKCMDS 47 | endef 48 | define POSTBUILDCMDS 49 | @echo Running post-build commands 50 | $(TARGET) 51 | endef 52 | endif 53 | 54 | ifeq ($(config),release) 55 | OBJDIR = obj/Release/hiberlite_test 56 | TARGETDIR = .. 57 | TARGET = $(TARGETDIR)/hiberlite_test 58 | DEFINES += -DRELEASE 59 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 60 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 61 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -v -std=c++0x 62 | CXXFLAGS += $(CFLAGS) 63 | LDFLAGS += -L.. -s 64 | RESFLAGS += $(DEFINES) $(INCLUDES) 65 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 66 | LDDEPS += ../libhiberlite.a ../libsqlite.a 67 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 68 | define PREBUILDCMDS 69 | endef 70 | define PRELINKCMDS 71 | endef 72 | define POSTBUILDCMDS 73 | @echo Running post-build commands 74 | $(TARGET) 75 | endef 76 | endif 77 | 78 | ifeq ($(config),debug32) 79 | OBJDIR = obj/x32/Debug/hiberlite_test 80 | TARGETDIR = .. 81 | TARGET = $(TARGETDIR)/hiberlite_test 82 | DEFINES += -DDEBUG -D_DEBUG 83 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 84 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 85 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -m32 -v -std=c++0x 86 | CXXFLAGS += $(CFLAGS) 87 | LDFLAGS += -L.. -m32 -L/usr/lib32 88 | RESFLAGS += $(DEFINES) $(INCLUDES) 89 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 90 | LDDEPS += ../libhiberlite.a ../libsqlite.a 91 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 92 | define PREBUILDCMDS 93 | endef 94 | define PRELINKCMDS 95 | endef 96 | define POSTBUILDCMDS 97 | @echo Running post-build commands 98 | $(TARGET) 99 | endef 100 | endif 101 | 102 | ifeq ($(config),release32) 103 | OBJDIR = obj/x32/Release/hiberlite_test 104 | TARGETDIR = .. 105 | TARGET = $(TARGETDIR)/hiberlite_test 106 | DEFINES += -DRELEASE 107 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 108 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 109 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -m32 -v -std=c++0x 110 | CXXFLAGS += $(CFLAGS) 111 | LDFLAGS += -L.. -s -m32 -L/usr/lib32 112 | RESFLAGS += $(DEFINES) $(INCLUDES) 113 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 114 | LDDEPS += ../libhiberlite.a ../libsqlite.a 115 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 116 | define PREBUILDCMDS 117 | endef 118 | define PRELINKCMDS 119 | endef 120 | define POSTBUILDCMDS 121 | @echo Running post-build commands 122 | $(TARGET) 123 | endef 124 | endif 125 | 126 | ifeq ($(config),debug64) 127 | OBJDIR = obj/x64/Debug/hiberlite_test 128 | TARGETDIR = .. 129 | TARGET = $(TARGETDIR)/hiberlite_test 130 | DEFINES += -DDEBUG -D_DEBUG 131 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 132 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 133 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -m64 -v -std=c++0x 134 | CXXFLAGS += $(CFLAGS) 135 | LDFLAGS += -L.. -m64 -L/usr/lib64 136 | RESFLAGS += $(DEFINES) $(INCLUDES) 137 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 138 | LDDEPS += ../libhiberlite.a ../libsqlite.a 139 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 140 | define PREBUILDCMDS 141 | endef 142 | define PRELINKCMDS 143 | endef 144 | define POSTBUILDCMDS 145 | @echo Running post-build commands 146 | $(TARGET) 147 | endef 148 | endif 149 | 150 | ifeq ($(config),release64) 151 | OBJDIR = obj/x64/Release/hiberlite_test 152 | TARGETDIR = .. 153 | TARGET = $(TARGETDIR)/hiberlite_test 154 | DEFINES += -DRELEASE 155 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 156 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 157 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -m64 -v -std=c++0x 158 | CXXFLAGS += $(CFLAGS) 159 | LDFLAGS += -L.. -s -m64 -L/usr/lib64 160 | RESFLAGS += $(DEFINES) $(INCLUDES) 161 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 162 | LDDEPS += ../libhiberlite.a ../libsqlite.a 163 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 164 | define PREBUILDCMDS 165 | endef 166 | define PRELINKCMDS 167 | endef 168 | define POSTBUILDCMDS 169 | @echo Running post-build commands 170 | $(TARGET) 171 | endef 172 | endif 173 | 174 | OBJECTS := \ 175 | $(OBJDIR)/tests.o \ 176 | 177 | RESOURCES := \ 178 | 179 | SHELLTYPE := msdos 180 | ifeq (,$(ComSpec)$(COMSPEC)) 181 | SHELLTYPE := posix 182 | endif 183 | ifeq (/bin,$(findstring /bin,$(SHELL))) 184 | SHELLTYPE := posix 185 | endif 186 | 187 | .PHONY: clean prebuild prelink 188 | 189 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) 190 | @: 191 | 192 | $(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES) 193 | @echo Linking hiberlite_test 194 | $(SILENT) $(LINKCMD) 195 | $(POSTBUILDCMDS) 196 | 197 | $(TARGETDIR): 198 | @echo Creating $(TARGETDIR) 199 | ifeq (posix,$(SHELLTYPE)) 200 | $(SILENT) mkdir -p $(TARGETDIR) 201 | else 202 | $(SILENT) mkdir $(subst /,\\,$(TARGETDIR)) 203 | endif 204 | 205 | $(OBJDIR): 206 | @echo Creating $(OBJDIR) 207 | ifeq (posix,$(SHELLTYPE)) 208 | $(SILENT) mkdir -p $(OBJDIR) 209 | else 210 | $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) 211 | endif 212 | 213 | clean: 214 | @echo Cleaning hiberlite_test 215 | ifeq (posix,$(SHELLTYPE)) 216 | $(SILENT) rm -f $(TARGET) 217 | $(SILENT) rm -rf $(OBJDIR) 218 | else 219 | $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) 220 | $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR)) 221 | endif 222 | 223 | prebuild: 224 | $(PREBUILDCMDS) 225 | 226 | prelink: 227 | $(PRELINKCMDS) 228 | 229 | ifneq (,$(PCH)) 230 | $(GCH): $(PCH) 231 | @echo $(notdir $<) 232 | ifeq (posix,$(SHELLTYPE)) 233 | -$(SILENT) cp $< $(OBJDIR) 234 | else 235 | $(SILENT) xcopy /D /Y /Q "$(subst /,\,$<)" "$(subst /,\,$(OBJDIR))" 1>nul 236 | endif 237 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 238 | endif 239 | 240 | $(OBJDIR)/tests.o: ../tests.cpp 241 | @echo $(notdir $<) 242 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 243 | 244 | -include $(OBJECTS:%.o=%.d) 245 | -------------------------------------------------------------------------------- /Build/hiberlite_test.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug native 6 | Win32 7 | 8 | 9 | Debug native 10 | x64 11 | 12 | 13 | Debug 14 | Win32 15 | 16 | 17 | Debug 18 | x64 19 | 20 | 21 | Release native 22 | Win32 23 | 24 | 25 | Release native 26 | x64 27 | 28 | 29 | Release 30 | Win32 31 | 32 | 33 | Release 34 | x64 35 | 36 | 37 | 38 | {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E} 39 | true 40 | Win32Proj 41 | hiberlite_test 42 | 43 | 44 | 45 | Application 46 | true 47 | MultiByte 48 | v120 49 | 50 | 51 | Application 52 | true 53 | MultiByte 54 | v120 55 | 56 | 57 | Application 58 | true 59 | MultiByte 60 | v120 61 | 62 | 63 | Application 64 | false 65 | MultiByte 66 | v120 67 | 68 | 69 | Application 70 | false 71 | MultiByte 72 | v120 73 | 74 | 75 | Application 76 | false 77 | MultiByte 78 | v120 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | true 104 | ..\bin\hiberlite_test\Debug\ 105 | ..\obj\hiberlite_test\Debug\native\ 106 | hiberlite_test 107 | .exe 108 | 109 | 110 | true 111 | ..\bin\hiberlite_test\Debug\ 112 | ..\obj\hiberlite_test\Debug\x32\ 113 | hiberlite_test 114 | .exe 115 | 116 | 117 | true 118 | ..\bin\hiberlite_test\Debug\ 119 | ..\obj\hiberlite_test\Debug\x64\ 120 | hiberlite_test 121 | .exe 122 | 123 | 124 | false 125 | ..\bin\hiberlite_test\Release\ 126 | ..\obj\hiberlite_test\Release\native\ 127 | hiberlite_test 128 | .exe 129 | 130 | 131 | false 132 | ..\bin\hiberlite_test\Release\ 133 | ..\obj\hiberlite_test\Release\x32\ 134 | hiberlite_test 135 | .exe 136 | 137 | 138 | false 139 | ..\bin\hiberlite_test\Release\ 140 | ..\obj\hiberlite_test\Release\x64\ 141 | hiberlite_test 142 | .exe 143 | 144 | 145 | 146 | NotUsing 147 | Level3 148 | DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 149 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 150 | EditAndContinue 151 | Disabled 152 | 153 | 154 | Console 155 | true 156 | mainCRTStartup 157 | 158 | 159 | "$(TargetPath)" 160 | 161 | 162 | 163 | 164 | NotUsing 165 | Level3 166 | DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 167 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 168 | EditAndContinue 169 | Disabled 170 | 171 | 172 | Console 173 | true 174 | mainCRTStartup 175 | 176 | 177 | "$(TargetPath)" 178 | 179 | 180 | 181 | 182 | NotUsing 183 | Level3 184 | DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 185 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 186 | ProgramDatabase 187 | Disabled 188 | 189 | 190 | Console 191 | true 192 | mainCRTStartup 193 | 194 | 195 | "$(TargetPath)" 196 | 197 | 198 | 199 | 200 | NotUsing 201 | Level3 202 | RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 203 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 204 | Full 205 | true 206 | true 207 | false 208 | true 209 | 210 | 211 | Console 212 | false 213 | true 214 | true 215 | mainCRTStartup 216 | 217 | 218 | "$(TargetPath)" 219 | 220 | 221 | 222 | 223 | NotUsing 224 | Level3 225 | RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 226 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 227 | Full 228 | true 229 | true 230 | false 231 | true 232 | 233 | 234 | Console 235 | false 236 | true 237 | true 238 | mainCRTStartup 239 | 240 | 241 | "$(TargetPath)" 242 | 243 | 244 | 245 | 246 | NotUsing 247 | Level3 248 | RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 249 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 250 | Full 251 | true 252 | true 253 | false 254 | true 255 | 256 | 257 | Console 258 | false 259 | true 260 | true 261 | mainCRTStartup 262 | 263 | 264 | "$(TargetPath)" 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62} 273 | 274 | 275 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43} 276 | 277 | 278 | 279 | 280 | 281 | -------------------------------------------------------------------------------- /Build/hiberlite_test.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {89565304-F535-D29F-FE4D-5D766AAC3801} 6 | 7 | 8 | 9 | 10 | Sources 11 | 12 | 13 | -------------------------------------------------------------------------------- /Build/sample.make: -------------------------------------------------------------------------------- 1 | # GNU Make project makefile autogenerated by Premake 2 | ifndef config 3 | config=debug 4 | endif 5 | 6 | ifndef verbose 7 | SILENT = @ 8 | endif 9 | 10 | ifndef CC 11 | CC = gcc 12 | endif 13 | 14 | ifndef CXX 15 | CXX = g++ 16 | endif 17 | 18 | ifndef AR 19 | AR = ar 20 | endif 21 | 22 | ifndef RESCOMP 23 | ifdef WINDRES 24 | RESCOMP = $(WINDRES) 25 | else 26 | RESCOMP = windres 27 | endif 28 | endif 29 | 30 | ifeq ($(config),debug) 31 | OBJDIR = obj/Debug/sample 32 | TARGETDIR = .. 33 | TARGET = $(TARGETDIR)/sample 34 | DEFINES += -DDEBUG -D_DEBUG 35 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 36 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 37 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -v -std=c++0x 38 | CXXFLAGS += $(CFLAGS) 39 | LDFLAGS += -L.. 40 | RESFLAGS += $(DEFINES) $(INCLUDES) 41 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 42 | LDDEPS += ../libhiberlite.a ../libsqlite.a 43 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 44 | define PREBUILDCMDS 45 | endef 46 | define PRELINKCMDS 47 | endef 48 | define POSTBUILDCMDS 49 | @echo Running post-build commands 50 | $(TARGET) 51 | endef 52 | endif 53 | 54 | ifeq ($(config),release) 55 | OBJDIR = obj/Release/sample 56 | TARGETDIR = .. 57 | TARGET = $(TARGETDIR)/sample 58 | DEFINES += -DRELEASE 59 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 60 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 61 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -v -std=c++0x 62 | CXXFLAGS += $(CFLAGS) 63 | LDFLAGS += -L.. -s 64 | RESFLAGS += $(DEFINES) $(INCLUDES) 65 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 66 | LDDEPS += ../libhiberlite.a ../libsqlite.a 67 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 68 | define PREBUILDCMDS 69 | endef 70 | define PRELINKCMDS 71 | endef 72 | define POSTBUILDCMDS 73 | @echo Running post-build commands 74 | $(TARGET) 75 | endef 76 | endif 77 | 78 | ifeq ($(config),debug32) 79 | OBJDIR = obj/x32/Debug/sample 80 | TARGETDIR = .. 81 | TARGET = $(TARGETDIR)/sample 82 | DEFINES += -DDEBUG -D_DEBUG 83 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 84 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 85 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -m32 -v -std=c++0x 86 | CXXFLAGS += $(CFLAGS) 87 | LDFLAGS += -L.. -m32 -L/usr/lib32 88 | RESFLAGS += $(DEFINES) $(INCLUDES) 89 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 90 | LDDEPS += ../libhiberlite.a ../libsqlite.a 91 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 92 | define PREBUILDCMDS 93 | endef 94 | define PRELINKCMDS 95 | endef 96 | define POSTBUILDCMDS 97 | @echo Running post-build commands 98 | $(TARGET) 99 | endef 100 | endif 101 | 102 | ifeq ($(config),release32) 103 | OBJDIR = obj/x32/Release/sample 104 | TARGETDIR = .. 105 | TARGET = $(TARGETDIR)/sample 106 | DEFINES += -DRELEASE 107 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 108 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 109 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -m32 -v -std=c++0x 110 | CXXFLAGS += $(CFLAGS) 111 | LDFLAGS += -L.. -s -m32 -L/usr/lib32 112 | RESFLAGS += $(DEFINES) $(INCLUDES) 113 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 114 | LDDEPS += ../libhiberlite.a ../libsqlite.a 115 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 116 | define PREBUILDCMDS 117 | endef 118 | define PRELINKCMDS 119 | endef 120 | define POSTBUILDCMDS 121 | @echo Running post-build commands 122 | $(TARGET) 123 | endef 124 | endif 125 | 126 | ifeq ($(config),debug64) 127 | OBJDIR = obj/x64/Debug/sample 128 | TARGETDIR = .. 129 | TARGET = $(TARGETDIR)/sample 130 | DEFINES += -DDEBUG -D_DEBUG 131 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 132 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 133 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -m64 -v -std=c++0x 134 | CXXFLAGS += $(CFLAGS) 135 | LDFLAGS += -L.. -m64 -L/usr/lib64 136 | RESFLAGS += $(DEFINES) $(INCLUDES) 137 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 138 | LDDEPS += ../libhiberlite.a ../libsqlite.a 139 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 140 | define PREBUILDCMDS 141 | endef 142 | define PRELINKCMDS 143 | endef 144 | define POSTBUILDCMDS 145 | @echo Running post-build commands 146 | $(TARGET) 147 | endef 148 | endif 149 | 150 | ifeq ($(config),release64) 151 | OBJDIR = obj/x64/Release/sample 152 | TARGETDIR = .. 153 | TARGET = $(TARGETDIR)/sample 154 | DEFINES += -DRELEASE 155 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 156 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 157 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -m64 -v -std=c++0x 158 | CXXFLAGS += $(CFLAGS) 159 | LDFLAGS += -L.. -s -m64 -L/usr/lib64 160 | RESFLAGS += $(DEFINES) $(INCLUDES) 161 | LIBS += ../libhiberlite.a ../libsqlite.a -ldl -lpthread 162 | LDDEPS += ../libhiberlite.a ../libsqlite.a 163 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(LIBS) $(LDFLAGS) 164 | define PREBUILDCMDS 165 | endef 166 | define PRELINKCMDS 167 | endef 168 | define POSTBUILDCMDS 169 | @echo Running post-build commands 170 | $(TARGET) 171 | endef 172 | endif 173 | 174 | OBJECTS := \ 175 | $(OBJDIR)/sample.o \ 176 | 177 | RESOURCES := \ 178 | 179 | SHELLTYPE := msdos 180 | ifeq (,$(ComSpec)$(COMSPEC)) 181 | SHELLTYPE := posix 182 | endif 183 | ifeq (/bin,$(findstring /bin,$(SHELL))) 184 | SHELLTYPE := posix 185 | endif 186 | 187 | .PHONY: clean prebuild prelink 188 | 189 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) 190 | @: 191 | 192 | $(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES) 193 | @echo Linking sample 194 | $(SILENT) $(LINKCMD) 195 | $(POSTBUILDCMDS) 196 | 197 | $(TARGETDIR): 198 | @echo Creating $(TARGETDIR) 199 | ifeq (posix,$(SHELLTYPE)) 200 | $(SILENT) mkdir -p $(TARGETDIR) 201 | else 202 | $(SILENT) mkdir $(subst /,\\,$(TARGETDIR)) 203 | endif 204 | 205 | $(OBJDIR): 206 | @echo Creating $(OBJDIR) 207 | ifeq (posix,$(SHELLTYPE)) 208 | $(SILENT) mkdir -p $(OBJDIR) 209 | else 210 | $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) 211 | endif 212 | 213 | clean: 214 | @echo Cleaning sample 215 | ifeq (posix,$(SHELLTYPE)) 216 | $(SILENT) rm -f $(TARGET) 217 | $(SILENT) rm -rf $(OBJDIR) 218 | else 219 | $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) 220 | $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR)) 221 | endif 222 | 223 | prebuild: 224 | $(PREBUILDCMDS) 225 | 226 | prelink: 227 | $(PRELINKCMDS) 228 | 229 | ifneq (,$(PCH)) 230 | $(GCH): $(PCH) 231 | @echo $(notdir $<) 232 | ifeq (posix,$(SHELLTYPE)) 233 | -$(SILENT) cp $< $(OBJDIR) 234 | else 235 | $(SILENT) xcopy /D /Y /Q "$(subst /,\,$<)" "$(subst /,\,$(OBJDIR))" 1>nul 236 | endif 237 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 238 | endif 239 | 240 | $(OBJDIR)/sample.o: ../sample.cpp 241 | @echo $(notdir $<) 242 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 243 | 244 | -include $(OBJECTS:%.o=%.d) 245 | -------------------------------------------------------------------------------- /Build/sample.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug native 6 | Win32 7 | 8 | 9 | Debug native 10 | x64 11 | 12 | 13 | Debug 14 | Win32 15 | 16 | 17 | Debug 18 | x64 19 | 20 | 21 | Release native 22 | Win32 23 | 24 | 25 | Release native 26 | x64 27 | 28 | 29 | Release 30 | Win32 31 | 32 | 33 | Release 34 | x64 35 | 36 | 37 | 38 | {073E391B-F3DF-63F1-DC9A-7745C8DBEA41} 39 | true 40 | Win32Proj 41 | sample 42 | 43 | 44 | 45 | Application 46 | true 47 | MultiByte 48 | v120 49 | 50 | 51 | Application 52 | true 53 | MultiByte 54 | v120 55 | 56 | 57 | Application 58 | true 59 | MultiByte 60 | v120 61 | 62 | 63 | Application 64 | false 65 | MultiByte 66 | v120 67 | 68 | 69 | Application 70 | false 71 | MultiByte 72 | v120 73 | 74 | 75 | Application 76 | false 77 | MultiByte 78 | v120 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | true 104 | ..\bin\sample\Debug\ 105 | ..\obj\sample\Debug\native\ 106 | sample 107 | .exe 108 | 109 | 110 | true 111 | ..\bin\sample\Debug\ 112 | ..\obj\sample\Debug\x32\ 113 | sample 114 | .exe 115 | 116 | 117 | true 118 | ..\bin\sample\Debug\ 119 | ..\obj\sample\Debug\x64\ 120 | sample 121 | .exe 122 | 123 | 124 | false 125 | ..\bin\sample\Release\ 126 | ..\obj\sample\Release\native\ 127 | sample 128 | .exe 129 | 130 | 131 | false 132 | ..\bin\sample\Release\ 133 | ..\obj\sample\Release\x32\ 134 | sample 135 | .exe 136 | 137 | 138 | false 139 | ..\bin\sample\Release\ 140 | ..\obj\sample\Release\x64\ 141 | sample 142 | .exe 143 | 144 | 145 | 146 | NotUsing 147 | Level3 148 | DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 149 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 150 | EditAndContinue 151 | Disabled 152 | 153 | 154 | Console 155 | true 156 | mainCRTStartup 157 | 158 | 159 | "$(TargetPath)" 160 | 161 | 162 | 163 | 164 | NotUsing 165 | Level3 166 | DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 167 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 168 | EditAndContinue 169 | Disabled 170 | 171 | 172 | Console 173 | true 174 | mainCRTStartup 175 | 176 | 177 | "$(TargetPath)" 178 | 179 | 180 | 181 | 182 | NotUsing 183 | Level3 184 | DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 185 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 186 | ProgramDatabase 187 | Disabled 188 | 189 | 190 | Console 191 | true 192 | mainCRTStartup 193 | 194 | 195 | "$(TargetPath)" 196 | 197 | 198 | 199 | 200 | NotUsing 201 | Level3 202 | RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 203 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 204 | Full 205 | true 206 | true 207 | false 208 | true 209 | 210 | 211 | Console 212 | false 213 | true 214 | true 215 | mainCRTStartup 216 | 217 | 218 | "$(TargetPath)" 219 | 220 | 221 | 222 | 223 | NotUsing 224 | Level3 225 | RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 226 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 227 | Full 228 | true 229 | true 230 | false 231 | true 232 | 233 | 234 | Console 235 | false 236 | true 237 | true 238 | mainCRTStartup 239 | 240 | 241 | "$(TargetPath)" 242 | 243 | 244 | 245 | 246 | NotUsing 247 | Level3 248 | RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 249 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 250 | Full 251 | true 252 | true 253 | false 254 | true 255 | 256 | 257 | Console 258 | false 259 | true 260 | true 261 | mainCRTStartup 262 | 263 | 264 | "$(TargetPath)" 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62} 273 | 274 | 275 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43} 276 | 277 | 278 | 279 | 280 | 281 | -------------------------------------------------------------------------------- /Build/sample.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {89565304-F535-D29F-FE4D-5D766AAC3801} 6 | 7 | 8 | 9 | 10 | Sources 11 | 12 | 13 | -------------------------------------------------------------------------------- /Build/sqlite.make: -------------------------------------------------------------------------------- 1 | # GNU Make project makefile autogenerated by Premake 2 | ifndef config 3 | config=debug 4 | endif 5 | 6 | ifndef verbose 7 | SILENT = @ 8 | endif 9 | 10 | ifndef CC 11 | CC = gcc 12 | endif 13 | 14 | ifndef CXX 15 | CXX = g++ 16 | endif 17 | 18 | ifndef AR 19 | AR = ar 20 | endif 21 | 22 | ifndef RESCOMP 23 | ifdef WINDRES 24 | RESCOMP = $(WINDRES) 25 | else 26 | RESCOMP = windres 27 | endif 28 | endif 29 | 30 | ifeq ($(config),debug) 31 | OBJDIR = obj/Debug/sqlite 32 | TARGETDIR = .. 33 | TARGET = $(TARGETDIR)/libsqlite.a 34 | DEFINES += -DDEBUG -D_DEBUG 35 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 36 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 37 | CFLAGS += $(CPPFLAGS) $(ARCH) -g 38 | CXXFLAGS += $(CFLAGS) 39 | LDFLAGS += 40 | RESFLAGS += $(DEFINES) $(INCLUDES) 41 | LIBS += 42 | LDDEPS += 43 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 44 | define PREBUILDCMDS 45 | endef 46 | define PRELINKCMDS 47 | endef 48 | define POSTBUILDCMDS 49 | endef 50 | endif 51 | 52 | ifeq ($(config),release) 53 | OBJDIR = obj/Release/sqlite 54 | TARGETDIR = .. 55 | TARGET = $(TARGETDIR)/libsqlite.a 56 | DEFINES += -DRELEASE 57 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 58 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 59 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 60 | CXXFLAGS += $(CFLAGS) 61 | LDFLAGS += -s 62 | RESFLAGS += $(DEFINES) $(INCLUDES) 63 | LIBS += 64 | LDDEPS += 65 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 66 | define PREBUILDCMDS 67 | endef 68 | define PRELINKCMDS 69 | endef 70 | define POSTBUILDCMDS 71 | endef 72 | endif 73 | 74 | ifeq ($(config),debug32) 75 | OBJDIR = obj/x32/Debug/sqlite 76 | TARGETDIR = .. 77 | TARGET = $(TARGETDIR)/libsqlite.a 78 | DEFINES += -DDEBUG -D_DEBUG 79 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 80 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 81 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -m32 82 | CXXFLAGS += $(CFLAGS) 83 | LDFLAGS += -m32 -L/usr/lib32 84 | RESFLAGS += $(DEFINES) $(INCLUDES) 85 | LIBS += 86 | LDDEPS += 87 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 88 | define PREBUILDCMDS 89 | endef 90 | define PRELINKCMDS 91 | endef 92 | define POSTBUILDCMDS 93 | endef 94 | endif 95 | 96 | ifeq ($(config),release32) 97 | OBJDIR = obj/x32/Release/sqlite 98 | TARGETDIR = .. 99 | TARGET = $(TARGETDIR)/libsqlite.a 100 | DEFINES += -DRELEASE 101 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 102 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 103 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -m32 104 | CXXFLAGS += $(CFLAGS) 105 | LDFLAGS += -s -m32 -L/usr/lib32 106 | RESFLAGS += $(DEFINES) $(INCLUDES) 107 | LIBS += 108 | LDDEPS += 109 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 110 | define PREBUILDCMDS 111 | endef 112 | define PRELINKCMDS 113 | endef 114 | define POSTBUILDCMDS 115 | endef 116 | endif 117 | 118 | ifeq ($(config),debug64) 119 | OBJDIR = obj/x64/Debug/sqlite 120 | TARGETDIR = .. 121 | TARGET = $(TARGETDIR)/libsqlite.a 122 | DEFINES += -DDEBUG -D_DEBUG 123 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 124 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 125 | CFLAGS += $(CPPFLAGS) $(ARCH) -g -m64 126 | CXXFLAGS += $(CFLAGS) 127 | LDFLAGS += -m64 -L/usr/lib64 128 | RESFLAGS += $(DEFINES) $(INCLUDES) 129 | LIBS += 130 | LDDEPS += 131 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 132 | define PREBUILDCMDS 133 | endef 134 | define PRELINKCMDS 135 | endef 136 | define POSTBUILDCMDS 137 | endef 138 | endif 139 | 140 | ifeq ($(config),release64) 141 | OBJDIR = obj/x64/Release/sqlite 142 | TARGETDIR = .. 143 | TARGET = $(TARGETDIR)/libsqlite.a 144 | DEFINES += -DRELEASE 145 | INCLUDES += -I../include -I../sqlite-amalgamation -I../Catch/single_include 146 | CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) 147 | CFLAGS += $(CPPFLAGS) $(ARCH) -O2 -m64 148 | CXXFLAGS += $(CFLAGS) 149 | LDFLAGS += -s -m64 -L/usr/lib64 150 | RESFLAGS += $(DEFINES) $(INCLUDES) 151 | LIBS += 152 | LDDEPS += 153 | LINKCMD = $(AR) -rcs $(TARGET) $(OBJECTS) 154 | define PREBUILDCMDS 155 | endef 156 | define PRELINKCMDS 157 | endef 158 | define POSTBUILDCMDS 159 | endef 160 | endif 161 | 162 | OBJECTS := \ 163 | $(OBJDIR)/sqlite3.o \ 164 | 165 | RESOURCES := \ 166 | 167 | SHELLTYPE := msdos 168 | ifeq (,$(ComSpec)$(COMSPEC)) 169 | SHELLTYPE := posix 170 | endif 171 | ifeq (/bin,$(findstring /bin,$(SHELL))) 172 | SHELLTYPE := posix 173 | endif 174 | 175 | .PHONY: clean prebuild prelink 176 | 177 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) 178 | @: 179 | 180 | $(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES) 181 | @echo Linking sqlite 182 | $(SILENT) $(LINKCMD) 183 | $(POSTBUILDCMDS) 184 | 185 | $(TARGETDIR): 186 | @echo Creating $(TARGETDIR) 187 | ifeq (posix,$(SHELLTYPE)) 188 | $(SILENT) mkdir -p $(TARGETDIR) 189 | else 190 | $(SILENT) mkdir $(subst /,\\,$(TARGETDIR)) 191 | endif 192 | 193 | $(OBJDIR): 194 | @echo Creating $(OBJDIR) 195 | ifeq (posix,$(SHELLTYPE)) 196 | $(SILENT) mkdir -p $(OBJDIR) 197 | else 198 | $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) 199 | endif 200 | 201 | clean: 202 | @echo Cleaning sqlite 203 | ifeq (posix,$(SHELLTYPE)) 204 | $(SILENT) rm -f $(TARGET) 205 | $(SILENT) rm -rf $(OBJDIR) 206 | else 207 | $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) 208 | $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR)) 209 | endif 210 | 211 | prebuild: 212 | $(PREBUILDCMDS) 213 | 214 | prelink: 215 | $(PRELINKCMDS) 216 | 217 | ifneq (,$(PCH)) 218 | $(GCH): $(PCH) 219 | @echo $(notdir $<) 220 | ifeq (posix,$(SHELLTYPE)) 221 | -$(SILENT) cp $< $(OBJDIR) 222 | else 223 | $(SILENT) xcopy /D /Y /Q "$(subst /,\,$<)" "$(subst /,\,$(OBJDIR))" 1>nul 224 | endif 225 | $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 226 | endif 227 | 228 | $(OBJDIR)/sqlite3.o: ../sqlite-amalgamation/sqlite3.c 229 | @echo $(notdir $<) 230 | $(SILENT) $(CC) $(CFLAGS) -o "$@" -MF $(@:%.o=%.d) -c "$<" 231 | 232 | -include $(OBJECTS:%.o=%.d) 233 | -------------------------------------------------------------------------------- /Build/sqlite.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug native 6 | Win32 7 | 8 | 9 | Debug native 10 | x64 11 | 12 | 13 | Debug 14 | Win32 15 | 16 | 17 | Debug 18 | x64 19 | 20 | 21 | Release native 22 | Win32 23 | 24 | 25 | Release native 26 | x64 27 | 28 | 29 | Release 30 | Win32 31 | 32 | 33 | Release 34 | x64 35 | 36 | 37 | 38 | {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43} 39 | true 40 | Win32Proj 41 | sqlite 42 | 43 | 44 | 45 | StaticLibrary 46 | true 47 | MultiByte 48 | v120 49 | 50 | 51 | StaticLibrary 52 | true 53 | MultiByte 54 | v120 55 | 56 | 57 | StaticLibrary 58 | true 59 | MultiByte 60 | v120 61 | 62 | 63 | StaticLibrary 64 | false 65 | MultiByte 66 | v120 67 | 68 | 69 | StaticLibrary 70 | false 71 | MultiByte 72 | v120 73 | 74 | 75 | StaticLibrary 76 | false 77 | MultiByte 78 | v120 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | ..\bin\sqlite\Debug\ 104 | ..\obj\sqlite\Debug\native\ 105 | sqlite 106 | .lib 107 | 108 | 109 | ..\bin\sqlite\Debug\ 110 | ..\obj\sqlite\Debug\x32\ 111 | sqlite 112 | .lib 113 | 114 | 115 | ..\bin\sqlite\Debug\ 116 | ..\obj\sqlite\Debug\x64\ 117 | sqlite 118 | .lib 119 | 120 | 121 | ..\bin\sqlite\Release\ 122 | ..\obj\sqlite\Release\native\ 123 | sqlite 124 | .lib 125 | 126 | 127 | ..\bin\sqlite\Release\ 128 | ..\obj\sqlite\Release\x32\ 129 | sqlite 130 | .lib 131 | 132 | 133 | ..\bin\sqlite\Release\ 134 | ..\obj\sqlite\Release\x64\ 135 | sqlite 136 | .lib 137 | 138 | 139 | 140 | NotUsing 141 | Level3 142 | DEBUG;_DEBUG;%(PreprocessorDefinitions) 143 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 144 | EditAndContinue 145 | Disabled 146 | CompileAsC 147 | 148 | 149 | Windows 150 | true 151 | 152 | 153 | 154 | 155 | NotUsing 156 | Level3 157 | DEBUG;_DEBUG;%(PreprocessorDefinitions) 158 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 159 | EditAndContinue 160 | Disabled 161 | CompileAsC 162 | 163 | 164 | Windows 165 | true 166 | 167 | 168 | 169 | 170 | NotUsing 171 | Level3 172 | DEBUG;_DEBUG;%(PreprocessorDefinitions) 173 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 174 | ProgramDatabase 175 | Disabled 176 | CompileAsC 177 | 178 | 179 | Windows 180 | true 181 | 182 | 183 | 184 | 185 | NotUsing 186 | Level3 187 | RELEASE;%(PreprocessorDefinitions) 188 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 189 | Full 190 | true 191 | true 192 | false 193 | true 194 | CompileAsC 195 | 196 | 197 | Windows 198 | false 199 | true 200 | true 201 | 202 | 203 | 204 | 205 | NotUsing 206 | Level3 207 | RELEASE;%(PreprocessorDefinitions) 208 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 209 | Full 210 | true 211 | true 212 | false 213 | true 214 | CompileAsC 215 | 216 | 217 | Windows 218 | false 219 | true 220 | true 221 | 222 | 223 | 224 | 225 | NotUsing 226 | Level3 227 | RELEASE;%(PreprocessorDefinitions) 228 | ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories) 229 | Full 230 | true 231 | true 232 | false 233 | true 234 | CompileAsC 235 | 236 | 237 | Windows 238 | false 239 | true 240 | true 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | -------------------------------------------------------------------------------- /Build/sqlite.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {C196CD9C-2D76-4C38-368E-D70EA2ECB299} 6 | 7 | 8 | {89565304-F535-D29F-FE4D-5D766AAC3801} 9 | 10 | 11 | 12 | 13 | Headers 14 | 15 | 16 | 17 | 18 | Sources 19 | 20 | 21 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | 3 | project(hiberlite) 4 | 5 | #find_package(Qt5 CONFIG REQUIRED Core Gui Widgets) 6 | 7 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 8 | set(CMAKE_CXX_STANDARD 11) 9 | 10 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-terminate") 11 | 12 | set(TARGET_NAME hiberlite) 13 | 14 | set(SOURCES_SQLITE 15 | sqlite-amalgamation/sqlite3.c 16 | sqlite-amalgamation/sqlite3.h 17 | ) 18 | 19 | set(SOURCES 20 | src/BeanLoader.cpp 21 | src/BeanUpdater.cpp 22 | src/ChildKiller.cpp 23 | src/CppModel.cpp 24 | src/Database.cpp 25 | src/ModelExtractor.cpp 26 | src/Registry.cpp 27 | src/shared_res.cpp 28 | src/SQLiteStmt.cpp 29 | src/Visitor.cpp 30 | 31 | include/BeanLoader.h 32 | include/BeanLoader_impl.hpp 33 | include/BeanUpdater.h 34 | include/BeanUpdater_impl.hpp 35 | include/ChildKiller.h 36 | include/ChildKiller_impl.hpp 37 | include/CppModel.h 38 | include/Database.h 39 | include/Database_tmpl_impl.hpp 40 | include/ModelExtractor.h 41 | include/ModelExtractor_impl.hpp 42 | include/Registry.h 43 | include/Registry_impl.hpp 44 | include/SQLiteStmt.h 45 | include/UpdateVisitor_tmpl.hpp 46 | include/Visitor.h 47 | include/Visitor_tmpl_impl.hpp 48 | include/bean_ptr.h 49 | include/bean_ptr_impl.hpp 50 | include/common.h 51 | include/db_error.h 52 | include/hiberdefs.h 53 | include/hiberlite.h 54 | include/nvp.h 55 | include/shared_res.h 56 | include/some_types.h 57 | ) 58 | 59 | add_library(${TARGET_NAME} 60 | ${SOURCES} 61 | ${SOURCES_SQLITE} 62 | ) 63 | 64 | target_include_directories(${TARGET_NAME} 65 | PUBLIC 66 | include 67 | sqlite-amalgamation 68 | ) 69 | 70 | target_link_libraries(${TARGET_NAME} 71 | pthread 72 | dl 73 | ) 74 | 75 | add_executable(sample 76 | sample.cpp 77 | ) 78 | 79 | target_link_libraries(sample 80 | ${TARGET_NAME} 81 | ) 82 | 83 | add_executable(tests 84 | tests.cpp 85 | ) 86 | 87 | target_link_libraries(tests 88 | ${TARGET_NAME} 89 | ) 90 | 91 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2014, Paul Korzhyk 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Hiberlite nor the names of its contributors may be used 13 | to endorse or promote products derived from this software without specific 14 | prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | INSTALL_PREFIX = /usr 3 | INSTALL_HEADERS = $(INSTALL_PREFIX)/include/hiberlite 4 | INSTALL_LIB = $(INSTALL_PREFIX)/lib 5 | 6 | all : libhiberlite.a sqlite3.o tests sample 7 | 8 | OBJS=BeanLoader.o BeanUpdater.o ChildKiller.o CppModel.o Database.o ModelExtractor.o Registry.o SQLiteStmt.o Visitor.o shared_res.o sqlite3.o 9 | 10 | CXXFLAGS=-std=c++0x -Iinclude/ -Wall -Isqlite-amalgamation 11 | LDFLAGS=-lpthread -ldl 12 | 13 | libhiberlite.a : $(OBJS) 14 | ar -r -s libhiberlite.a $(OBJS) 15 | 16 | tests : libhiberlite.a 17 | 18 | install : 19 | mkdir -p $(INSTALL_HEADERS) 20 | cp include/* $(INSTALL_HEADERS)/ 21 | mkdir -p $(INSTALL_LIB) 22 | cp libhiberlite.a $(INSTALL_LIB)/ 23 | 24 | sqlite3.o : 25 | gcc -c sqlite-amalgamation/sqlite3.c -o sqlite3.o 26 | 27 | %.o : src/%.cpp include/* 28 | g++ -c $(CXXFLAGS) $< -o $@ 29 | 30 | tests : tests.cpp libhiberlite.a 31 | g++ $(CXXFLAGS) -L./ tests.cpp -o tests -lhiberlite $(LDFLAGS) 32 | 33 | sample : sample.cpp libhiberlite.a 34 | g++ $(CXXFLAGS) -L./ sample.cpp -o sample -lhiberlite $(LDFLAGS) 35 | 36 | clean: 37 | rm -rf *.o tests sample 38 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | C++ to Sqlite ORM 3 | 4 | USAGE: just compile and link all files under src/ to your project. 5 | Add 6 | #include "hiberlite.h" 7 | to your code. 8 | 9 | 10 | C++ object-relational mapping with API inspired by the Boost.Serialization - that means almost no API to learn. 11 | 12 | In contrast to most serialization libraries with SQL serializers, C++ objects mapped with hiberlite behave similar to active record pattern - you are not forced to follow the "read all your data/modify some small part/write everything back" path. 13 | 14 | For people who need reliable data storage, ACID transactions, simple random-access to their data files, and don't like coding in SQL. 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hiberlite ORM 2 | 3 | [![Build Status](https://travis-ci.org/paulftw/hiberlite.png?branch=master)](https://travis-ci.org/paulftw/hiberlite) [![Build status](https://ci.appveyor.com/api/projects/status/7hmib3hlpx40ap07/branch/master?svg=true)](https://ci.appveyor.com/project/d-led/hiberlite/branch/master) 4 | 5 | 6 | C++ object-relational mapping with API inspired by the awesome Boost.Serialization - that means _almost no API to learn_. 7 | 8 | ## Usage 9 | 10 | Just compile and link all files under src/ to your project. 11 | Include the main header: 12 | 13 | ```cpp 14 | #include "hiberlite.h" 15 | ``` 16 | 17 | ## Features 18 | 19 | Key features of Hiberlite are: 20 | - Boost.Serialization like API 21 | - no code generators / preprocessors 22 | - support for one-to-many and many-to-many relations 23 | - automatic code generation 24 | - lazy loading 25 | - smart pointers 26 | - no need to inherit from a single base class 27 | 28 | In contrast to most serialization libraries with SQL serializers, C++ objects mapped with 29 | hiberlite behave similar to active record pattern - you are not forced to follow the 30 | "read all your data/modify some small part/write everything back" path. 31 | 32 | For people who need reliable data storage, ACID transactions, simple random-access to their data files, 33 | and don't like coding in SQL. 34 | 35 | ----------------------- 36 | 37 | # Tutorial 38 | 39 | While building a typical RDBMS application developer has to deal with the following tasks: 40 | 41 | 1. Open a database 42 | 2. Create database schema 43 | 3. Populate the tables with data 44 | 4. Read and/or modify that data 45 | 46 | Hiberlite greatly reduces the implementation of each of these tasks. 47 | 48 | ## Creating a database 49 | 50 | Opening a database is as simple as 51 | 52 | ```cpp 53 | hiberlite::Database db; 54 | db.open("sample.db"); 55 | ``` 56 | 57 | Where 58 | 59 | ```cpp 60 | Database::open(std::string filename) 61 | ``` 62 | 63 | opens a sqlite3 file. If it doesn't exist it will be created. 64 | Another option is to have constructor automatically open/create the DB file: 65 | 66 | ```cpp 67 | hiberlite::Database db("sample.db"); 68 | ``` 69 | 70 | 71 | ## Creating database schema 72 | 73 | In C++ You deal with classes and objects. You know what objects You want to store in the database. 74 | And hiberlite will figure out how to store that data. 75 | 76 | 77 | ### Defining data model 78 | 79 | First You must prepare the data classes for use with hiberlite. 80 | Suppose we develop a social-network application. We define a person class as: 81 | 82 | ```cpp 83 | class Person{ 84 | public: 85 | string name; 86 | int age; 87 | vector bio; 88 | }; 89 | ``` 90 | 91 | Now, to let hiberlite know about the internal structure of this class, 92 | we add an access method and an export declaration: 93 | 94 | ```cpp 95 | class Person{ 96 | friend class hiberlite::access; 97 | template 98 | void hibernate(Archive & ar) 99 | { 100 | ar & HIBERLITE_NVP(name); 101 | ar & HIBERLITE_NVP(age); 102 | ar & HIBERLITE_NVP(bio); 103 | } 104 | public: 105 | string name; 106 | double age; 107 | vector bio; 108 | }; 109 | HIBERLITE_EXPORT_CLASS(Person) 110 | ``` 111 | 112 | Inside the **hibernate(Archive & ar)** method we list all the data fields we want to persist in the database. 113 | Macro **HIBERLITE_EXPORT_CLASS(Person)** is invoked to register the class name with Hiberlite. 114 | For now just remember to invoke it once per class in your project. (Placing it in the Person.cpp is a good idea) 115 | 116 | At this point hiberlite is able to map the Person to a database. 117 | 118 | ### Creating tables 119 | 120 | Database schema in hiberlite is simply a set of classes, that are stored in the database. 121 | A programmer defines that set of classes, and hiberlite determines the needed tables and their columns. 122 | 123 | Each instance of Database maintains its own copy of the database schema (set of data classes). To insert a new class to that set, use registerBeanClass template method: 124 | 125 | ```cpp 126 | db.registerBeanClass(); 127 | ``` 128 | 129 | In most applications several classes are stored in one database - so usually You will call **registerBeanClass** several times: 130 | 131 | ```cpp 132 | Database db("gmail2.0.db"); 133 | db.registerBeanClass(); 134 | db.registerBeanClass(); 135 | db.registerBeanClass(); 136 | ``` 137 | 138 | When the classes are registered, Database can create tables to map them: 139 | 140 | ```cpp 141 | db.dropModel(); 142 | db.createModel(); 143 | ``` 144 | 145 | **createModel()** executes several **CREATE TABLE** queries. 146 | **dropModel()** cleans the database - executes **DROP TABLE IF EXISTS** query for each table in the schema. 147 | Besides uninstallers, this method may be used to destroy the old tables (from a probably obsolete scheme) 148 | before calling createModel(). 149 | 150 | ## Saving data 151 | 152 | When the database with proper schema is opened, we can put some Person objects in it: 153 | 154 | ```cpp 155 | Person x; 156 | x.name="Amanda"; 157 | x.age=21; 158 | x.bio.push_back("born 1987"); 159 | hiberlite::bean_ptr p=db.copyBean(x); 160 | x.age=-1; //does NOT change any database record 161 | p->age=22; //does change the database 162 | ``` 163 | 164 | **copyBean(x)** template method creates a copy of its argument and saves it to the database. 165 | It returns a smart pointer - **bean_ptr**. 166 | 167 | **bean_ptr** is inspired by the **boost::shared_ptr**. The main difference is that in addition 168 | to deletion, **bean_ptr** guarantees that the referenced object will be also saved to the database, 169 | when no longer needed. 170 | 171 | An internal primary key is autogenerated for each object in the database. It can be read 172 | with **sqlid_t bean_ptr::get_id()**. 173 | 174 | Another way to create a bean is to use **createBean()** template method: 175 | 176 | ```cpp 177 | hiberlite::bean_ptr p=db.createBean(); 178 | p->name="Amanda"; 179 | p->age=21; 180 | p->bio.push_back("born 1987"); 181 | ``` 182 | 183 | 184 | ## Loading data 185 | 186 | There are several methods to query the database: 187 | 188 | **bean_ptr Database::loadBean(sqlid_t id)** loads the bean with the given id. 189 | 190 | ```cpp 191 | bean_ptr p=db.loadBean(1); 192 | cout << "first person is " << p->name << endl; 193 | ``` 194 | 195 | In this case object itself is not loaded, when bean_ptr is returned. 196 | bean_ptr is a lazy pointer, so the wrapped object will be loaded when first needed. 197 | In this example Person will be loaded later, when we try to access the name field. 198 | 199 | **std::vector< bean_ptr > Database::getAllBeans()** 200 | returns a vector with all the beans of a given class C. 201 | 202 | ```cpp 203 | vector< bean_ptr > v=db.getAllBeans(); 204 | cout << "found " << v.size() << " persons in the database\n"; 205 | ``` 206 | 207 | In this example objects are not loaded at all. 208 | 209 | You can load the same object more than once - all the returned bean_ptr's will point the same bean. 210 | 211 | ## Deleting beans 212 | 213 | To remove an object from the database, call bean_ptr::destroy(): 214 | 215 | ```cpp 216 | bean_ptr p==db.loadBean(1); 217 | p.destroy(); 218 | ``` 219 | 220 | ## Examples 221 | 222 | All the above code is put together in sample.cpp. For more demonstration see the poor-mans unit tests : tests.cpp. 223 | 224 | User-defined class 225 | First we define the class we plan to store in the database: 226 | 227 | ```cpp 228 | class MyClass{ 229 | friend class hiberlite::access; 230 | template 231 | void hibernate(Archive & ar) 232 | { 233 | ar & HIBERLITE_NVP(a); 234 | ar & HIBERLITE_NVP(b); 235 | ar & HIBERLITE_NVP(vs); 236 | } 237 | public: 238 | int a; 239 | double b; 240 | vector vs; 241 | }; 242 | HIBERLITE_EXPORT_CLASS(MyClass) 243 | ``` 244 | 245 | Note the friend declaration and the hibernate(...) template method - these two pieces of code are necessary 246 | for hiberlite to access the internal structure of the user-defined class. 247 | 248 | **HIBERLITE_NVP** is a macro that creates a name-value pair with reference to its argument. 249 | 250 | **HIBERLITE_EXPORT_CLASS()** defines the root table name for the class. More on this later. 251 | 252 | ## How it is stored 253 | 254 | hiberlite will use 2 tables to represent MyClass instances in the database: 255 | 256 | ```cpp 257 | CREATE TABLE MyClass 258 | ( 259 | a INTEGER, 260 | b REAL, 261 | hiberlite_id INTEGER PRIMARY KEY AUTOINCREMENT 262 | ) 263 | CREATE TABLE MyClass_vs_items 264 | ( 265 | hiberlite_entry_indx INTEGER, 266 | hiberlite_id INTEGER PRIMARY KEY AUTOINCREMENT, 267 | hiberlite_parent_id INTEGER, 268 | item TEXT 269 | ) 270 | ``` 271 | 272 | Table MyClass is the root table for MyClass. It will contain one row per object. Columns a and b store values of the corresponding int and double fields. 273 | 274 | HIBERLITE_EXPORT_CLASS(MyClass) macro simply declares that instances of MyClass must be stored int the MyClass root table and its subtables. 275 | 276 | MyClass_vs_items table is the "subtable" of MyClass. It is used to store elements of the vs vector: hiberlite_parent_id references the hiberlite_id of the root table, hiberlite_entry_indx - is the zero-index of the string element of the vector, and item is the value of that element. 277 | 278 | Objects in the database are called beans. To add a new bean to the database we call 279 | 280 | ```cpp 281 | hiberlite::bean_ptr p=db.copyBean(x); 282 | ``` 283 | 284 | **copyBean()** creates an internal copy of its argument (by invoking copy-constructor **new MyClass(x)**), 285 | saves it in the database and returns a **bean_ptr**, pointing to that copy. 286 | **bean_ptr** is a smart-pointer, it will perform reference-counting and care about saving and destroying your 287 | bean when it is no longer in use. 288 | But the object will not be lost - it is stored in the database. 289 | The only way to remove it is to call **bean_ptr::destroy()**. 290 | 291 | There are two other ways to create a bean in the database: 292 | **bean_ptr Database::createBean()** creates a bean using default constructor and returns a 293 | **bean_ptr Database::manageBean(C& ptr)** takes control over its argument and wraps it in the bean_ptr. 294 | You must not call **delete ptr;** after calling **manageBean(ptr)** - **bean_ptr** will do it when necessary. 295 | 296 | ## Loading data 297 | 298 | Call to 299 | 300 | ```cpp 301 | std::vector< hiberlite::bean_ptr > v=db.getAllBeans(); 302 | ``` 303 | 304 | will return a vector with all objects in the database. 305 | 306 | bean_ptr is a smart pointer, but I forgot to mention that it is also a lazy pointer. 307 | Beans itself are not loaded when with **getAllBeans()** - only their primary keys. 308 | To give user the access to the underlying object, C& bean_ptr::operator->() is overloaded. 309 | The object will be created and fetched from the database with the first use of operator->. 310 | 311 | ## User-defined primitive types 312 | 313 | Sometimes, numbers or strings are not suitable representations for fields of objects. In that case it is possible to extend `hiberlite`'s conversion mechanism to support types other than the ones supported. For example: 314 | 315 | given an enum: 316 | 317 | ```cpp 318 | enum class Status { 319 | OK, 320 | NOT_OK 321 | }; 322 | ``` 323 | 324 | the macro `HIBERLITE_NVP` will cause a compile error if a member of that type is used with it. In order to convert the enum to a number and back (conversion safety considerations may apply), it is possible to define custom conversions before defining the data model: 325 | 326 | ```cpp 327 | namespace hiberlite { 328 | template 329 | void hibernate(A& ar, Status& value, const unsigned int) { 330 | ar& db_atom(value); 331 | } 332 | 333 | template <> 334 | inline std::string db_atom::sqliteStorageClass() { 335 | return "INTEGER"; 336 | } 337 | 338 | template <> 339 | template 340 | void db_atom::loadValue(Stmt& res, Arg& arg) { 341 | val = static_cast(res.get_int(arg)); 342 | } 343 | 344 | template <> 345 | inline void db_atom::bindValue(sqlite3_stmt* stmt, int col) { 346 | sqlite3_bind_int(stmt, col, static_cast(val)); 347 | } 348 | } 349 | ``` 350 | 351 | This allows the following to work: 352 | 353 | ```cpp 354 | struct Item { 355 | Status status; 356 | 357 | template 358 | void hibernate(Archive & ar) { 359 | ar & HIBERLITE_NVP(status); 360 | } 361 | }; 362 | ``` 363 | -------------------------------------------------------------------------------- /catch_tests.cpp: -------------------------------------------------------------------------------- 1 | #define CATCH_CONFIG_MAIN 2 | #include "catch.hpp" 3 | #include "hiberlite.h" 4 | using namespace hiberlite; 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | 14 | class B{ 15 | friend class hiberlite::access; 16 | template 17 | void hibernate(Archive & ar) 18 | { 19 | ar & HIBERLITE_NVP(name); 20 | ar & HIBERLITE_NVP(weight); 21 | ar & HIBERLITE_NVP(height); 22 | } 23 | 24 | public: 25 | string name; 26 | double weight; 27 | int height; 28 | }; 29 | 30 | class A{ 31 | friend class hiberlite::access; 32 | template 33 | void hibernate(Archive & ar) 34 | { 35 | ar & HIBERLITE_NVP(seti); 36 | ar & HIBERLITE_NVP(i); 37 | ar & HIBERLITE_NVP(s); 38 | ar & HIBERLITE_NVP(vi); 39 | ar & HIBERLITE_NVP(v); 40 | ar & HIBERLITE_NVP(mm); 41 | } 42 | 43 | public: 44 | int i; 45 | string s; 46 | vector< pair > vi; 47 | set< double > seti; 48 | vector< bean_ptr > v; 49 | map > mm; 50 | }; 51 | 52 | class X{ 53 | friend class hiberlite::access; 54 | template 55 | void hibernate(Archive & ar) 56 | { 57 | ar & HIBERLITE_NVP(seti); 58 | ar & HIBERLITE_NVP(vvi); 59 | ar & HIBERLITE_NVP(mm); 60 | } 61 | public: 62 | set< pair > seti; 63 | vector< vector > vvi; 64 | map< vector, map > mm; 65 | bool operator==(const X& x){ 66 | return seti==x.seti && vvi==x.vvi && mm==x.mm; 67 | } 68 | }; 69 | 70 | HIBERLITE_EXPORT_CLASS(A) 71 | HIBERLITE_EXPORT_CLASS(B) 72 | HIBERLITE_EXPORT_CLASS(X) 73 | 74 | TEST_CASE() { 75 | Database db("catch_test.db"); 76 | 77 | CHECK_NOTHROW( db.registerBeanClass() ); 78 | CHECK_NOTHROW( db.registerBeanClass() ); 79 | 80 | vector msg=db.checkModel(); 81 | for(size_t ci=0;ci ptr=db.copyBean(x); 107 | if (!ptr.get_object()) 108 | CAPTURE(x.name); 109 | CHECK( ptr.get_object() ); 110 | obj.v.push_back(ptr); 111 | } 112 | while(obj.v.size()){ 113 | obj.v[0].destroy(); 114 | obj.v.erase(obj.v.begin()); 115 | } 116 | bean_ptr a=db.copyBean(obj); 117 | if(a.get_id()%10==0) 118 | CAPTURE(std::string("save obj with name ")+(*a).s); 119 | CHECK( (a.get_id()%10) != 0 ); 120 | } 121 | } 122 | 123 | TEST_CASE() { 124 | Database db("catch_test.db"); 125 | // we will not create or drop tables, so model initialization 126 | // is not necessary 127 | // db.registerBeanClass(); 128 | // db.registerBeanClass(); 129 | 130 | Database otherdb("catch_copy.db"); 131 | CHECK_NOTHROW( otherdb.registerBeanClass() ); 132 | CHECK_NOTHROW( otherdb.registerBeanClass() ); 133 | 134 | CHECK_NOTHROW( otherdb.dropModel() ); 135 | CHECK_NOTHROW( otherdb.createModel() ); 136 | 137 | bean_ptr be=db.loadBean(1); 138 | CHECK( be.get_object() ); 139 | A obj2=*be; 140 | bean_ptr a2=otherdb.copyBean(obj2); 141 | if (!a2.get_object()) 142 | CAPTURE(std::string("load obj with name ") + (*a2).s); 143 | CHECK( a2.get_object() ); 144 | } 145 | 146 | TEST_CASE() { 147 | X x; 148 | x.vvi.resize(5); 149 | map< vector, map > mm; 150 | vector randstr; 151 | unsigned int NS=30; 152 | for(unsigned int i=0;i vs; 160 | for(unsigned int i=0;i<5;i++) 161 | vs.push_back( randstr[(17+7*i)%NS] ); 162 | for(unsigned int i=0;i<10;i++) 163 | x.mm[vs][ randstr[(19*i)%NS] ]=randstr[(23*i)%NS]; 164 | } 165 | 166 | { 167 | Database db("catch_t3.db"); 168 | CHECK_NOTHROW( db.registerBeanClass() ); 169 | CHECK_NOTHROW( db.dropModel() ); 170 | CHECK_NOTHROW( db.createModel() ); 171 | CHECK_NOTHROW( db.copyBean(x) ); 172 | } 173 | 174 | { 175 | Database db("catch_t3.db"); 176 | CHECK_NOTHROW( db.registerBeanClass() ); 177 | bean_ptr xptr=db.loadBean(1); 178 | CAPTURE( "load failed" ); 179 | CHECK( (*xptr)==x ); 180 | } 181 | 182 | } 183 | 184 | struct ULL { 185 | unsigned long long ull; 186 | 187 | template 188 | void hibernate(Archive & ar) 189 | { 190 | ar & HIBERLITE_NVP(ull); 191 | } 192 | }; 193 | 194 | HIBERLITE_EXPORT_CLASS(ULL); 195 | 196 | TEST_CASE("unsigned long long should survive serialization") { 197 | hiberlite::Database db("ull.db"); 198 | db.registerBeanClass(); 199 | db.dropModel(); 200 | db.createModel(); 201 | 202 | ULL max = { numeric_limits::max() }; 203 | // struct to avoid compiler warning C4307 204 | REQUIRE((max.ull + 1) == 0); 205 | bean_ptr max_old = db.copyBean(max); 206 | bean_ptr max_new = db.loadBean(max_old.get_id()); 207 | CHECK(max_new->ull == max.ull); 208 | } 209 | 210 | 211 | enum class Gender { 212 | male, female 213 | }; 214 | 215 | struct Person { 216 | 217 | Gender gender_; 218 | 219 | template 220 | void hibernate(Archive & ar) { 221 | ar & HIBERLITE_NVP(gender_); 222 | } 223 | }; 224 | 225 | namespace hiberlite { 226 | template void hibernate(A& ar, Gender& value, const unsigned int) 227 | { 228 | ar & db_atom(value); 229 | } 230 | 231 | template<> inline std::string db_atom::sqliteStorageClass() 232 | { 233 | return "INTEGER"; 234 | } 235 | 236 | template<> template void db_atom::loadValue(Stmt& res, Arg& arg) 237 | { 238 | val = static_cast(res.get_int(arg)); 239 | } 240 | 241 | template<> inline void db_atom::bindValue(sqlite3_stmt* stmt, int col) 242 | { 243 | sqlite3_bind_int(stmt, col, static_cast(val)); 244 | } 245 | } 246 | 247 | HIBERLITE_EXPORT_CLASS(Person); 248 | 249 | SCENARIO("custom enum type conversions") { 250 | GIVEN("a db") { 251 | hiberlite::Database db("custom.db"); 252 | { 253 | WHEN("I add register a type with an enum field") { 254 | db.registerBeanClass(); 255 | db.dropModel(); 256 | db.createModel(); 257 | 258 | AND_WHEN("I save some entries in the db") { 259 | Person m = { Gender::male }; 260 | Person f = { Gender::female }; 261 | 262 | db.copyBean(m); 263 | db.copyBean(f); 264 | 265 | THEN("The db contains the entries with the correct enum values") { 266 | auto ppl = db.getAllBeans(); 267 | CHECK(ppl.size() == 2); 268 | CHECK(ppl[0]->gender_ == Gender::male); 269 | CHECK(ppl[1]->gender_ == Gender::female); 270 | } 271 | } 272 | } 273 | } 274 | } 275 | } 276 | -------------------------------------------------------------------------------- /include/BeanLoader.h: -------------------------------------------------------------------------------- 1 | #ifndef BeanLoader_H 2 | #define BeanLoader_H 3 | 4 | namespace hiberlite{ 5 | 6 | class LoadBean { 7 | public: 8 | template 9 | inline void notifyInitWalk(AV& av); 10 | 11 | template 12 | inline void notifyDoneWalk(AV& av); 13 | 14 | template 15 | inline void act(AV& av, db_atom atom){ 16 | int col_indx=locateCol(av.getScope().prefix()); 17 | atom.loadValue(stmt.top().first, col_indx); 18 | } 19 | 20 | template 21 | inline void act(AV& av, collection_nvp nvp ); 22 | 23 | protected: 24 | std::stack< std::pair > stmt; 25 | 26 | inline int locateCol(std::string name){ 27 | SQLiteSelect& sel=stmt.top().first; 28 | unsigned int n=sel.column_count(); 29 | for(unsigned int i=0;i 37 | { 38 | public: 39 | BeanLoader(); 40 | 41 | template 42 | C* loadBean(bean_key k); 43 | 44 | protected: 45 | LoadBean actor; 46 | 47 | private: 48 | }; 49 | 50 | } //namespace hiberlite 51 | 52 | #endif // BeanLoader_H 53 | -------------------------------------------------------------------------------- /include/BeanLoader_impl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BeanLoader_IMPL_HPP_INCLUDED 2 | #define BeanLoader_IMPL_HPP_INCLUDED 3 | 4 | namespace hiberlite{ 5 | 6 | template 7 | void LoadBean::notifyInitWalk(AV& av) 8 | { 9 | while(!stmt.empty()) 10 | stmt.pop(); 11 | 12 | sqlid_t curId=av.getRootId(); 13 | 14 | std::string query="SELECT * FROM "+av.getScope().table() 15 | +" WHERE "+HIBERLITE_PRIMARY_KEY_COLUMN+"="+Transformer::toSQLiteValue(curId)+";"; 16 | 17 | SQLiteSelect sel(av.getConnection(), query); 18 | if(!sel.step()) 19 | throw database_error("Id " + std::to_string(curId) + " not found in table " + av.getScope().table()); 20 | stmt.push( std::make_pair(sel,curId) ); 21 | } 22 | 23 | template 24 | void LoadBean::notifyDoneWalk(AV& av) 25 | { 26 | while(!stmt.empty()) 27 | stmt.pop(); 28 | } 29 | 30 | template 31 | void LoadBean::act(AV& av, collection_nvp nvp ) 32 | { 33 | av.diveTable(nvp.name); 34 | std::string tab=av.getScope().table(); 35 | std::vector children=Database::dbSelectChildIds(av.getConnection(), tab, stmt.top().second); 36 | nvp.stream.startLoadFromDb(); 37 | 38 | for(size_t i=0;i(0)); 41 | 42 | std::string query="SELECT * FROM "+tab 43 | +" WHERE "+HIBERLITE_PRIMARY_KEY_COLUMN+"="+Transformer::toSQLiteValue(children[i])+";"; 44 | SQLiteSelect sel(av.getConnection(), query); 45 | if(!sel.step()) 46 | throw database_error("id not found in the database"); 47 | stmt.push( std::make_pair(sel,children[i]) ); 48 | 49 | sql_nvp el("item", *entry); 50 | av & el; 51 | 52 | stmt.pop(); 53 | nvp.stream.putNext(*entry); 54 | destroy(*this, entry, static_cast(0)); 55 | } 56 | av.pop(); 57 | } 58 | 59 | template 60 | C* BeanLoader::loadBean(bean_key key) 61 | { 62 | C* bean; 63 | construct(*this, &bean, static_cast(0)); 64 | startWalk(*bean, key); 65 | return bean; 66 | } 67 | 68 | } //namespace hiberlite 69 | 70 | #endif // BEANUPDATER_IMPL_HPP_INCLUDED 71 | -------------------------------------------------------------------------------- /include/BeanUpdater.h: -------------------------------------------------------------------------------- 1 | #ifndef BEANUPDATER_H 2 | #define BEANUPDATER_H 3 | 4 | #include 5 | #include 6 | 7 | namespace hiberlite{ 8 | 9 | struct RowScope{ 10 | static const int FirstAtom=100; 11 | std::vector atoms; 12 | std::string table; 13 | std::string query; 14 | sqlid_t id; 15 | bool needComma; 16 | template 17 | inline void addAssignment(const std::string name, db_atom& atom); 18 | 19 | void addSimpleAssign(const std::string name, std::string value); 20 | 21 | ~RowScope(); 22 | }; 23 | 24 | class Transformer{ 25 | public: 26 | static std::string toSQLiteValue(const double& val){ 27 | char s[64]; 28 | sprintf(s,"%lf",val); 29 | return s; 30 | } 31 | static std::string toSQLiteValue(const float& val){ 32 | char s[64]; 33 | sprintf(s,"%f",val); 34 | return s; 35 | } 36 | static std::string toSQLiteValue(const long double& val){ 37 | char s[64]; 38 | sprintf(s,"%Lf",val); 39 | return s; 40 | } 41 | 42 | #define HIBERLITE_STRINGIFY_NUM(VALTYPE) \ 43 | static std::string toSQLiteValue(const VALTYPE &val){ \ 44 | char s[64]; \ 45 | char* p=s+63; \ 46 | *(p--)=0; \ 47 | VALTYPE tmp=val; \ 48 | bool needmin=0; \ 49 | if(tmp<(VALTYPE)0) \ 50 | needmin=1,tmp*=-1; \ 51 | do{ \ 52 | *(p--)='0' + (tmp%10); \ 53 | tmp/=10; \ 54 | }while(tmp); \ 55 | if(needmin) *(p--)='-'; \ 56 | return p+1; \ 57 | } 58 | 59 | #define HIBERLITE_STRINGIFY_UNSIGNED_NUM(VALTYPE) \ 60 | static std::string toSQLiteValue(const VALTYPE &val){ \ 61 | char s[64]; \ 62 | char* p=s+63; \ 63 | *(p--)=0; \ 64 | VALTYPE tmp=val; \ 65 | do{ \ 66 | *(p--)='0' + (tmp%10); \ 67 | tmp/=10; \ 68 | }while(tmp); \ 69 | return p+1; \ 70 | } 71 | 72 | HIBERLITE_STRINGIFY_NUM(int) 73 | HIBERLITE_STRINGIFY_UNSIGNED_NUM(unsigned int) 74 | HIBERLITE_STRINGIFY_NUM(char) 75 | //HIBERLITE_STRINGIFY_NUM(unsigned char) 76 | HIBERLITE_STRINGIFY_NUM(long long int) 77 | HIBERLITE_STRINGIFY_UNSIGNED_NUM(unsigned long long int) 78 | #undef HIBERLITE_STRINGIFY_NUM 79 | 80 | static std::string toSQLiteValue(const unsigned char &val){ 81 | char s[64]; 82 | int i=63; 83 | s[i--]=0; 84 | unsigned char tmp=val; 85 | do{ 86 | s[i--]='0' + (tmp%10); 87 | tmp/=10; 88 | }while(tmp); 89 | return s+i+1; 90 | } 91 | 92 | 93 | static std::string toSQLiteValue(const char* val){ 94 | size_t n=strlen(val); 95 | char* s=new char[4+2*n]; 96 | int x=sprintf(s,"X'"); 97 | 98 | for(unsigned int i=0;i 120 | inline void notifyInitWalk(AV& av); 121 | 122 | template 123 | inline void notifyDoneWalk(AV& av); 124 | 125 | template 126 | inline void act(AV& av, db_atom atom){ 127 | curRow()->addAssignment(av.getScope().prefix(), atom); 128 | } 129 | 130 | template 131 | inline void act(AV& av, collection_nvp nvp ); 132 | 133 | protected: 134 | std::stack< shared_res > rowStack; 135 | RowScope* curRow(); 136 | 137 | void startRow(std::string table, sqlid_t rowid, sqlid_t parent_id, sqlid_t index); 138 | void commitRow(shared_connection con, sqlid_t rowid); 139 | }; 140 | 141 | class BeanUpdater : AVisitor 142 | { 143 | public: 144 | BeanUpdater(); 145 | 146 | template 147 | void update(bean_key k, C& bean); 148 | 149 | protected: 150 | UpdateBean actor; 151 | 152 | private: 153 | }; 154 | 155 | } //namespace hiberlite 156 | 157 | #endif // BEANUPDATER_H 158 | -------------------------------------------------------------------------------- /include/BeanUpdater_impl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BEANUPDATER_IMPL_HPP_INCLUDED 2 | #define BEANUPDATER_IMPL_HPP_INCLUDED 3 | 4 | namespace hiberlite{ 5 | 6 | template 7 | inline void RowScope::addAssignment(const std::string name, db_atom& atom){ 8 | int id=FirstAtom+static_cast(atoms.size()); 9 | 10 | addSimpleAssign(name, "?"+Transformer::toSQLiteValue(id) ); 11 | 12 | db_atom* x=new db_atom(atom); 13 | atoms.push_back(x); 14 | } 15 | 16 | template 17 | void UpdateBean::notifyInitWalk(AV& av) 18 | { 19 | startRow(av.getScope().table(), av.getRootId(), Database::NULL_ID,0); 20 | } 21 | 22 | template 23 | void UpdateBean::notifyDoneWalk(AV& av) 24 | { 25 | commitRow(av.getConnection(), av.getRootId()); 26 | } 27 | 28 | template 29 | void UpdateBean::act(AV& av, collection_nvp nvp ){ 30 | 31 | sqlid_t index=0; 32 | S& stream=nvp.stream; 33 | 34 | av.diveTable(nvp.name); 35 | std::string tab=av.getScope().table(); 36 | while(!stream.done()){ 37 | E& el=stream.getNext(); 38 | sqlid_t entry_id=Database::allocId(av.getConnection(), tab); 39 | 40 | startRow(tab,entry_id, curRow()->id,index); 41 | sql_nvp el_nvp("item",el); 42 | av & el_nvp; 43 | commitRow(av.getConnection(), entry_id); 44 | index++; 45 | } 46 | av.pop(); 47 | } 48 | 49 | template 50 | void BeanUpdater::update(bean_key key, C& bean) 51 | { 52 | startWalk( bean, key ); 53 | } 54 | 55 | } //namespace hiberlite 56 | 57 | #endif // BEANUPDATER_IMPL_HPP_INCLUDED 58 | -------------------------------------------------------------------------------- /include/ChildKiller.h: -------------------------------------------------------------------------------- 1 | #ifndef CHILDKILLER_H 2 | #define CHILDKILLER_H 3 | 4 | namespace hiberlite{ 5 | 6 | class KillChildren{ 7 | public: 8 | template 9 | inline void notifyInitWalk(AV& av); 10 | 11 | template 12 | inline void notifyDoneWalk(AV& av); 13 | 14 | template 15 | inline void act(AV& av, db_atom nvp ){} 16 | 17 | template 18 | inline void act(AV& av, collection_nvp nvp ); 19 | 20 | protected: 21 | std::stack rowId; 22 | }; 23 | 24 | class ChildKiller : AVisitor 25 | { 26 | public: 27 | ChildKiller(); 28 | 29 | template 30 | void killChildren(bean_key k, C& bean); 31 | 32 | protected: 33 | KillChildren actor; 34 | 35 | private: 36 | }; 37 | 38 | } //namespace hiberlite 39 | 40 | #endif // CHILDKILLER_H 41 | -------------------------------------------------------------------------------- /include/ChildKiller_impl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CHILDKILLER_IMPL_HPP_INCLUDED 2 | #define CHILDKILLER_IMPL_HPP_INCLUDED 3 | 4 | namespace hiberlite{ 5 | 6 | template 7 | void KillChildren::notifyInitWalk(AV& av) 8 | { 9 | rowId=std::stack(); 10 | rowId.push(av.getRootId()); 11 | } 12 | 13 | template 14 | void KillChildren::notifyDoneWalk(AV& av) 15 | { 16 | } 17 | 18 | template 19 | void KillChildren::act(AV& av, collection_nvp nvp ) 20 | { 21 | av.diveTable(nvp.name); 22 | std::string tab=av.getScope().table(); 23 | std::vector children=Database::dbSelectChildIds(av.getConnection(), tab, rowId.top()); 24 | for(size_t i=0;i(0)); 27 | rowId.push(children[i]); 28 | sql_nvp el("item",*entry); 29 | av & el; 30 | rowId.pop(); 31 | destroy(*this, entry, static_cast(0)); 32 | } 33 | av.pop(); 34 | 35 | Database::dbDeleteRows(av.getConnection(),tab,HIBERLITE_PARENTID_COLUMN,rowId.top()); 36 | } 37 | 38 | template 39 | void ChildKiller::killChildren(bean_key key, C& bean) 40 | { 41 | startWalk(bean, key); 42 | } 43 | 44 | } //namespace hiberlite 45 | 46 | 47 | #endif // BEANUPDATER_IMPL_HPP_INCLUDED 48 | -------------------------------------------------------------------------------- /include/CppModel.h: -------------------------------------------------------------------------------- 1 | #ifndef CPPMODEL_H 2 | #define CPPMODEL_H 3 | 4 | namespace hiberlite{ 5 | 6 | class Scope{ 7 | public: 8 | std::string _table, _prefix; 9 | int prefix_depth; 10 | 11 | inline Scope(std::string t, std::string p): _table(t) 12 | , _prefix(p) 13 | ,prefix_depth(0) 14 | {} 15 | inline Scope() : prefix_depth(0) {} 16 | 17 | inline std::string table() { return _table; } 18 | inline std::string prefix() { return _prefix; } 19 | 20 | std::string name_column(std::string name); 21 | std::string full(); 22 | }; 23 | 24 | class Column{ 25 | public: 26 | inline Column(std::string _n="", std::string _s="") : name(_n), storage_type(_s) {} 27 | std::string name; 28 | std::string storage_type; 29 | }; 30 | 31 | class Table{ 32 | public: 33 | Table(); 34 | std::string name; 35 | std::map columns; 36 | void add(Column c); 37 | bool contains(std::string colname); 38 | }; 39 | 40 | class Model : public std::map { 41 | public: 42 | void add(Table t); 43 | }; 44 | 45 | }//namespace hiberlite 46 | 47 | #endif // CPPMODEL_H 48 | -------------------------------------------------------------------------------- /include/Database.h: -------------------------------------------------------------------------------- 1 | #ifndef DATABASE_H 2 | #define DATABASE_H 3 | 4 | namespace hiberlite{ 5 | 6 | class ModelExtractor; 7 | class UpdateBean; 8 | 9 | class Database : noncopyable 10 | { 11 | protected: 12 | friend class UpdateBean; 13 | friend class KillChildren; 14 | friend class LoadBean; 15 | 16 | template 17 | friend class real_bean; 18 | 19 | ModelExtractor* mx; 20 | 21 | template 22 | static void dbDelete(bean_key key, C& bean); 23 | 24 | template 25 | static void dbUpdate(bean_key key, C& bean); 26 | 27 | template 28 | static C* dbLoad(bean_key key); 29 | 30 | static sqlid_t allocId(shared_connection c, std::string table); 31 | sqlid_t allocId(std::string table); 32 | 33 | static void dbExecQuery(shared_connection con, std::string query); 34 | void dbExecQuery(std::string query); 35 | 36 | static std::vector dbSelectIds(shared_connection con, const std::string table, 37 | const std::string condition, const std::string orderBy); 38 | 39 | static std::vector dbSelectChildIds(shared_connection con, std::string table, sqlid_t parent); 40 | inline std::vector dbSelectChildIds(std::string table, sqlid_t parent); 41 | 42 | shared_connection con; 43 | 44 | template 45 | static void dbDeleteRows( shared_connection con, std::string table, std::string column, C value ); 46 | 47 | public: 48 | static const sqlid_t NULL_ID=-1; 49 | 50 | template 51 | static std::string getClassName(); 52 | 53 | Database(); 54 | Database(std::string fname); 55 | virtual ~Database(); 56 | 57 | void open(std::string fname); 58 | void close(); 59 | 60 | template 61 | inline void registerBeanClass(); 62 | 63 | Model getModel(); 64 | inline shared_connection getConnection() { return con; } 65 | 66 | std::vector checkModel(); 67 | void dropModel(); 68 | void createModel(); 69 | 70 | template 71 | bean_ptr loadBean(sqlid_t objId); 72 | 73 | template 74 | std::vector getBeanIds(); 75 | 76 | template 77 | std::vector< bean_ptr > getAllBeans(); 78 | 79 | template 80 | bean_ptr copyBean(const C& c); 81 | 82 | template 83 | bean_ptr createBean(); 84 | 85 | template 86 | bean_ptr manageBean(C* ptr); 87 | }; 88 | 89 | } //namespace hiberlite; 90 | 91 | 92 | #endif // DATABASE_H 93 | -------------------------------------------------------------------------------- /include/Database_tmpl_impl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATABASE_TMPL_IMPL_HPP_INCLUDED 2 | #define DATABASE_TMPL_IMPL_HPP_INCLUDED 3 | 4 | namespace hiberlite{ 5 | 6 | template 7 | void Database::dbDelete(bean_key key, C& bean) 8 | { 9 | try{ 10 | dbExecQuery(key.con,"ROLLBACK TRANSACTION;"); 11 | }catch(...){} 12 | dbExecQuery(key.con,"BEGIN TRANSACTION;"); 13 | 14 | ChildKiller ck; 15 | ck.killChildren(key,bean); 16 | dbDeleteRows(key.con, Database::getClassName(), HIBERLITE_PRIMARY_KEY_COLUMN, key.id); 17 | 18 | dbExecQuery(key.con,"COMMIT TRANSACTION;"); 19 | } 20 | 21 | template 22 | void Database::dbDeleteRows(shared_connection con, std::string table, std::string column, C value ) 23 | { 24 | std::string query="DELETE FROM "+table 25 | + " WHERE "+column+"="+Transformer::toSQLiteValue(value)+";"; 26 | dbExecQuery(con,query); 27 | } 28 | 29 | 30 | template 31 | void Database::dbUpdate(bean_key key, C& bean) 32 | { 33 | try{ 34 | dbExecQuery(key.con,"ROLLBACK TRANSACTION;"); 35 | }catch(...){} 36 | dbExecQuery(key.con,"BEGIN TRANSACTION;"); 37 | 38 | ChildKiller ck; 39 | ck.killChildren(key,bean); 40 | BeanUpdater u; 41 | u.update(key, bean); 42 | 43 | dbExecQuery(key.con,"COMMIT TRANSACTION;"); 44 | } 45 | 46 | template 47 | C* Database::dbLoad(bean_key key) 48 | { 49 | BeanLoader bl; 50 | return bl.loadBean(key); 51 | } 52 | 53 | template 54 | inline bean_ptr Database::createBean() 55 | { 56 | C* obj=new C(); 57 | return manageBean(obj); 58 | } 59 | 60 | template 61 | bean_ptr Database::copyBean(const C& c) 62 | { 63 | return manageBean( new C(c) ); 64 | } 65 | 66 | template 67 | inline bean_ptr Database::manageBean(C* ptr) 68 | { 69 | sqlid_t id=allocId( Database::getClassName() ); 70 | bean_key key(con,id); 71 | dbUpdate(key,*ptr); 72 | return Registry::createBeanPtr(key,ptr); 73 | } 74 | 75 | template 76 | inline bean_ptr Database::loadBean(sqlid_t id) 77 | { 78 | return Registry::get( bean_key(con,id) ); 79 | } 80 | 81 | template 82 | std::vector Database::getBeanIds() 83 | { 84 | return dbSelectIds(con, getClassName(),"", "" ); 85 | } 86 | 87 | template 88 | std::vector< bean_ptr > Database::getAllBeans() 89 | { 90 | std::vector ids=getBeanIds(); 91 | size_t N=ids.size(); 92 | std::vector< bean_ptr > ans; 93 | ans.reserve(N); 94 | for(size_t i=0;i(ids[i]) ); 96 | return ans; 97 | } 98 | 99 | 100 | template 101 | inline void Database::registerBeanClass() 102 | { 103 | if(!mx) 104 | mx=new ModelExtractor(); 105 | std::string classname=Database::getClassName(); 106 | 107 | mx->extractModel(con); 108 | } 109 | 110 | } //namespace hiberlite 111 | 112 | #endif // DATABASE_TMPL_IMPL_HPP_INCLUDED 113 | -------------------------------------------------------------------------------- /include/ModelExtractor.h: -------------------------------------------------------------------------------- 1 | #ifndef MODELEXTRACTOR_H 2 | #define MODELEXTRACTOR_H 3 | 4 | namespace hiberlite{ 5 | 6 | class ExtractModel{ 7 | public: 8 | Model getModel(); 9 | 10 | template 11 | inline void notifyInitWalk(AV& av){ 12 | model[av.getScope().table()].name=av.getScope().table(); 13 | } 14 | 15 | template 16 | inline void notifyDoneWalk(AV& av){} 17 | 18 | template 19 | inline void act(AV& av, db_atom atom) { 20 | putColumn(av, atom.sqliteStorageClass()); 21 | } 22 | 23 | template 24 | inline void act(AV& av, collection_nvp nvp ); 25 | 26 | protected: 27 | template 28 | inline void putColumn(AV& av, std::string storage) 29 | { 30 | Scope scope=av.getScope(); 31 | putNamedColumn(scope.table(), scope.prefix(), storage); 32 | } 33 | 34 | inline void putNamedColumn(std::string table, std::string colname, std::string storClass){ 35 | model[ table ].name=table; 36 | if( model[table].contains( colname ) ) 37 | throw std::logic_error(colname+": column name is in use"); 38 | model[ table ].add( Column(colname,storClass) ); 39 | } 40 | 41 | Model model; 42 | }; 43 | 44 | class ModelExtractor : AVisitor{ 45 | public: 46 | ModelExtractor(); 47 | template 48 | void extractModel(shared_connection _con); 49 | Model getModel(); 50 | 51 | protected: 52 | ExtractModel actor; 53 | }; 54 | 55 | } //namespace hiberlite 56 | 57 | #endif // MODELEXTRACTOR_H 58 | -------------------------------------------------------------------------------- /include/ModelExtractor_impl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MODELEXTRACTOR_IMPL_HPP_INCLUDED 2 | #define MODELEXTRACTOR_IMPL_HPP_INCLUDED 3 | 4 | namespace hiberlite{ 5 | 6 | template 7 | void ExtractModel::act(AV& av, collection_nvp nvp ) 8 | { 9 | E* entry; 10 | construct(av, &entry, static_cast(0)); 11 | av.diveTable(nvp.name); 12 | 13 | putNamedColumn(av.getScope().table(), HIBERLITE_PARENTID_COLUMN, HIBERLITE_ID_STORAGE_CLASS); 14 | putNamedColumn(av.getScope().table(), HIBERLITE_ENTRY_INDEX_COLUMN, HIBERLITE_ID_STORAGE_CLASS); 15 | 16 | sql_nvp el("item",*entry); 17 | av & el; 18 | av.pop(); 19 | destroy(*this, entry, static_cast(0)); 20 | } 21 | 22 | template 23 | void ModelExtractor::extractModel(shared_connection _con) 24 | { 25 | C* bean; 26 | construct(*this, &bean, static_cast(0)); 27 | bean_key key(_con, Database::NULL_ID); 28 | startWalk(*bean, key); 29 | destroy(*this, bean, static_cast(0)); 30 | } 31 | 32 | } //namespace hiberlite 33 | 34 | #endif // MODELEXTRACTOR_IMPL_HPP_INCLUDED 35 | -------------------------------------------------------------------------------- /include/Registry.h: -------------------------------------------------------------------------------- 1 | #ifndef REGISTRY_H_INCLUDED 2 | #define REGISTRY_H_INCLUDED 3 | 4 | namespace hiberlite{ 5 | 6 | class Database; 7 | 8 | template class bean_ptr; 9 | template class Registry; 10 | template class real_bean; 11 | 12 | template 13 | class rb_pair : public shared_cnt_obj_pair< real_bean > { 14 | protected: 15 | friend class Registry; 16 | 17 | inline rb_pair(real_bean* rbean); 18 | 19 | public: 20 | inline bean_key get_key(); 21 | inline virtual ~rb_pair(); 22 | }; 23 | 24 | 25 | template 26 | class Registry{ 27 | protected: 28 | friend class rb_pair; 29 | 30 | static std::map* > rbpairs; 31 | 32 | static void notifyRBDies(rb_pair* r); 33 | 34 | public: 35 | static bean_ptr get(const bean_key key); 36 | static bool has(const bean_key key); 37 | 38 | static bean_ptr createBeanPtr(bean_key key, C* obj); 39 | }; 40 | 41 | template 42 | std::map< bean_key, rb_pair* > Registry::rbpairs; 43 | 44 | } //namespace hiberlite 45 | 46 | #endif // REGISTRY_H_INCLUDED 47 | -------------------------------------------------------------------------------- /include/Registry_impl.hpp: -------------------------------------------------------------------------------- 1 | namespace hiberlite{ 2 | 3 | template 4 | rb_pair::~rb_pair() 5 | { 6 | Registry::notifyRBDies(this); 7 | } 8 | 9 | template 10 | rb_pair::rb_pair(real_bean* rbean) : shared_cnt_obj_pair< real_bean >(rbean) 11 | { 12 | } 13 | 14 | template 15 | bean_key rb_pair::get_key() 16 | { 17 | return shared_cnt_obj_pair< real_bean >::res->get_key(); 18 | } 19 | 20 | template 21 | bean_ptr Registry::createBeanPtr(bean_key key, C* obj) 22 | { 23 | if(key.id==Database::NULL_ID) 24 | return bean_ptr(key,NULL); 25 | 26 | real_bean* rb=new real_bean(key,obj); 27 | rb_pair* para=new rb_pair(rb); 28 | 29 | if( rbpairs.find(key)!=rbpairs.end() ) 30 | throw std::logic_error("bean already exists"); 31 | 32 | rbpairs[key]=para; 33 | 34 | bean_ptr ans(key, para); 35 | return ans; 36 | } 37 | 38 | template 39 | bean_ptr Registry::get(const bean_key key) 40 | { 41 | typename std::map* >::iterator it; 42 | it=rbpairs.find(key); 43 | if(it==rbpairs.end()) 44 | return createBeanPtr(key,NULL); 45 | else 46 | return bean_ptr(key, it->second); 47 | } 48 | 49 | template 50 | bool Registry::has(const bean_key key) 51 | { 52 | return rbpairs.find(key)!=rbpairs.end(); 53 | } 54 | 55 | template 56 | void Registry::notifyRBDies(rb_pair* r){ 57 | rbpairs.erase(r->get_key()); 58 | } 59 | 60 | } // namespace hiberlite 61 | -------------------------------------------------------------------------------- /include/SQLiteStmt.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLITESTMT_H 2 | #define SQLITESTMT_H 3 | 4 | namespace hiberlite{ 5 | 6 | class statement_ptr{ 7 | public: 8 | inline statement_ptr(sqlite3_stmt* st) : obj(st) {} 9 | inline ~statement_ptr() { sqlite3_finalize(obj); } 10 | 11 | sqlite3_stmt* get_stmt() { return obj; } 12 | private: 13 | sqlite3_stmt* obj; 14 | 15 | inline statement_ptr(const statement_ptr& st); 16 | inline statement_ptr& operator=(const statement_ptr& st); 17 | }; 18 | 19 | typedef shared_res shared_stmt; 20 | 21 | class SQLiteSelect 22 | { 23 | public: 24 | SQLiteSelect(shared_connection con, std::string query); 25 | 26 | bool step(); 27 | 28 | virtual ~SQLiteSelect(); 29 | 30 | const void* get_blob(int iCol); 31 | int get_bytes(int iCol); 32 | double get_double(int iCol); 33 | int get_int(int iCol); 34 | sqlid_t get_int64(int iCol); 35 | const unsigned char *get_text(int iCol); 36 | int get_type(int iCol); 37 | int column_count(); 38 | std::string get_name(int N); 39 | 40 | protected: 41 | bool active; 42 | shared_stmt statement; 43 | shared_connection con; 44 | private: 45 | }; 46 | 47 | } //namespace hiberlite 48 | 49 | #endif // SQLITESTMT_H 50 | -------------------------------------------------------------------------------- /include/UpdateVisitor_tmpl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef INSERVISITOR_TMPL_HPP_INCLUDED 2 | #define INSERVISITOR_TMPL_HPP_INCLUDED 3 | 4 | namespace hiberlite{ 5 | 6 | } //namespace hiberlite 7 | 8 | 9 | #endif // INSERVISITOR_TMPL_HPP_INCLUDED 10 | -------------------------------------------------------------------------------- /include/Visitor.h: -------------------------------------------------------------------------------- 1 | #ifndef VISITOR_H 2 | #define VISITOR_H 3 | 4 | #include 5 | 6 | namespace hiberlite{ 7 | 8 | class access{ 9 | public: 10 | template 11 | static void hibernate(A& a, C& c) { 12 | c.hibernate(a); 13 | } 14 | 15 | template 16 | static void construct(A& /*a*/, C** c) 17 | { 18 | *c=new C(); 19 | } 20 | 21 | template 22 | static void destroy(A& /*a*/, C* c) 23 | { 24 | delete c; 25 | } 26 | }; 27 | 28 | template 29 | void hibernate(A& a, C& c, const long unsigned int bogus) 30 | { 31 | access::hibernate(a,c); 32 | } 33 | 34 | template 35 | void construct(A& a, C** c, const long unsigned int bogus) 36 | { 37 | access::construct(a,c); 38 | } 39 | 40 | template 41 | void destroy(A& a, C* c, const long unsigned int bogus) 42 | { 43 | access::destroy(a,c); 44 | } 45 | 46 | /* 47 | class Actor{ 48 | public: 49 | template 50 | void act(Vis* vis, collection_nvp nvp); 51 | 52 | template 53 | void act(Vis* vis, db_atom atom); 54 | 55 | template 56 | void notifyInitWalk(AV& av); 57 | 58 | template 59 | void notifyDoneWalk(AV& av); 60 | }; 61 | */ 62 | 63 | template 64 | class AVisitor{ 65 | public: 66 | bool is_loading(); 67 | bool is_saving(); 68 | bool is_model(); 69 | bool is_deleting(); 70 | 71 | AVisitor(C* _actor, int _purp); 72 | ~AVisitor(); 73 | shared_connection getConnection(); 74 | sqlid_t getRootId(); 75 | inline Scope getScope() { return scope; } 76 | 77 | template 78 | void startWalk(Y& obj, bean_key _k); 79 | 80 | template 81 | void walk(Y& obj); 82 | 83 | template 84 | AVisitor& operator&(sql_nvp nvp); 85 | 86 | template 87 | AVisitor& operator&(collection_nvp nvp); 88 | 89 | template 90 | AVisitor& operator&(db_atom atom); 91 | 92 | void divePrefix(std::string name); 93 | 94 | void diveTable(std::string name); 95 | 96 | void pop(); 97 | 98 | static const int LOADING =1; 99 | static const int SAVING =2; 100 | static const int MODEL =3; 101 | static const int DELETING =4; 102 | protected: 103 | C* actor; 104 | int purpose; 105 | 106 | void popScope(); 107 | void pushAndSubTable(std::string name); 108 | void pushAndSubPrefix(std::string prefix); 109 | 110 | std::stack stack; 111 | Scope scope; 112 | 113 | bean_key rootKey; 114 | }; 115 | 116 | class DropChildren; 117 | class UpdateBean; 118 | class BeanUpdater; 119 | 120 | class ExtractModel; 121 | class ModelExtractor; 122 | 123 | } //namespace hiberlite 124 | 125 | #endif // VISITOR_H 126 | -------------------------------------------------------------------------------- /include/Visitor_tmpl_impl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VISITOR_TMPL_IMPL_HPP_INCLUDED 2 | #define VISITOR_TMPL_IMPL_HPP_INCLUDED 3 | 4 | namespace hiberlite{ 5 | 6 | template 7 | AVisitor::AVisitor(C* _act, int _purp) : actor(_act) 8 | , purpose(_purp) 9 | {} 10 | 11 | template 12 | bool AVisitor::is_loading(){ 13 | return purpose==LOADING; 14 | } 15 | 16 | template 17 | bool AVisitor::is_saving(){ 18 | return purpose==SAVING; 19 | } 20 | 21 | template 22 | bool AVisitor::is_model(){ 23 | return purpose==MODEL; 24 | } 25 | 26 | template 27 | bool AVisitor::is_deleting(){ 28 | return purpose==DELETING; 29 | } 30 | 31 | template 32 | AVisitor::~AVisitor() {} 33 | 34 | template 35 | shared_connection AVisitor::getConnection() 36 | { 37 | return rootKey.con; 38 | } 39 | 40 | template 41 | sqlid_t AVisitor::getRootId() 42 | { 43 | return rootKey.id; 44 | } 45 | 46 | template template 47 | void AVisitor::startWalk(Y& obj, bean_key key) 48 | { 49 | rootKey=key; 50 | stack=std::stack(); 51 | std::string ClassName=Database::getClassName(); 52 | scope=Scope(ClassName,""); 53 | 54 | actor->notifyInitWalk(*this); 55 | walk(obj); 56 | actor->notifyDoneWalk(*this); 57 | } 58 | 59 | template template 60 | void AVisitor::walk(Y& obj) 61 | { 62 | hibernate(*this, obj, static_cast(0)); 63 | } 64 | 65 | template template 66 | AVisitor& AVisitor::operator&(sql_nvp nvp) 67 | { 68 | divePrefix(nvp.name); 69 | walk(nvp.value); 70 | pop(); 71 | return *this; 72 | } 73 | 74 | template template 75 | AVisitor& AVisitor::operator&(db_atom atom) 76 | { 77 | actor->act(*this,atom); 78 | return *this; 79 | } 80 | 81 | template template 82 | AVisitor& AVisitor::operator&(collection_nvp nvp) 83 | { 84 | actor->act(*this,nvp); 85 | return *this; 86 | } 87 | 88 | template 89 | void AVisitor::divePrefix(std::string name){ 90 | pushAndSubPrefix(name); 91 | } 92 | 93 | template 94 | void AVisitor::diveTable(std::string name){ 95 | pushAndSubTable(name); 96 | } 97 | 98 | template 99 | void AVisitor::pop(){ 100 | popScope(); 101 | } 102 | 103 | template 104 | void AVisitor::popScope() 105 | { 106 | if(!stack.size()) 107 | throw std::runtime_error("popScope with empty stack"); 108 | scope=stack.top(); 109 | stack.pop(); 110 | } 111 | 112 | template 113 | void AVisitor::pushAndSubTable(std::string name) 114 | { 115 | stack.push(scope); 116 | scope._table=scope.full()+"_"+name; 117 | scope._prefix=""; 118 | scope.prefix_depth=0; 119 | } 120 | 121 | template 122 | void AVisitor::pushAndSubPrefix(std::string prefix) 123 | { 124 | stack.push(scope); 125 | if(scope.prefix().size()) 126 | scope._prefix+="_"+prefix; 127 | else 128 | scope._prefix+=prefix; 129 | scope.prefix_depth++; 130 | } 131 | 132 | } //namespace hiberlite 133 | 134 | #endif // VISITOR_TMPL_IMPL_HPP_INCLUDED 135 | -------------------------------------------------------------------------------- /include/bean_ptr.h: -------------------------------------------------------------------------------- 1 | #ifndef BEAN_PTR_H_INCLUDED 2 | #define BEAN_PTR_H_INCLUDED 3 | 4 | namespace hiberlite{ 5 | 6 | class Database; 7 | class access; 8 | 9 | template 10 | class Registry; 11 | 12 | template 13 | class shared_res; 14 | 15 | template 16 | class real_bean : noncopyable { 17 | public: 18 | inline C* operator->(); 19 | inline C* get(); 20 | 21 | ~real_bean(); 22 | 23 | bean_key get_key() const { return key; } 24 | 25 | void save(); 26 | 27 | void destroy(); 28 | bool destroyed() const { return forgotten; } 29 | 30 | protected: 31 | inline void loadLazy(); 32 | 33 | bean_key key; 34 | C* obj; 35 | bool forgotten; 36 | 37 | private: 38 | friend class Registry; 39 | real_bean(const bean_key _key, C* _obj); //only Registry can create the real_bean 40 | }; 41 | 42 | template 43 | class bean_ptr : public shared_res< real_bean > 44 | { 45 | friend class hiberlite::access; 46 | template 47 | void hibernate(Archive & ar); 48 | 49 | friend class Registry; 50 | bean_ptr(bean_key k, rb_pair* rbpair); 51 | 52 | sqlid_t tmp_id; 53 | 54 | public: 55 | bean_ptr(bean_key k); 56 | 57 | bean_ptr(); 58 | 59 | operator bool() const; 60 | 61 | bean_ptr(const bean_ptr& other); 62 | bean_ptr& operator=(const bean_ptr& other); 63 | 64 | void save(); 65 | void destroy(); 66 | 67 | bool destroyed() { 68 | return shared_res< real_bean >::get_object()->destroyed(); 69 | } 70 | 71 | inline sqlid_t get_id(); 72 | inline C& operator*(); 73 | inline C* operator->(); 74 | }; 75 | 76 | }//namespace hiberlite 77 | 78 | #endif // BEAN_PTR_H_INCLUDED 79 | -------------------------------------------------------------------------------- /include/bean_ptr_impl.hpp: -------------------------------------------------------------------------------- 1 | namespace hiberlite{ 2 | 3 | template 4 | real_bean::real_bean(const bean_key _key, C* _obj) : key(_key), obj(_obj), forgotten(false) 5 | {} 6 | 7 | template 8 | real_bean::~real_bean() 9 | { 10 | save(); 11 | delete obj; 12 | } 13 | 14 | template 15 | void real_bean::destroy() { 16 | if(forgotten) 17 | return; 18 | Database::dbDelete(key, *obj); 19 | delete obj; 20 | forgotten=true; 21 | obj=NULL; 22 | key.id=Database::NULL_ID; 23 | } 24 | 25 | template 26 | void real_bean::save() { 27 | if(forgotten) 28 | return; 29 | if(!obj) 30 | return; 31 | Database::dbUpdate(key, *obj); 32 | } 33 | 34 | template 35 | C* real_bean::operator->() 36 | { 37 | if(forgotten) 38 | return NULL; 39 | loadLazy(); 40 | if(!obj) 41 | throw std::runtime_error("NULL pointer exception!"); 42 | return obj; 43 | } 44 | 45 | template 46 | C* real_bean::get() 47 | { 48 | if(forgotten) 49 | return NULL; 50 | loadLazy(); 51 | if(!obj) 52 | throw std::runtime_error("NULL pointer exception!"); 53 | return obj; 54 | } 55 | 56 | template 57 | inline void real_bean::loadLazy() 58 | { 59 | if(!obj && key.id!=Database::NULL_ID) 60 | obj=Database::dbLoad(key); 61 | } 62 | 63 | template 64 | bean_ptr::bean_ptr(bean_key k, rb_pair* para) 65 | { 66 | this->takeRes(para); 67 | } 68 | 69 | template 70 | bean_ptr::bean_ptr(const bean_ptr& other) : shared_res< real_bean >(other) 71 | { 72 | } 73 | 74 | template 75 | bean_ptr& bean_ptr::operator=(const bean_ptr& other) 76 | { 77 | shared_res< real_bean >::operator=( other ); 78 | return *this; 79 | } 80 | 81 | template 82 | bean_ptr::bean_ptr(bean_key k) 83 | { 84 | *this=Registry::get(k); 85 | } 86 | 87 | template 88 | bean_ptr::bean_ptr() 89 | { 90 | } 91 | 92 | template 93 | bean_ptr::operator bool() const { 94 | return get_id()!=Database::NULL_ID; 95 | } 96 | 97 | template template 98 | void bean_ptr::hibernate(Archive & ar) 99 | { 100 | tmp_id=get_id(); 101 | 102 | if(tmp_id!=Database::NULL_ID 103 | && ar.getConnection()!=shared_res< real_bean >::get_object()->get_key().con) 104 | throw std::logic_error("saving the bean from different database"); 105 | 106 | ar & hiberlite::sql_nvp< sqlid_t > ("id", tmp_id ); 107 | if(ar.is_loading()) 108 | *this=Registry::get( bean_key(ar.getConnection(), tmp_id) ); 109 | } 110 | 111 | template 112 | C& bean_ptr::operator*() { 113 | return *(shared_res< real_bean >::get_object()->get()); 114 | } 115 | 116 | template 117 | C* bean_ptr::operator->() { 118 | return shared_res< real_bean >::get_object()->get(); 119 | } 120 | 121 | template 122 | void bean_ptr::destroy() { 123 | shared_res< real_bean >::get_object()->destroy(); 124 | } 125 | 126 | template 127 | void bean_ptr::save() { 128 | shared_res< real_bean >::get_object()->save(); 129 | } 130 | 131 | template 132 | sqlid_t bean_ptr::get_id() { 133 | if( !shared_res< real_bean >::get_object() ) 134 | return Database::NULL_ID; 135 | return shared_res< real_bean >::get_object()->get_key().id; 136 | } 137 | 138 | } //namespace hiberlite 139 | -------------------------------------------------------------------------------- /include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H_ 2 | #define COMMON_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace hiberlite{ 17 | 18 | class noncopyable 19 | { 20 | protected: 21 | noncopyable() {} 22 | ~noncopyable() {} 23 | private: 24 | noncopyable( const noncopyable& ); 25 | const noncopyable operator=( const noncopyable& ); 26 | 27 | }; 28 | 29 | typedef sqlite_int64 sqlid_t; 30 | 31 | } //namespace hiberlite 32 | 33 | #define HIBERLITE_HL_DBG_DO(x) ; 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/db_error.h: -------------------------------------------------------------------------------- 1 | #ifndef DB_ERROR_H_INCLUDED 2 | #define DB_ERROR_H_INCLUDED 3 | 4 | namespace hiberlite{ 5 | 6 | class database_error : public std::runtime_error{ 7 | public: 8 | inline database_error(const char* msg) : std::runtime_error(msg) {} 9 | inline database_error(std::string msg) : std::runtime_error(msg) {} 10 | inline static void database_assert(int result, shared_connection con){ 11 | if(result==SQLITE_OK) 12 | return; 13 | throw database_error( sqlite3_errmsg(con->getSQLite3Ptr()) ); 14 | } 15 | }; 16 | 17 | } //namespace hiberlite 18 | 19 | #endif // DB_ERROR_H_INCLUDED 20 | -------------------------------------------------------------------------------- /include/hiberdefs.h: -------------------------------------------------------------------------------- 1 | #ifndef HIBERDEFS_H_INCLUDED 2 | #define HIBERDEFS_H_INCLUDED 3 | 4 | #if (defined _MSC_VER && _MSC_VER< 1600) 5 | #include 6 | #define HIBERLITE_NVP(Field) hiberlite::sql_nvp< BOOST_TYPEOF(Field) >(#Field,Field) 7 | #else 8 | #define HIBERLITE_NVP(Field) hiberlite::sql_nvp< decltype(Field) >(#Field,Field) 9 | #endif 10 | #define HIBERLITE_BASE_CLASS(ClName) hiberlite::sql_nvp< ClName >(#ClName,*((ClName*)this) ) 11 | 12 | #define HIBERLITE_EXPORT_CLASS(ClName) \ 13 | namespace hiberlite{ \ 14 | template<> \ 15 | std::string Database::getClassName() \ 16 | { std::string temp(#ClName);std::replace(temp.begin(), temp.end(), ':', '_');return temp;}} 17 | 18 | //#define HIBERLITE_COLLECTION(Field) hiberlite::collection_nvp(#Field, Field, Field.begin(), Field.end()) 19 | //#define HIBERLITE_ARRAY(Field,N) hiberlite::collection_nvp(#Field, *Field, *(Field+N)) 20 | 21 | #define HIBERLITE_PRIMARY_KEY_COLUMN "hiberlite_id" 22 | #define HIBERLITE_PARENTID_COLUMN "hiberlite_parent_id" 23 | #define HIBERLITE_ENTRY_INDEX_COLUMN "hiberlite_entry_indx" 24 | #define HIBERLITE_ID_STORAGE_CLASS "INTEGER" 25 | 26 | #define HIBERLITE_PRIMARY_KEY_STORAGE_TYPE "PRIMARYKEY" 27 | 28 | #endif // HIBERDEFS_H_INCLUDED 29 | -------------------------------------------------------------------------------- /include/hiberlite.h: -------------------------------------------------------------------------------- 1 | #ifndef _HIBERLITE_H_ 2 | #define _HIBERLITE_H_ 3 | 4 | #include 5 | 6 | #include "common.h" 7 | #include "shared_res.h" 8 | #include "hiberdefs.h" 9 | #include "nvp.h" 10 | 11 | #include "db_error.h" 12 | 13 | #include "SQLiteStmt.h" 14 | 15 | #include "CppModel.h" 16 | 17 | #include "Registry.h" 18 | #include "bean_ptr.h" 19 | 20 | #include "Visitor.h" 21 | #include "ModelExtractor.h" 22 | #include "BeanUpdater.h" 23 | #include "ChildKiller.h" 24 | #include "BeanLoader.h" 25 | 26 | #include "Database.h" 27 | 28 | 29 | #include "Registry_impl.hpp" 30 | #include "bean_ptr_impl.hpp" 31 | #include "Database_tmpl_impl.hpp" 32 | 33 | #include "Visitor_tmpl_impl.hpp" 34 | #include "ModelExtractor_impl.hpp" 35 | #include "BeanUpdater_impl.hpp" 36 | #include "ChildKiller_impl.hpp" 37 | #include "BeanLoader_impl.hpp" 38 | 39 | #include "some_types.h" 40 | 41 | #endif //_HIBERLITE_H_ 42 | -------------------------------------------------------------------------------- /include/nvp.h: -------------------------------------------------------------------------------- 1 | #ifndef _NVP_H_ 2 | #define _NVP_H_ 3 | 4 | #include "common.h" 5 | 6 | namespace hiberlite{ 7 | 8 | template 9 | class sql_nvp{ 10 | public: 11 | std::string name; 12 | C& value; 13 | std::string search_key; 14 | 15 | sql_nvp(std::string _name, C& _value, std::string search="") : name(_name), value(_value), search_key(search) {} 16 | }; 17 | 18 | template 19 | class collection_nvp{ 20 | public: 21 | std::string name; 22 | Stream stream; 23 | collection_nvp(std::string _name, Stream _s) : name(_name), stream(_s) {} 24 | }; 25 | 26 | class abstract_atom{ 27 | public: 28 | virtual void bindValue(sqlite3_stmt* stmt, int col)=0; 29 | inline virtual ~abstract_atom() {} 30 | }; 31 | 32 | template 33 | class db_atom : public abstract_atom{ 34 | public: 35 | C& val; 36 | db_atom(C& x) : val(x) {} 37 | inline virtual ~db_atom() {} 38 | 39 | inline std::string sqliteStorageClass(); 40 | 41 | template 42 | void loadValue(Stmt& res, Arg& arg); 43 | 44 | inline virtual void bindValue(sqlite3_stmt* stmt, int col); 45 | }; 46 | 47 | } //namespace hiberlite 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/shared_res.h: -------------------------------------------------------------------------------- 1 | 2 | namespace hiberlite{ 3 | 4 | template 5 | class shared_res; 6 | 7 | template 8 | class shared_cnt_obj_pair : noncopyable { 9 | protected: 10 | friend class shared_res; 11 | 12 | C* res; 13 | int refCount; 14 | 15 | explicit inline shared_cnt_obj_pair(C* r) : res(r), refCount(0) {} 16 | 17 | public: 18 | 19 | inline C* getRes(){ 20 | return res; 21 | } 22 | inline virtual ~shared_cnt_obj_pair(){ 23 | if(refCount) 24 | throw std::logic_error("resource is busy"); 25 | delete res; 26 | } 27 | inline int getRefCount(){ 28 | return refCount; 29 | } 30 | inline void inc_pair_users(){ 31 | refCount++; 32 | } 33 | inline void dec_pair_users(){ 34 | refCount--; 35 | } 36 | }; 37 | 38 | template 39 | class shared_res{ 40 | protected: 41 | shared_cnt_obj_pair* res; 42 | 43 | inline void freeRes(){ 44 | if(!res) 45 | return; 46 | res->dec_pair_users(); 47 | if(res->getRefCount()==0) 48 | delete res; 49 | } 50 | inline void takeRes(shared_cnt_obj_pair* r){ 51 | res=r; 52 | if(!res) 53 | return; 54 | res->inc_pair_users(); 55 | } 56 | 57 | public: 58 | inline explicit shared_res(C* tg) : res(NULL) { 59 | if(!tg) 60 | throw std::logic_error("no reason to manage NULL object"); 61 | shared_cnt_obj_pair* share=new shared_cnt_obj_pair(tg); 62 | takeRes(share); 63 | } 64 | 65 | inline shared_res() : res(NULL) {} 66 | 67 | inline shared_res(const shared_res& x) : res(NULL) { 68 | takeRes(x.res); 69 | } 70 | 71 | inline virtual ~shared_res(){ 72 | freeRes(); 73 | } 74 | 75 | inline shared_res& operator=(const shared_res& x){ 76 | if(x.res!=res){ 77 | freeRes(); 78 | takeRes(x.res); 79 | } 80 | return *this; 81 | } 82 | 83 | inline C* get_object(){ 84 | if(!res) 85 | return NULL; 86 | return res->getRes(); 87 | } 88 | 89 | inline C* operator->(){ 90 | return get_object(); 91 | } 92 | 93 | inline int get_ref_count(){ 94 | if(!res) 95 | return 0; 96 | return res->getRefCount(); 97 | } 98 | 99 | inline bool operator==(const shared_res& x) const{ 100 | return x.res==res; 101 | } 102 | inline bool operator<(const shared_res& x) const{ 103 | return res shared_connection; 125 | 126 | class bean_key{ 127 | public: 128 | sqlid_t id; 129 | shared_connection con; 130 | 131 | bean_key(sqlid_t _id, shared_connection _con) : id(_id), con(_con) {} 132 | bean_key(shared_connection _con, sqlid_t _id) : id(_id), con(_con) {} 133 | ~bean_key() {} 134 | bean_key(); 135 | 136 | bool operator<(const bean_key& k) const{ 137 | return (id 7 | class stl_stream_adapter{ 8 | C& ct; 9 | typename C::iterator it; 10 | E xx; 11 | public: 12 | void startLoadFromDb(){ 13 | ct.clear(); 14 | it=ct.begin(); 15 | } 16 | stl_stream_adapter(C& _ct) : ct(_ct){ 17 | it=ct.begin(); 18 | } 19 | void putNext(E& el){ 20 | ct.insert(ct.end(), el); 21 | it=ct.end(); 22 | } 23 | E& getNext(){ 24 | xx=*it++; 25 | return xx; 26 | } 27 | bool done(){ 28 | return it==ct.end(); 29 | } 30 | }; 31 | 32 | template 33 | void hibernate(A& ar, std::vector& v, const unsigned int) 34 | { 35 | collection_nvp > > body( "items", stl_stream_adapter >(v) ); 36 | ar & body; 37 | } 38 | 39 | template 40 | void hibernate(A& ar, std::pair& m, const unsigned int) 41 | { 42 | sql_nvp f("first", m.first); 43 | sql_nvp s("second", m.second); 44 | ar & f; 45 | ar & s; 46 | } 47 | 48 | template 49 | void hibernate(A& ar, std::set& m, const unsigned int) 50 | { 51 | typedef Key ElType; 52 | collection_nvp > > 53 | body( "items", stl_stream_adapter >(m) ); 54 | ar & body; 55 | } 56 | 57 | template 58 | void hibernate(A& ar, std::list& m, const unsigned int) 59 | { 60 | typedef Key ElType; 61 | collection_nvp > > 62 | body( "items", stl_stream_adapter >(m) ); 63 | ar & body; 64 | } 65 | 66 | template 67 | class stl_map_adapter{ 68 | typedef std::pair RType; 69 | typedef std::pair WType; 70 | typedef std::map C; 71 | C& ct; 72 | typename C::iterator it; 73 | 74 | WType xx; 75 | public: 76 | void startLoadFromDb(){ 77 | ct.clear(); 78 | it=ct.begin(); 79 | } 80 | stl_map_adapter(C& _ct) : ct(_ct){ 81 | it=ct.begin(); 82 | } 83 | void putNext(WType& el){ 84 | ct.insert(el); 85 | it=ct.end(); 86 | } 87 | WType& getNext(){ 88 | xx=*it++; 89 | return xx; 90 | } 91 | bool done(){ 92 | return it==ct.end(); 93 | } 94 | }; 95 | template 96 | void hibernate(A& ar, std::map& m, const unsigned int) 97 | { 98 | typedef std::pair ElType; 99 | collection_nvp > 100 | body( "items", stl_map_adapter(m) ); 101 | ar & body; 102 | } 103 | 104 | #define HIBERLITE_DEF_DB_ATOM(T, GetFromDB, PutToDB, StorClass) \ 105 | template void hibernate(A& ar, T& value, const unsigned int) \ 106 | { ar & db_atom(value); } \ 107 | template<> inline std::string db_atom::sqliteStorageClass() \ 108 | { return StorClass; } \ 109 | template<> template void db_atom::loadValue(Stmt& res, Arg& arg) \ 110 | { val=res.GetFromDB(arg); } \ 111 | template<> inline void db_atom::bindValue(sqlite3_stmt* stmt, int col) \ 112 | { PutToDB(stmt,col,val); } 113 | 114 | #define HIBERLITE_DEF_INT_ATOM(T) HIBERLITE_DEF_DB_ATOM(T, get_int, sqlite3_bind_int, "INTEGER") 115 | 116 | HIBERLITE_DEF_INT_ATOM(int) 117 | HIBERLITE_DEF_INT_ATOM(unsigned int) 118 | HIBERLITE_DEF_INT_ATOM(char) 119 | HIBERLITE_DEF_INT_ATOM(unsigned char) 120 | HIBERLITE_DEF_INT_ATOM(short) 121 | HIBERLITE_DEF_INT_ATOM(unsigned short) 122 | 123 | HIBERLITE_DEF_DB_ATOM(long long, get_int64, sqlite3_bind_int64, "INTEGER") 124 | 125 | HIBERLITE_DEF_DB_ATOM(long int, get_int64, sqlite3_bind_int64, "INTEGER") 126 | HIBERLITE_DEF_DB_ATOM(unsigned long int, get_int64, sqlite3_bind_int64, "INTEGER") 127 | HIBERLITE_DEF_DB_ATOM(unsigned long long, get_int64, sqlite3_bind_int64, "INTEGER") 128 | 129 | HIBERLITE_DEF_DB_ATOM(float, get_double, sqlite3_bind_double, "REAL") 130 | HIBERLITE_DEF_DB_ATOM(double, get_double, sqlite3_bind_double, "REAL") 131 | 132 | #undef HIBERLITE_DEF_INT_ATOM 133 | #undef HIBERLITE_DEF_DB_ATOM 134 | 135 | // std::string -> TEXT type 136 | 137 | template 138 | void hibernate(A& ar, std::string& value, const unsigned int) { 139 | ar & db_atom(value); 140 | } 141 | 142 | template<> template 143 | void db_atom::loadValue(Stmt& res, Arg& arg) { 144 | val = std::string((const char*)(res.get_text(arg))); 145 | } 146 | 147 | template<> 148 | inline std::string db_atom::sqliteStorageClass() { 149 | return "TEXT"; 150 | } 151 | 152 | template<> 153 | inline void db_atom::bindValue(sqlite3_stmt* stmt, int col) { 154 | sqlite3_bind_text(stmt, col, val.c_str(), -1, SQLITE_TRANSIENT); 155 | } 156 | 157 | // std::vector -> BLOB type 158 | 159 | template 160 | void hibernate(A& ar, std::vector& value, const unsigned int){ 161 | ar & db_atom>(value); 162 | } 163 | 164 | template<> template 165 | void db_atom>::loadValue(Stmt& res, Arg& arg) { 166 | const uint8_t* tmp = static_cast(res.get_blob(arg)); 167 | val.assign(tmp, tmp + res.get_bytes(arg)); 168 | } 169 | 170 | template<> 171 | inline std::string db_atom>::sqliteStorageClass() { 172 | return "BLOB"; 173 | } 174 | 175 | template<> 176 | inline void db_atom>::bindValue(sqlite3_stmt* stmt, int col) { 177 | sqlite3_bind_blob(stmt, col, val.data(), val.size(), SQLITE_TRANSIENT); 178 | } 179 | 180 | } //namespace hiberlite 181 | 182 | #endif // SOM_TYPES_H_INCLUDED 183 | -------------------------------------------------------------------------------- /make_vs2013.bat: -------------------------------------------------------------------------------- 1 | premake5 vs2013 2 | pause -------------------------------------------------------------------------------- /premake5.lua: -------------------------------------------------------------------------------- 1 | function CompilerSpecificFlags() 2 | filter { "action:vs*" } 3 | defines { 4 | "_CRT_SECURE_NO_DEPRECATE", 5 | "_CRT_NONSTDC_NO_DEPRECATE" 6 | } 7 | filter { "action:gmake" } 8 | buildoptions { "-std=c++0x" } 9 | filter {} -- to reset configuration filter 10 | end 11 | 12 | function RunTargetAfterBuild() 13 | configuration {"xcode*" } 14 | postbuildcommands {"$TARGET_BUILD_DIR/$TARGET_NAME"} 15 | 16 | configuration {"gmake"} 17 | postbuildcommands { "$(TARGET)" } 18 | 19 | configuration {"codeblocks" } 20 | postbuildcommands { "$(TARGET_OUTPUT_FILE)"} 21 | 22 | configuration { "vs*"} 23 | postbuildcommands { "\"$(TargetPath)\"" } 24 | configuration "*" -- to reset configuration filter 25 | end 26 | 27 | solution "hiberlite" 28 | location "Build" 29 | 30 | platforms { "native", "x32", "x64" } 31 | configurations { "Debug", "Release" } 32 | 33 | objdir "obj/%{prj.name}/%{cfg.buildcfg}" 34 | targetdir "bin/%{prj.name}/%{cfg.buildcfg}" 35 | 36 | includedirs { 37 | [[./include]], 38 | [[./sqlite-amalgamation]], 39 | [[./Catch/single_include]] 40 | } 41 | 42 | vpaths { 43 | ["Headers"] = {"**.h","**.hpp"}, 44 | ["Sources"] = {"**.c", "**.cpp"}, 45 | } 46 | 47 | filter { "configurations:Debug" } 48 | defines { "DEBUG", "_DEBUG" } 49 | flags { "Symbols" } 50 | 51 | filter { "configurations:Release" } 52 | defines { "RELEASE" } 53 | flags { "Optimize" } 54 | 55 | filter {} 56 | 57 | ---------------------------------------------------------------------------------------------------------------- 58 | project "hiberlite" 59 | language "C++" 60 | location "Build" 61 | kind "StaticLib" 62 | CompilerSpecificFlags() 63 | files { 64 | "./include/*.h", 65 | "./include/*.hpp", 66 | "./src/*.cpp", 67 | } 68 | 69 | ---------------------------------------------------------------------------------------------------------------- 70 | project "sqlite" 71 | language "C" 72 | kind "StaticLib" 73 | files { 74 | "./sqlite-amalgamation/*.h", 75 | "./sqlite-amalgamation/*.c", 76 | } 77 | 78 | ---------------------------------------------------------------------------------------------------------------- 79 | 80 | function default_project(name,files_table) 81 | project(name) 82 | language "C++" 83 | kind "ConsoleApp" 84 | files(files_table) 85 | links { "hiberlite", "sqlite" } 86 | CompilerSpecificFlags() 87 | RunTargetAfterBuild() 88 | 89 | filter {"system:linux"} 90 | links { "dl" , "pthread" } 91 | filter {} 92 | end 93 | 94 | default_project("sample",{ "./sample.cpp" }) 95 | default_project("catch_test",{ "./catch_tests.cpp" }) 96 | default_project("hiberlite_test",{ "./tests.cpp" }) 97 | -------------------------------------------------------------------------------- /sample.cpp: -------------------------------------------------------------------------------- 1 | #include "hiberlite.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | class Person{ 10 | friend class hiberlite::access; 11 | template 12 | void hibernate(Archive & ar) 13 | { 14 | ar & HIBERLITE_NVP(name); 15 | ar & HIBERLITE_NVP(age); 16 | ar & HIBERLITE_NVP(bio); 17 | } 18 | public: 19 | string name; 20 | double age; 21 | vector bio; 22 | }; 23 | 24 | HIBERLITE_EXPORT_CLASS(Person) 25 | 26 | void createDB() 27 | { 28 | hiberlite::Database db("sample.db"); 29 | //register bean classes 30 | db.registerBeanClass(); 31 | //drop all tables beans will use 32 | db.dropModel(); 33 | //create those tables again with proper schema 34 | db.createModel(); 35 | 36 | const char* names[5]={"Stanley Marsh", "Kyle Broflovski", "Eric Theodore Cartman", "Kenneth McCormick", "Leopold Stotch"}; 37 | 38 | for(unsigned int i=0;i<5;i++) { 39 | Person x; 40 | x.name=names[i%5]; 41 | x.age=14+i*0.1; 42 | x.bio.push_back("Hello"); 43 | x.bio.push_back("world"); 44 | x.bio.push_back("!"); 45 | 46 | hiberlite::bean_ptr p=db.copyBean(x); //create a managed copy of the object 47 | } 48 | } 49 | 50 | void printDB() 51 | { 52 | hiberlite::Database db("sample.db"); 53 | db.registerBeanClass(); 54 | 55 | cout << string(15,'=')+"\nreading the DB\n"; 56 | 57 | vector< hiberlite::bean_ptr > v=db.getAllBeans(); 58 | 59 | cout << "found " << v.size() << " persons in the database:\n"; 60 | 61 | for(size_t j=0;jbio.size();i++) 66 | i && cout << ", ", cout << v[j]->bio[i]; 67 | cout << "}]\n"; 68 | } 69 | } 70 | 71 | void modifyDB() 72 | { 73 | hiberlite::Database db("sample.db"); 74 | db.registerBeanClass(); 75 | 76 | vector< hiberlite::bean_ptr > v=db.getAllBeans(); 77 | cout << v[0]->name << " will be deleted.\n"; 78 | v[0].destroy(); 79 | cout << v[1]->name << " becomes 1 year older.\n\n"; 80 | v[1]->age+=1; 81 | } 82 | 83 | int main() 84 | { 85 | createDB(); 86 | printDB(); 87 | modifyDB(); 88 | printDB(); 89 | modifyDB(); 90 | printDB(); 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /src/BeanLoader.cpp: -------------------------------------------------------------------------------- 1 | #include "hiberlite.h" 2 | 3 | namespace hiberlite{ 4 | 5 | BeanLoader::BeanLoader() : AVisitor(&actor, LOADING) 6 | {} 7 | 8 | } //namespace hiberlite 9 | -------------------------------------------------------------------------------- /src/BeanUpdater.cpp: -------------------------------------------------------------------------------- 1 | #include "hiberlite.h" 2 | 3 | namespace hiberlite{ 4 | 5 | RowScope::~RowScope() 6 | { 7 | for(size_t i=0;i rs(new RowScope); 25 | rowStack.push(rs); 26 | curRow()->query="UPDATE "+table+" SET "; 27 | curRow()->id=rowid; 28 | curRow()->needComma=false; 29 | if(parent_id!=Database::NULL_ID){ 30 | curRow()->addSimpleAssign(HIBERLITE_PARENTID_COLUMN,Transformer::toSQLiteValue(parent_id)); 31 | curRow()->addSimpleAssign(HIBERLITE_ENTRY_INDEX_COLUMN,Transformer::toSQLiteValue(index)); 32 | } 33 | } 34 | 35 | void UpdateBean::commitRow(shared_connection con, sqlid_t rowid) 36 | { 37 | if(!curRow()->needComma){ 38 | rowStack.pop(); 39 | return; 40 | } 41 | if(rowid!=curRow()->id) 42 | throw std::runtime_error("rowid mismatch"); 43 | curRow()->query+=std::string(" WHERE ")+ HIBERLITE_PRIMARY_KEY_COLUMN + "="+ Transformer::toSQLiteValue(rowid) +";"; 44 | 45 | sqlite3_stmt* stmt_ptr=NULL; 46 | { 47 | sqlite3* db=con->getSQLite3Ptr(); 48 | const char* foob; 49 | int rc=sqlite3_prepare_v2(db,curRow()->query.c_str(),-1,&stmt_ptr,&foob); 50 | database_error::database_assert(rc, con); 51 | } 52 | shared_stmt statement( new statement_ptr(stmt_ptr) ); 53 | 54 | for(size_t i=0;iatoms.size();i++){ 55 | curRow()->atoms[i]->bindValue(statement->get_stmt(), static_cast(i)+RowScope::FirstAtom); 56 | } 57 | 58 | { 59 | int rc=sqlite3_step(statement->get_stmt()); 60 | if(rc!=SQLITE_DONE) 61 | database_error::database_assert(rc, con); 62 | } 63 | 64 | 65 | if(!rowStack.size()) 66 | throw std::logic_error("UpdateVisitor: commit row, but no row started"); 67 | 68 | rowStack.pop(); 69 | } 70 | 71 | BeanUpdater::BeanUpdater() : AVisitor(&actor, SAVING) 72 | {} 73 | 74 | } //namespace hiberlite 75 | -------------------------------------------------------------------------------- /src/ChildKiller.cpp: -------------------------------------------------------------------------------- 1 | #include "hiberlite.h" 2 | 3 | namespace hiberlite{ 4 | 5 | ChildKiller::ChildKiller() : AVisitor(&actor, DELETING) 6 | {} 7 | 8 | } //namespace hiberlite 9 | -------------------------------------------------------------------------------- /src/CppModel.cpp: -------------------------------------------------------------------------------- 1 | #include "hiberlite.h" 2 | 3 | namespace hiberlite{ 4 | 5 | void Model::add(Table t) 6 | { 7 | if( find(t.name)!=end() ) 8 | throw std::logic_error("table ["+t.name+"] already exists"); 9 | HIBERLITE_HL_DBG_DO( std::cout << "model add table " << t.name << std::endl; ) 10 | insert( std::pair(t.name,t) ); 11 | } 12 | 13 | Table::Table() 14 | { 15 | add(Column(HIBERLITE_PRIMARY_KEY_COLUMN,HIBERLITE_PRIMARY_KEY_STORAGE_TYPE)); 16 | } 17 | 18 | void Table::add(Column c) 19 | { 20 | HIBERLITE_HL_DBG_DO( std::cout << "table " << name << " add column " << c.name << " : " << c.storage_type << std::endl; ) 21 | columns[c.name]=c; 22 | } 23 | 24 | bool Table::contains(std::string colname) 25 | { 26 | return columns.find(colname)!=columns.end(); 27 | } 28 | 29 | std::string Scope::name_column(std::string name) 30 | { 31 | if(prefix().size()) 32 | return prefix()+"_"+name; 33 | else 34 | return name; 35 | } 36 | 37 | std::string Scope::full() 38 | { 39 | if(prefix().size()) 40 | return table()+"_"+prefix(); 41 | else 42 | return table(); 43 | } 44 | 45 | } //namespace hiberlite 46 | -------------------------------------------------------------------------------- /src/Database.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "hiberlite.h" 3 | 4 | namespace hiberlite{ 5 | 6 | Database::Database() : mx(NULL) 7 | { 8 | } 9 | 10 | Database::Database(std::string fname) : mx(NULL) 11 | { 12 | open(fname); 13 | } 14 | 15 | Database::~Database() 16 | { 17 | close(); 18 | } 19 | 20 | void Database::open(std::string fname) 21 | { 22 | sqlite3* db=NULL; 23 | 24 | try{ 25 | //TODO UTF-8 string 26 | int rc=sqlite3_open(fname.c_str(), &db); 27 | if(rc!=SQLITE_OK) 28 | throw database_error( std::string("database error: ")+sqlite3_errmsg(db) ); 29 | con=shared_connection(new autoclosed_con(db)); 30 | 31 | }catch(std::runtime_error e){ 32 | if(db) 33 | sqlite3_close(db); 34 | throw e; 35 | } 36 | } 37 | 38 | void Database::close() 39 | { 40 | if(mx) { 41 | delete mx; 42 | mx=NULL; 43 | } 44 | } 45 | 46 | std::vector Database::checkModel() 47 | { 48 | //TODO checkModel 49 | std::vector ans; 50 | return ans; 51 | } 52 | 53 | void Database::dropModel() 54 | { 55 | if(!mx) 56 | throw std::logic_error("register bean classes first"); 57 | Model mdl=mx->getModel(); 58 | for(Model::iterator it=mdl.begin();it!=mdl.end();it++){ 59 | Table& t=it->second; 60 | std::string query="DROP TABLE IF EXISTS "+t.name+";"; 61 | dbExecQuery(query); 62 | } 63 | } 64 | 65 | void Database::createModel() 66 | { 67 | if(!mx) 68 | throw std::logic_error("register bean classes first"); 69 | Model mdl=mx->getModel(); 70 | for(Model::iterator it=mdl.begin();it!=mdl.end();it++){ 71 | Table& t=it->second; 72 | std::string query="CREATE TABLE "+t.name+" ("; 73 | bool needComma=false; 74 | for(std::map::iterator c=t.columns.begin();c!=t.columns.end();c++){ 75 | if(needComma) 76 | query+=", "; 77 | needComma=true; 78 | Column& col=c->second; 79 | query += col.name + " "; 80 | if(col.name==HIBERLITE_PRIMARY_KEY_COLUMN) 81 | query+="INTEGER PRIMARY KEY AUTOINCREMENT"; 82 | else 83 | query+=col.storage_type; 84 | } 85 | query +=");"; 86 | dbExecQuery(query); 87 | } 88 | } 89 | 90 | sqlid_t Database::allocId(shared_connection c, std::string table) 91 | { 92 | //THREAD critical call 93 | char* err_msg=NULL; 94 | std::string query="INSERT INTO "+table+" ("+HIBERLITE_PRIMARY_KEY_COLUMN+") VALUES (NULL);"; 95 | HIBERLITE_HL_DBG_DO( std::cout << "exec: " << query << std::endl; ) 96 | int rc=sqlite3_exec(c->getSQLite3Ptr(),query.c_str(),NULL, NULL, &err_msg ); 97 | if(err_msg) 98 | throw database_error(err_msg); 99 | database_error::database_assert(rc, c); 100 | 101 | return sqlite3_last_insert_rowid(c->getSQLite3Ptr()); 102 | } 103 | 104 | void Database::dbExecQuery(shared_connection con, std::string query) 105 | { 106 | char* err_msg=NULL; 107 | HIBERLITE_HL_DBG_DO( std::cout << "exec: " << query << std::endl; ) 108 | int rc=sqlite3_exec(con->getSQLite3Ptr(),query.c_str(),NULL, NULL, &err_msg ); 109 | if(err_msg){ 110 | std::string msg=err_msg; 111 | sqlite3_free(err_msg); 112 | throw database_error(msg); 113 | } 114 | database_error::database_assert(rc, con); 115 | } 116 | 117 | sqlid_t Database::allocId(std::string table){ 118 | return allocId(con, table); 119 | } 120 | 121 | void Database::dbExecQuery(std::string query){ 122 | return dbExecQuery(con, query); 123 | } 124 | 125 | std::vector Database::dbSelectIds(shared_connection con, const std::string table, const std::string condition, const std::string orderBy) 126 | { 127 | std::string where; 128 | if(condition.size()) 129 | where=" WHERE "+condition; 130 | std::string order; 131 | if(orderBy.size()) 132 | order=" ORDER BY "+orderBy; 133 | std::string query="SELECT "+std::string(HIBERLITE_PRIMARY_KEY_COLUMN) 134 | +" FROM "+table 135 | +where 136 | +order 137 | +";"; 138 | SQLiteSelect sel(con, query); 139 | std::vector ans; 140 | while(sel.step()) 141 | ans.push_back( sel.get_int64(0) ); 142 | return ans; 143 | } 144 | 145 | std::vector Database::dbSelectChildIds(shared_connection con, std::string table, sqlid_t parent) 146 | { 147 | return dbSelectIds(con, table, std::string(HIBERLITE_PARENTID_COLUMN)+"="+Transformer::toSQLiteValue(parent) 148 | , HIBERLITE_ENTRY_INDEX_COLUMN); 149 | } 150 | 151 | std::vector Database::dbSelectChildIds(std::string table, sqlid_t parent) 152 | { 153 | return dbSelectChildIds(con,table,parent); 154 | } 155 | 156 | 157 | } //namespace hiberlite; 158 | -------------------------------------------------------------------------------- /src/ModelExtractor.cpp: -------------------------------------------------------------------------------- 1 | #include "hiberlite.h" 2 | 3 | namespace hiberlite{ 4 | 5 | ModelExtractor::ModelExtractor() : AVisitor(&actor, MODEL) 6 | {} 7 | 8 | Model ExtractModel::getModel() { 9 | return model; 10 | } 11 | 12 | Model ModelExtractor::getModel() { 13 | return actor.getModel(); 14 | } 15 | 16 | } //namespace hiberlite 17 | -------------------------------------------------------------------------------- /src/Registry.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "hiberlite.h" 3 | 4 | namespace hiberlite{ 5 | 6 | //template 7 | //std::map< bean_key, bean_ptr > Registry::beans=std::map< bean_key, bean_ptr >(); 8 | 9 | } //namespace hiberlite 10 | -------------------------------------------------------------------------------- /src/SQLiteStmt.cpp: -------------------------------------------------------------------------------- 1 | #include "hiberlite.h" 2 | 3 | namespace hiberlite{ 4 | 5 | SQLiteSelect::SQLiteSelect(shared_connection _con, std::string query) : con(_con) 6 | { 7 | HIBERLITE_HL_DBG_DO( std::cout << "query: " << query << std::endl; ) 8 | active=false; 9 | sqlite3_stmt* stmt_ptr=NULL; 10 | sqlite3* db=con->getSQLite3Ptr(); 11 | const char* foob; 12 | int rc=sqlite3_prepare_v2(db,query.c_str(),-1,&stmt_ptr,&foob); 13 | database_error::database_assert(rc, con); 14 | statement=shared_stmt( new statement_ptr(stmt_ptr) ); 15 | } 16 | 17 | SQLiteSelect::~SQLiteSelect() 18 | { 19 | } 20 | 21 | bool SQLiteSelect::step() 22 | { 23 | int rc=sqlite3_step(statement->get_stmt()); 24 | if(rc==SQLITE_DONE) 25 | return false; 26 | if(rc==SQLITE_ROW){ 27 | active=true; 28 | return true; 29 | } 30 | database_error::database_assert(rc, con); 31 | throw database_error("really strange - sqlite3_step returns SQLITE_OK"); 32 | } 33 | 34 | const void* SQLiteSelect::get_blob(int iCol){ 35 | if(!active) 36 | throw std::runtime_error("step() was not called before column access"); 37 | return sqlite3_column_blob(statement->get_stmt(), iCol); 38 | } 39 | 40 | int SQLiteSelect::get_bytes(int iCol){ 41 | if(!active) 42 | throw std::runtime_error("step() was not called before column access"); 43 | return sqlite3_column_bytes(statement->get_stmt(), iCol); 44 | } 45 | 46 | double SQLiteSelect::get_double(int iCol){ 47 | if(!active) 48 | throw std::runtime_error("step() was not called before column access"); 49 | return sqlite3_column_double(statement->get_stmt(), iCol); 50 | } 51 | 52 | int SQLiteSelect::get_int(int iCol){ 53 | if(!active) 54 | throw std::runtime_error("step() was not called before column access"); 55 | return sqlite3_column_int(statement->get_stmt(), iCol); 56 | } 57 | 58 | sqlid_t SQLiteSelect::get_int64(int iCol){ 59 | if(!active) 60 | throw std::runtime_error("step() was not called before column access"); 61 | return sqlite3_column_int64(statement->get_stmt(), iCol); 62 | } 63 | 64 | const unsigned char *SQLiteSelect::get_text(int iCol){ 65 | if(!active) 66 | throw std::runtime_error("step() was not called before column access"); 67 | return sqlite3_column_text(statement->get_stmt(), iCol); 68 | } 69 | 70 | int SQLiteSelect::get_type(int iCol){ 71 | if(!active) 72 | throw std::runtime_error("step() was not called before column access"); 73 | return sqlite3_column_type(statement->get_stmt(), iCol); 74 | } 75 | 76 | std::string SQLiteSelect::get_name(int N){ 77 | if(!active) 78 | throw std::runtime_error("step() was not called before column access"); 79 | return sqlite3_column_name(statement->get_stmt(), N); 80 | } 81 | 82 | int SQLiteSelect::column_count(){ 83 | if(!active) 84 | throw std::runtime_error("step() was not called before column access"); 85 | return sqlite3_column_count(statement->get_stmt()); 86 | } 87 | 88 | 89 | } 90 | 91 | //namespace hiberlite 92 | -------------------------------------------------------------------------------- /src/Visitor.cpp: -------------------------------------------------------------------------------- 1 | #include "hiberlite.h" 2 | 3 | namespace hiberlite { 4 | 5 | } //namespace hiberlite 6 | -------------------------------------------------------------------------------- /src/shared_res.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "hiberlite.h" 3 | 4 | namespace hiberlite{ 5 | 6 | bean_key::bean_key() 7 | { 8 | id=Database::NULL_ID; 9 | } 10 | 11 | } //namespace hiberlite 12 | -------------------------------------------------------------------------------- /tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "hiberlite.h" 3 | using namespace hiberlite; 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | 13 | class B{ 14 | friend class hiberlite::access; 15 | template 16 | void hibernate(Archive & ar) 17 | { 18 | ar & HIBERLITE_NVP(name); 19 | ar & HIBERLITE_NVP(weight); 20 | ar & HIBERLITE_NVP(height); 21 | } 22 | 23 | public: 24 | string name; 25 | double weight; 26 | int height; 27 | }; 28 | 29 | class A{ 30 | friend class hiberlite::access; 31 | template 32 | void hibernate(Archive & ar) 33 | { 34 | ar & HIBERLITE_NVP(seti); 35 | ar & HIBERLITE_NVP(i); 36 | ar & HIBERLITE_NVP(s); 37 | ar & HIBERLITE_NVP(vi); 38 | ar & HIBERLITE_NVP(v); 39 | ar & HIBERLITE_NVP(mm); 40 | } 41 | 42 | public: 43 | int i; 44 | string s; 45 | vector< pair > vi; 46 | set< double > seti; 47 | vector< bean_ptr > v; 48 | map > mm; 49 | }; 50 | 51 | class X{ 52 | friend class hiberlite::access; 53 | template 54 | void hibernate(Archive & ar) 55 | { 56 | ar & HIBERLITE_NVP(seti); 57 | ar & HIBERLITE_NVP(vvi); 58 | ar & HIBERLITE_NVP(mm); 59 | } 60 | public: 61 | set< pair > seti; 62 | vector< vector > vvi; 63 | map< vector, map > mm; 64 | bool operator==(const X& x){ 65 | return seti==x.seti && vvi==x.vvi && mm==x.mm; 66 | } 67 | }; 68 | 69 | class WrappedBytes { 70 | friend class hiberlite::access; 71 | template 72 | void hibernate(Archive & ar) 73 | { 74 | ar & HIBERLITE_NVP(bytes); 75 | } 76 | public: 77 | vector bytes; 78 | bool operator==(const WrappedBytes& wrappedBytes) { 79 | return bytes == wrappedBytes.bytes; 80 | } 81 | }; 82 | 83 | HIBERLITE_EXPORT_CLASS(A) 84 | HIBERLITE_EXPORT_CLASS(B) 85 | HIBERLITE_EXPORT_CLASS(X) 86 | HIBERLITE_EXPORT_CLASS(WrappedBytes) 87 | 88 | struct Tester{ 89 | void test1(){ 90 | Database db("test.db"); 91 | 92 | db.registerBeanClass(); 93 | db.registerBeanClass(); 94 | 95 | vector msg=db.checkModel(); 96 | for(size_t ci=0;ci ptr=db.copyBean(x); 121 | obj.v.push_back(ptr); 122 | } 123 | while(obj.v.size()){ 124 | obj.v[0].destroy(); 125 | obj.v.erase(obj.v.begin()); 126 | } 127 | bean_ptr a=db.copyBean(obj); 128 | if(a.get_id()%10==0) 129 | cout << "save obj with name " << (*a).s << endl; 130 | } 131 | } 132 | void test2(){ 133 | Database db("test.db"); 134 | // we will not create or drop tables, so model initialization 135 | // is not necessary 136 | // db.registerBeanClass(); 137 | // db.registerBeanClass(); 138 | 139 | Database otherdb("copy.db"); 140 | otherdb.registerBeanClass(); 141 | otherdb.registerBeanClass(); 142 | 143 | otherdb.dropModel(); 144 | otherdb.createModel(); 145 | 146 | bean_ptr be=db.loadBean(1); 147 | A obj2=*be; 148 | bean_ptr a2=otherdb.copyBean(obj2); 149 | cout << "load obj with name " << (*a2).s << endl; 150 | } 151 | 152 | void test3(){ 153 | X x; 154 | x.vvi.resize(5); 155 | map< vector, map > mm; 156 | vector randstr; 157 | unsigned int NS=30; 158 | for(unsigned int i=0;i vs; 166 | for(unsigned int i=0;i<5;i++) 167 | vs.push_back( randstr[(17+7*i)%NS] ); 168 | for(unsigned int i=0;i<10;i++) 169 | x.mm[vs][ randstr[(19*i)%NS] ]=randstr[(23*i)%NS]; 170 | } 171 | 172 | { 173 | Database db("t3.db"); 174 | db.registerBeanClass(); 175 | db.dropModel(); 176 | db.createModel(); 177 | db.copyBean(x); 178 | } 179 | 180 | { 181 | Database db("t3.db"); 182 | db.registerBeanClass(); 183 | bean_ptr xptr=db.loadBean(1); 184 | if( !(*xptr==x) ) 185 | throw std::runtime_error("load failed"); 186 | } 187 | 188 | } 189 | 190 | void test4() { 191 | WrappedBytes wrappedBytes; 192 | wrappedBytes.bytes = {'a', 'b', 'c', 'd', 'e'}; 193 | 194 | { 195 | Database db("t4.db"); 196 | db.registerBeanClass(); 197 | db.dropModel(); 198 | db.createModel(); 199 | db.copyBean(wrappedBytes); 200 | } 201 | 202 | { 203 | Database db("t4.db"); 204 | db.registerBeanClass(); 205 | bean_ptr wb_ptr = db.loadBean(1); 206 | if (!(*wb_ptr == wrappedBytes)) 207 | throw std::runtime_error("BLOB load failed"); 208 | } 209 | } 210 | }; 211 | 212 | int main() 213 | { 214 | try{ 215 | { 216 | Tester t; 217 | t.test1(); 218 | t.test2(); 219 | t.test3(); 220 | t.test4(); 221 | } 222 | cout << "tests passed\n"; 223 | }catch(std::exception& e){ 224 | cerr << "caught exception\n"; 225 | cerr << e.what() << "\n"; 226 | return 1; 227 | } 228 | catch(...){ 229 | cerr << "caught strange exception\n"; 230 | return 1; 231 | } 232 | return 0; 233 | }/**/ 234 | --------------------------------------------------------------------------------