Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

This contains the 64 bit working version of the sqlnative2 client for
Node.js
  • Loading branch information...
commit d0fffdfdcca3dcfb657441d4d1f71ab5ac94fc3a 0 parents
@jdarling authored
Showing with 45,177 additions and 0 deletions.
  1. +22 −0 .gitattributes
  2. +170 −0 .gitignore
  3. +37 −0 examples/test.js
  4. BIN  ext/libjson/._JSONOptions.h
  5. +270 −0 ext/libjson/Dependencies/libbase64++/libbase64++.h
  6. +1,088 −0 ext/libjson/Dependencies/mempool++/mempool.h
  7. BIN  ext/libjson/Documentation.pdf
  8. +43 −0 ext/libjson/Getting Started/C++ Interface/array.htm
  9. +57 −0 ext/libjson/Getting Started/C++ Interface/basic_parser.htm
  10. +46 −0 ext/libjson/Getting Started/C++ Interface/child_node.htm
  11. +36 −0 ext/libjson/Getting Started/C++ Interface/simple_write.htm
  12. +48 −0 ext/libjson/Getting Started/Library Interface/array.htm
  13. +77 −0 ext/libjson/Getting Started/Library Interface/basic_parser.htm
  14. +50 −0 ext/libjson/Getting Started/Library Interface/child_node.htm
  15. +17 −0 ext/libjson/Getting Started/Library Interface/scripts/shAutoloader.js
  16. +97 −0 ext/libjson/Getting Started/Library Interface/scripts/shBrushCpp.js
  17. +17 −0 ext/libjson/Getting Started/Library Interface/scripts/shCore.js
  18. +17 −0 ext/libjson/Getting Started/Library Interface/scripts/shLegacy.js
  19. +43 −0 ext/libjson/Getting Started/Library Interface/simple_write.htm
  20. +226 −0 ext/libjson/Getting Started/Library Interface/styles/shCore.css
  21. +328 −0 ext/libjson/Getting Started/Library Interface/styles/shCoreDefault.css
  22. +331 −0 ext/libjson/Getting Started/Library Interface/styles/shCoreDjango.css
  23. +339 −0 ext/libjson/Getting Started/Library Interface/styles/shCoreEclipse.css
  24. +324 −0 ext/libjson/Getting Started/Library Interface/styles/shCoreEmacs.css
  25. +328 −0 ext/libjson/Getting Started/Library Interface/styles/shCoreFadeToGrey.css
  26. +324 −0 ext/libjson/Getting Started/Library Interface/styles/shCoreMDUltra.css
  27. +324 −0 ext/libjson/Getting Started/Library Interface/styles/shCoreMidnight.css
  28. +324 −0 ext/libjson/Getting Started/Library Interface/styles/shCoreRDark.css
  29. +117 −0 ext/libjson/Getting Started/Library Interface/styles/shThemeDefault.css
  30. +120 −0 ext/libjson/Getting Started/Library Interface/styles/shThemeDjango.css
  31. +128 −0 ext/libjson/Getting Started/Library Interface/styles/shThemeEclipse.css
  32. +113 −0 ext/libjson/Getting Started/Library Interface/styles/shThemeEmacs.css
  33. +117 −0 ext/libjson/Getting Started/Library Interface/styles/shThemeFadeToGrey.css
  34. +113 −0 ext/libjson/Getting Started/Library Interface/styles/shThemeMDUltra.css
  35. +113 −0 ext/libjson/Getting Started/Library Interface/styles/shThemeMidnight.css
  36. +113 −0 ext/libjson/Getting Started/Library Interface/styles/shThemeRDark.css
  37. +361 −0 ext/libjson/JSONOptions.h
  38. +13 −0 ext/libjson/License.txt
  39. +32 −0 ext/libjson/Source/JSONAllocator.cpp
  40. +77 −0 ext/libjson/Source/JSONAllocator.h
  41. +99 −0 ext/libjson/Source/JSONChildren.cpp
  42. +333 −0 ext/libjson/Source/JSONChildren.h
  43. +42 −0 ext/libjson/Source/JSONDebug.cpp
  44. +58 −0 ext/libjson/Source/JSONDebug.h
  45. +187 −0 ext/libjson/Source/JSONDefs.h
  46. +73 −0 ext/libjson/Source/JSONDefs/GNU_C.h
  47. +36 −0 ext/libjson/Source/JSONDefs/Strings_Defs.h
  48. +26 −0 ext/libjson/Source/JSONDefs/Unknown_C.h
  49. +26 −0 ext/libjson/Source/JSONDefs/Visual_C.h
  50. +81 −0 ext/libjson/Source/JSONGlobals.h
  51. +214 −0 ext/libjson/Source/JSONIterators.cpp
  52. +147 −0 ext/libjson/Source/JSONMemory.cpp
  53. +171 −0 ext/libjson/Source/JSONMemory.h
  54. +38 −0 ext/libjson/Source/JSONMemoryPool.h
  55. +377 −0 ext/libjson/Source/JSONNode.cpp
  56. +998 −0 ext/libjson/Source/JSONNode.h
  57. +198 −0 ext/libjson/Source/JSONNode_Mutex.cpp
  58. +499 −0 ext/libjson/Source/JSONPreparse.cpp
  59. +28 −0 ext/libjson/Source/JSONPreparse.h
  60. +308 −0 ext/libjson/Source/JSONSharedString.h
  61. +23 −0 ext/libjson/Source/JSONSingleton.h
  62. +138 −0 ext/libjson/Source/JSONStream.cpp
  63. +91 −0 ext/libjson/Source/JSONStream.h
  64. +404 −0 ext/libjson/Source/JSONValidator.cpp
  65. +38 −0 ext/libjson/Source/JSONValidator.h
  66. +672 −0 ext/libjson/Source/JSONWorker.cpp
  67. +65 −0 ext/libjson/Source/JSONWorker.h
  68. +252 −0 ext/libjson/Source/JSONWriter.cpp
  69. +35 −0 ext/libjson/Source/JSON_Base64.h
  70. +450 −0 ext/libjson/Source/NumberToString.h
  71. +833 −0 ext/libjson/Source/internalJSONNode.cpp
  72. +514 −0 ext/libjson/Source/internalJSONNode.h
  73. +605 −0 ext/libjson/Source/libjson.cpp
  74. +371 −0 ext/libjson/TestSuite/All/Options.txt
  75. +246 −0 ext/libjson/TestSuite/All/main.cpp
  76. +311 −0 ext/libjson/TestSuite/Benchmark/main.cpp
  77. +42 −0 ext/libjson/TestSuite/Benchmark/makefile
  78. +12 −0 ext/libjson/TestSuite/Checklist.txt
  79. +155 −0 ext/libjson/TestSuite/RunTestSuite2.cpp
  80. +9 −0 ext/libjson/TestSuite/RunTestSuite2.h
  81. +297 −0 ext/libjson/TestSuite/StringTest.h
  82. +155 −0 ext/libjson/TestSuite/TestAssign.cpp
  83. +40 −0 ext/libjson/TestSuite/TestBinary.cpp
  84. +340 −0 ext/libjson/TestSuite/TestChildren.cpp
  85. +435 −0 ext/libjson/TestSuite/TestComments.cpp
  86. +204 −0 ext/libjson/TestSuite/TestConverters.cpp
  87. +115 −0 ext/libjson/TestSuite/TestCtors.cpp
  88. +101 −0 ext/libjson/TestSuite/TestEquality.cpp
  89. +257 −0 ext/libjson/TestSuite/TestFunctions.cpp
  90. +78 −0 ext/libjson/TestSuite/TestInequality.cpp
  91. +363 −0 ext/libjson/TestSuite/TestInspectors.cpp
  92. +838 −0 ext/libjson/TestSuite/TestIterators.cpp
  93. +345 −0 ext/libjson/TestSuite/TestMutex.cpp
  94. +290 −0 ext/libjson/TestSuite/TestNamespace.cpp
  95. +131 −0 ext/libjson/TestSuite/TestRefCounting.cpp
  96. +125 −0 ext/libjson/TestSuite/TestSharedString.cpp
  97. +171 −0 ext/libjson/TestSuite/TestStreams.cpp
  98. +197 −0 ext/libjson/TestSuite/TestString.cpp
  99. +79 −0 ext/libjson/TestSuite/TestSuite.1
  100. +78 −0 ext/libjson/TestSuite/TestSuite.cpp
  101. +109 −0 ext/libjson/TestSuite/TestSuite.h
  102. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/._project.xcworkspace
  103. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/._wallace.mode1v3
  104. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/._wallace.pbxuser
  105. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/._xcuserdata
  106. +685 −0 ext/libjson/TestSuite/TestSuite.xcodeproj/project.pbxproj
  107. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/project.xcworkspace/._xcuserdata
  108. +11 −0 ext/libjson/TestSuite/TestSuite.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  109. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/project.xcworkspace/xcuserdata/._wallace.xcuserdatad
  110. +17,091 −0 ...Suite/TestSuite.xcodeproj/project.xcworkspace/xcuserdata/wallace.xcuserdatad/UserInterfaceState.xcuserstate
  111. +10 −0 ...stSuite/TestSuite.xcodeproj/project.xcworkspace/xcuserdata/wallace.xcuserdatad/WorkspaceSettings.xcsettings
  112. +1,523 −0 ext/libjson/TestSuite/TestSuite.xcodeproj/wallace.mode1v3
  113. +2,465 −0 ext/libjson/TestSuite/TestSuite.xcodeproj/wallace.pbxuser
  114. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/xcuserdata/._wallace.xcuserdatad
  115. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/._xcdebugger
  116. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/._xcschemes
  117. +35 −0 ext/libjson/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
  118. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcschemes/._TestSuite.xcscheme
  119. BIN  ext/libjson/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcschemes/._xcschememanagement.plist
  120. +72 −0 ext/libjson/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcschemes/TestSuite.xcscheme
  121. +22 −0 ext/libjson/TestSuite/TestSuite.xcodeproj/xcuserdata/wallace.xcuserdatad/xcschemes/xcschememanagement.plist
  122. +74 −0 ext/libjson/TestSuite/TestSuite2Creator.php
  123. +225 −0 ext/libjson/TestSuite/TestValidator.cpp
  124. +169 −0 ext/libjson/TestSuite/TestWriter.cpp
  125. +298 −0 ext/libjson/TestSuite/UStringTest.h
  126. +176 −0 ext/libjson/TestSuite/UnitTest.cpp
  127. +229 −0 ext/libjson/TestSuite/UnitTest.h
  128. +149 −0 ext/libjson/TestSuite/main.cpp
  129. +137 −0 ext/libjson/TestSuite/makefile
  130. +24 −0 ext/libjson/TestSuite2/BaseTest.h
  131. +64 −0 ext/libjson/TestSuite2/JSONDebug/JSON_ASSERT.cpp
  132. +15 −0 ext/libjson/TestSuite2/JSONDebug/JSON_ASSERT.h
  133. +74 −0 ext/libjson/TestSuite2/JSONDebug/JSON_ASSERT_SAFE.cpp
  134. +15 −0 ext/libjson/TestSuite2/JSONDebug/JSON_ASSERT_SAFE.h
  135. +51 −0 ext/libjson/TestSuite2/JSONDebug/JSON_FAIL.cpp
  136. +14 −0 ext/libjson/TestSuite2/JSONDebug/JSON_FAIL.h
  137. +58 −0 ext/libjson/TestSuite2/JSONDebug/JSON_FAIL_SAFE.cpp
  138. +14 −0 ext/libjson/TestSuite2/JSONDebug/JSON_FAIL_SAFE.h
  139. +21 −0 ext/libjson/TestSuite2/JSONGlobals/jsonSingleton.cpp
  140. +13 −0 ext/libjson/TestSuite2/JSONGlobals/jsonSingleton.h
  141. +48 −0 ext/libjson/TestSuite2/JSONValidator/Resources/validyMacros.h
  142. +11 −0 ext/libjson/TestSuite2/JSONValidator/isValidArray.cpp
  143. +9 −0 ext/libjson/TestSuite2/JSONValidator/isValidArray.h
  144. +101 −0 ext/libjson/TestSuite2/JSONValidator/isValidMember.cpp
  145. +16 −0 ext/libjson/TestSuite2/JSONValidator/isValidMember.h
  146. +11 −0 ext/libjson/TestSuite2/JSONValidator/isValidNamedObject.cpp
  147. +9 −0 ext/libjson/TestSuite2/JSONValidator/isValidNamedObject.h
  148. +506 −0 ext/libjson/TestSuite2/JSONValidator/isValidNumber.cpp
  149. +21 −0 ext/libjson/TestSuite2/JSONValidator/isValidNumber.h
  150. +11 −0 ext/libjson/TestSuite2/JSONValidator/isValidObject.cpp
  151. +9 −0 ext/libjson/TestSuite2/JSONValidator/isValidObject.h
  152. +11 −0 ext/libjson/TestSuite2/JSONValidator/isValidPartialRoot.cpp
  153. +9 −0 ext/libjson/TestSuite2/JSONValidator/isValidPartialRoot.h
  154. +39 −0 ext/libjson/TestSuite2/JSONValidator/isValidRoot.cpp
  155. +14 −0 ext/libjson/TestSuite2/JSONValidator/isValidRoot.h
  156. +63 −0 ext/libjson/TestSuite2/JSONValidator/isValidString.cpp
  157. +17 −0 ext/libjson/TestSuite2/JSONValidator/isValidString.h
  158. +27 −0 ext/libjson/TestSuite2/JSONValidator/securityTest.cpp
  159. +12 −0 ext/libjson/TestSuite2/JSONValidator/securityTest.h
  160. +12 −0 ext/libjson/TestSuite2/JSON_Base64/json_decode64.cpp
  161. +12 −0 ext/libjson/TestSuite2/JSON_Base64/json_decode64.h
  162. +48 −0 ext/libjson/TestSuite2/JSON_Base64/json_encode64.cpp
  163. +13 −0 ext/libjson/TestSuite2/JSON_Base64/json_encode64.h
  164. +47 −0 ext/libjson/TestSuite2/NumberToString/_areFloatsEqual.cpp
  165. +14 −0 ext/libjson/TestSuite2/NumberToString/_areFloatsEqual.h
Sorry, we could not display the entire diff because it was too big.
22 .gitattributes
@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+*.sln merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
170 .gitignore
@@ -0,0 +1,170 @@
+#################
+## VC++ Files
+#################
+
+Debug/*.log
+Debug/*.tlog
+
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+[Dd]ebug/
+[Rr]elease/
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.vspscc
+.builds
+*.dotCover
+
+## TODO: If you have NuGet Package Restore enabled, uncomment this
+#packages/
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+
+# Visual Studio profiler
+*.psess
+*.vsp
+
+# ReSharper is a .NET coding add-in
+_ReSharper*
+
+# Installshield output folder
+[Ee]xpress
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish
+
+# Others
+[Bb]in
+[Oo]bj
+sql
+TestResults
+*.Cache
+ClientBin
+stylecop.*
+~$*
+*.dbmdl
+Generated_Code #added for RIA/Silverlight projects
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+
+
+
+############
+## Windows
+############
+
+# Windows image file caches
+Thumbs.db
+
+# Folder config file
+Desktop.ini
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
+
+# Mac crap
+.DS_Store
37 examples/test.js
@@ -0,0 +1,37 @@
+console.log("Loading SQL Server driver");
+var cs = require('../Debug/sqlnative2');
+
+console.log("Connecting to DB Server");
+var conn = new cs.SQLConnection('Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TEST;Data Source=localhost:1443');
+
+console.log(new Array(40).join('-='));
+console.log("Running a simple query against the server");
+console.log(conn.query("EXEC [dbo].[TestProc]").length);
+
+console.log(new Array(40).join('-='));
+console.log("Now to break it by connecting to something that doesn't exist");
+try{
+ var conn2 = new cs.SQLConnection('Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=NOEXIST;Data Source=goBoom');
+}catch(e){
+ console.log("Got an error: ", e);
+}
+
+console.log(new Array(40).join('-='));
+console.log("Try to brake it by sending a bad query");
+try{
+ conn.query("FRAZ BATZ NIMRO FREEBAR")
+}catch(e){
+ console.log("Got an error: ", e);
+}
+
+console.log(new Array(40).join('-='));
+console.log("Try to brake it by selecting from a table that does not exist");
+try{
+ console.log(conn.query("SELECT * FROM this_table_does_not_exist"));
+}catch(e){
+ console.log("Got an error: ", e);
+}
+
+console.log(new Array(40).join('-='));
+console.log("Finally re-run the query just to prove we still work");
+console.log(conn.query("EXEC [dbo].[TestProc]"));
BIN  ext/libjson/._JSONOptions.h
Binary file not shown
270 ext/libjson/Dependencies/libbase64++/libbase64++.h
@@ -0,0 +1,270 @@
+#ifndef LIBBASE64_CPP_H
+#define LIBBASE64_CPP_H
+
+#include <string>
+//#define LIBBASE64_THROW_STD_INVALID_ARGUMENT
+
+//version info
+#define __LIBBASE64_MAJOR__ 1
+#define __LIBBASE64_MINOR__ 1
+#define __LIBBASE64_PATCH__ 0
+#define __LIBBASE64_VERSION__ (__LIBBASE64_MAJOR__ * 10000 + __LIBBASE64_MINOR__ * 100 + __LIBBASE64_PATCH__)
+
+//code coverage and asserts
+#ifdef NDEBUG
+ #define LIBBASE64_ASSERT(cond, msg) (void)0
+ #define CREATEBOUNDCHECKER(type, name, ubound, lbound) (void)0
+ #define GETITEM_BOUNDCHECK(loc, name) (*(loc))
+#else
+ #include <iostream>
+ #define LIBBASE64_ASSERT(cond, msg) if (!(cond)){ std::cerr << msg << std::endl; throw false; }
+
+ template<typename T>
+ class libbase64_boundChecker {
+ public:
+ libbase64_boundChecker(const T * lbound, const T * ubound) : upperbound(ubound), lowerbound(lbound){};
+ T getLocation(const T * loc){
+ LIBBASE64_ASSERT(loc < upperbound, "Array index above bounds");
+ LIBBASE64_ASSERT(loc >= lowerbound, "Array index below bounds");
+ return *loc;
+ }
+ private:
+ const T * lowerbound;
+ const T * upperbound;
+ };
+ #define CREATEBOUNDCHECKER(type, name, ubound, lbound) libbase64_boundChecker<type> name(ubound, lbound)
+ #define GETITEM_BOUNDCHECK(loc, name) name.getLocation(loc)
+
+ #ifdef LIBBASE64CODECOVERAGE
+ #define LIBBASE64CODECOVERAGEBRANCH { static bool f_codeCoverage_ = false; if (f_codeCoverage_ == false){ libbase64::getCoverageHits<STRINGTYPE, CHARTYPE, UCHARTYPE, SAFETY>(true); f_codeCoverage_ = true; } }
+ #endif
+#endif
+#ifndef LIBBASE64CODECOVERAGE
+ #define LIBBASE64CODECOVERAGEBRANCH (void)0
+#endif
+
+//predictive branching optimizations
+#ifdef __GNUC__
+ #define LIBBASE64_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
+ #if (LIBBASE64_GCC_VERSION >= 29600)
+ #define libbase64_likely(x) __builtin_expect((long)((bool)(x)),1)
+ #define libbase64_unlikely(x) __builtin_expect((long)((bool)(x)),0)
+ #endif
+#endif
+#ifndef libbase64_likely
+ #define libbase64_likely(x) x
+ #define libbase64_unlikely(x) x
+#endif
+
+
+namespace libbase64 {
+ #ifdef LIBBASE64CODECOVERAGE //Gets the number of branches that has been made
+ template<class STRINGTYPE, typename CHARTYPE, typename UCHARTYPE, bool SAFETY>
+ static size_t getCoverageHits(bool inc){
+ static size_t hits = 0;
+ if (inc) ++hits;
+ return hits;
+ }
+ #endif
+
+ //characters used in convertions
+ namespace libbase64_characters {
+ template<typename T>
+ inline static const T * getChar64(void){
+ static const T char64s[64] = {
+ (T)'A', (T)'B', (T)'C', (T)'D', (T)'E', (T)'F', (T)'G', (T)'H', (T)'I', (T)'J', (T)'K', (T)'L', (T)'M',
+ (T)'N', (T)'O', (T)'P', (T)'Q', (T)'R', (T)'S', (T)'T', (T)'U', (T)'V', (T)'W', (T)'X', (T)'Y', (T)'Z',
+ (T)'a', (T)'b', (T)'c', (T)'d', (T)'e', (T)'f', (T)'g', (T)'h', (T)'i', (T)'j', (T)'k', (T)'l', (T)'m',
+ (T)'n', (T)'o', (T)'p', (T)'q', (T)'r', (T)'s', (T)'t', (T)'u', (T)'v', (T)'w', (T)'x', (T)'y', (T)'z',
+ (T)'0', (T)'1', (T)'2', (T)'3', (T)'4', (T)'5', (T)'6', (T)'7', (T)'8', (T)'9', (T)'+', (T)'/'
+ };
+ return char64s;
+ }
+
+ template<typename T>
+ inline static T getChar(unsigned char bin){
+ CREATEBOUNDCHECKER(T, char64bounds, getChar64<T>(), getChar64<T>() + 64);
+ return GETITEM_BOUNDCHECK(getChar64<T>() + bin, char64bounds);
+ }
+
+ template<typename T>
+ inline static T toBinary(T c) {
+ static T binaryConvert[80] = {62,48,49,50,63,52,53,54,55,56,57,58,59,60,61,249,250,251,252,253,254,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
+ CREATEBOUNDCHECKER(T, binaryConvertsbounds, binaryConvert, binaryConvert + 80);
+ return GETITEM_BOUNDCHECK(binaryConvert + c - 43, binaryConvertsbounds);
+ }
+
+ template<typename T>
+ static inline T & emptyString(void){
+ static T t;
+ return t;
+ }
+ }
+
+ namespace libbase64_Calculator {
+ inline static size_t getEncodingSize(size_t bytes){
+ return (bytes + 2 - ((bytes + 2) % 3)) / 3 * 4;
+ }
+ inline static size_t getDecodingSize(size_t res){
+ return res * 3 / 4;
+ }
+ }
+
+
+ /**
+ * Encodes data into a base64 string of STRINGTYPE
+ */
+ template<class STRINGTYPE, typename CHARTYPE, typename UCHARTYPE, bool SAFETY>
+ static STRINGTYPE encode(const unsigned char * binary, size_t bytes){
+ CREATEBOUNDCHECKER(unsigned char, binarybounds, binary, binary + bytes);
+
+ //make sure that there is actually something to encode
+ if (SAFETY){
+ if (libbase64_unlikely(bytes == 0)){
+ LIBBASE64CODECOVERAGEBRANCH;
+ return libbase64_characters::emptyString<STRINGTYPE>();
+ }
+ }
+
+ //calculate length and how misaligned it is
+ size_t misaligned = bytes % 3;
+ STRINGTYPE result;
+ result.reserve(libbase64_Calculator::getEncodingSize(bytes));
+
+ //do all of the ones that are 3 byte aligned
+ for (size_t i = 0, aligned((bytes - misaligned) / 3); i < aligned; ++i){
+ LIBBASE64CODECOVERAGEBRANCH;
+ result += libbase64_characters::getChar<CHARTYPE>((GETITEM_BOUNDCHECK(binary, binarybounds) & 0xFC) >> 2);
+ result += libbase64_characters::getChar<CHARTYPE>(((GETITEM_BOUNDCHECK(binary, binarybounds) & 0x03) << 4) + ((GETITEM_BOUNDCHECK(binary + 1, binarybounds) & 0xF0) >> 4));
+ result += libbase64_characters::getChar<CHARTYPE>(((GETITEM_BOUNDCHECK(binary + 1, binarybounds) & 0x0F) << 2) + ((GETITEM_BOUNDCHECK(binary + 2, binarybounds) & 0xC0) >> 6));
+ result += libbase64_characters::getChar<CHARTYPE>(GETITEM_BOUNDCHECK(binary + 2, binarybounds) & 0x3F);
+ binary += 3;
+ }
+
+ //handle any additional characters at the end of it
+ if (libbase64_likely(misaligned != 0)){
+ LIBBASE64CODECOVERAGEBRANCH;
+ //copy the rest into a temporary buffer, need it for the null terminators
+ unsigned char temp[3] = { '\0', '\0', '\0' };
+ for (unsigned char i = 0; i < (unsigned char)misaligned; ++i){
+ LIBBASE64CODECOVERAGEBRANCH;
+ temp[i] = GETITEM_BOUNDCHECK(binary++, binarybounds);
+ }
+
+ //now do the final three bytes
+ result += libbase64_characters::getChar<CHARTYPE>((temp[0] & 0xFC) >> 2);
+ result += libbase64_characters::getChar<CHARTYPE>(((temp[0] & 0x03) << 4) + ((temp[1] & 0xF0) >> 4));
+ if (misaligned == 2){
+ LIBBASE64CODECOVERAGEBRANCH;
+ result += libbase64_characters::getChar<CHARTYPE>(((temp[1] & 0x0F) << 2) + ((temp[2] & 0xC0) >> 6));
+ } else {
+ LIBBASE64CODECOVERAGEBRANCH;
+ result += (CHARTYPE)'=';
+ }
+ result += (CHARTYPE)'=';
+ } else {
+ LIBBASE64CODECOVERAGEBRANCH;
+ }
+
+ LIBBASE64_ASSERT(libbase64_Calculator::getEncodingSize(bytes) == result.length(), "Reserve wasn't the correct guess");
+ return result;
+ }
+
+ template<class STRINGTYPE, typename CHARTYPE, typename UCHARTYPE, bool SAFETY>
+ static std::string decode(const STRINGTYPE & encoded){
+ //check length to be sure its acceptable for base64
+ const size_t length = encoded.length();
+
+ if (SAFETY){
+ if (libbase64_unlikely((length % 4) != 0)){
+ LIBBASE64CODECOVERAGEBRANCH;
+ return libbase64_characters::emptyString<std::string>();
+ }
+ if (libbase64_unlikely(length == 0)){
+ LIBBASE64CODECOVERAGEBRANCH;
+ return libbase64_characters::emptyString<std::string>();
+ }
+
+ //check to be sure there aren't odd characters or characters in the wrong places
+ size_t pos = encoded.find_first_not_of(libbase64_characters::getChar64<CHARTYPE>());
+ if (libbase64_unlikely(pos != STRINGTYPE::npos)){
+ LIBBASE64CODECOVERAGEBRANCH;
+ if (libbase64_unlikely(encoded[pos] != (CHARTYPE)'=')){
+ LIBBASE64CODECOVERAGEBRANCH; //INVALID_CHAR
+ #ifdef LIBBASE64_THROW_STD_INVALID_ARGUMENT
+ throw std::invalid_argument("invalid character in base64");
+ #else
+ return libbase64_characters::emptyString<std::string>();
+ #endif
+ }
+ if (pos != length - 1){
+ LIBBASE64CODECOVERAGEBRANCH;
+ if (libbase64_unlikely(pos != length - 2)){
+ LIBBASE64CODECOVERAGEBRANCH; //EQUAL_WRONG_PLACE
+ #ifdef LIBBASE64_THROW_STD_INVALID_ARGUMENT
+ throw std::invalid_argument("equal sign in wrong place in base64");
+ #else
+ return libbase64_characters::emptyString<std::string>();
+ #endif
+ }
+ if (libbase64_unlikely(encoded[pos + 1] != (CHARTYPE)'=')){
+ LIBBASE64CODECOVERAGEBRANCH; //EQUAL_NOT_LAST
+ #ifdef LIBBASE64_THROW_STD_INVALID_ARGUMENT
+ throw std::invalid_argument("invalid character in base64");
+ #else
+ return libbase64_characters::emptyString<std::string>();
+ #endif
+ }
+ LIBBASE64CODECOVERAGEBRANCH;
+ } else {
+ LIBBASE64CODECOVERAGEBRANCH;
+ }
+ } else {
+ LIBBASE64CODECOVERAGEBRANCH;
+ }
+ }
+
+ const CHARTYPE * runner = encoded.data();
+ const CHARTYPE * end = runner + encoded.length();
+ CREATEBOUNDCHECKER(CHARTYPE, encodedbounds, runner, end);
+ size_t aligned = length / 4; //don't do the last ones as they might be = padding
+ std::string result;
+ --aligned;
+ result.reserve(libbase64_Calculator::getDecodingSize(length));
+
+ //first do the ones that can not have any padding
+ for (unsigned int i = 0; i < aligned; ++i){
+ const CHARTYPE second = libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner + 1, encodedbounds));
+ const CHARTYPE third = libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner + 2, encodedbounds));
+ result += (libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner, encodedbounds)) << 2) + ((second & 0x30) >> 4);
+ result += ((second & 0xf) << 4) + ((third & 0x3c) >> 2);
+ result += ((third & 0x3) << 6) + libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner + 3, encodedbounds));
+ runner += 4;
+ }
+
+ //now do the ones that might have padding, the first two characters can not be padding, so do them quickly
+ const CHARTYPE second = libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner + 1, encodedbounds));
+ result += (libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner + 0, encodedbounds)) << 2) + ((second & 0x30) >> 4);
+ runner += 2;
+ if ((runner != end) && (*runner != (CHARTYPE)'=')){ //not two = pads
+ LIBBASE64CODECOVERAGEBRANCH;
+ const CHARTYPE third = libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner, encodedbounds));
+ result += ((second & 0xf) << 4) + ((third & 0x3c) >> 2);
+ ++runner;
+ if ((runner != end) && (*runner != (CHARTYPE)'=')){ //no padding
+ LIBBASE64CODECOVERAGEBRANCH;
+ result += ((third & 0x3) << 6) + libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner, encodedbounds));
+ } else {
+ LIBBASE64CODECOVERAGEBRANCH;
+ }
+ } else {
+ LIBBASE64CODECOVERAGEBRANCH;
+ }
+
+ LIBBASE64_ASSERT(libbase64_Calculator::getDecodingSize(length) >= result.length(), "Reserve wasn't the correct guess, too small");
+ LIBBASE64_ASSERT((result.length() <= 3) || (libbase64_Calculator::getDecodingSize(length) > result.length() - 3), "Reserve wasn't the correct guess, too big");
+ return result;
+ }
+}
+
+#endif
1,088 ext/libjson/Dependencies/mempool++/mempool.h
@@ -0,0 +1,1088 @@
+#ifndef mempool___mempool_h
+#define mempool___mempool_h
+
+
+/*
+ * This is where you may alter options to give mempool++
+ */
+
+//#define MEMPOOL_DEBUGGING //Causes mempool++ to spit out what it's doing to the console
+//#define MEMPOOL_ASSERTS //Causes mempool++ to check what it's doing and look for impossible cases
+#define MEMPOOL_OVERFLOW 3.0f / 4.0f //Changes how full a pool is before going to fallbacks
+//#define MEMPOOL_DETERMINE_DISTRIBUTION //Allows mempool++ to automatically give you the best distribution
+#define MEMPOOL_DETERMINE_SCALAR 5.0f / 3.0f //Gives you this times the max number at any given time from distribution
+#define MEMPOOL_FALLBACK_DEPTH 3
+//#define MEMPOOL_PERFORMANCE_DEBUGGING
+//#define private public
+
+
+//version info
+#define __MEMPOOL_MAJOR__ 1
+#define __MEMPOOL_MINOR__ 2
+#define __MEMPOOL_PATCH__ 0
+#define __MEMPOOL_VERSION__ (__MEMPOOL_MAJOR__ * 10000 + __MEMPOOL_MINOR__ * 100 + __MEMPOOL_PATCH__)
+
+/*
+ * This is where special function / macro for special options are
+ */
+
+#ifdef MEMPOOL_DEBUGGING
+ #include <iostream>
+ #define MEMPOOL_DEBUG(x) std::cout << x << std::endl;
+#else
+ #define MEMPOOL_DEBUG(x)
+#endif
+
+#ifdef MEMPOOL_ASSERTS
+ #include <iostream>
+ #define MEMPOOL_ASSERT(condition) if (pool_unlikely(!(condition))){ std::cout << #condition << " isn't true" << std::endl; }
+ #define MEMPOOL_ASSERT2(condition, out) if (pool_unlikely(!(condition))){ std::cout << out << std::endl; }
+#else
+ #define MEMPOOL_ASSERT(condition)
+ #define MEMPOOL_ASSERT2(condition, out)
+#endif
+
+#ifdef MEMPOOL_PERFORMANCE_DEBUGGING
+ #include <iostream>
+ #include <sstream>
+ #include <string>
+ #define MEMPOOL_PERFORMANCE_DEBUG(x) std::cout << x << std::endl;
+#else
+ #define MEMPOOL_PERFORMANCE_DEBUG(x)
+#endif
+
+
+
+/*
+ * This is where compiler-specific code goes
+ */
+#ifdef __GNUC__
+ #if (__GNUC__ >= 3)
+ #define POOL_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+ #else
+ #define POOL_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
+ #endif
+
+ #if (POOL_GCC_VERSION >= 40300)
+ #define pool_hot pool_nothrow __attribute__ ((hot))
+ #else
+ #define pool_hot pool_nothrow
+ #endif
+
+ #if (POOL_GCC_VERSION >= 29600)
+ #define pool_likely(x) __builtin_expect((long)((bool)(x)),1)
+ #define pool_unlikely(x) __builtin_expect((long)((bool)(x)),0)
+ #else
+ #define pool_likely(x) x
+ #define pool_unlikely(x) x
+ #endif
+
+ #define pool_nothrow throw()
+#else
+ #define pool_hot pool_nothrow
+ #define pool_likely(x) x
+ #define pool_unlikely(x) x
+ #define pool_nothrow
+#endif
+
+#include <cstring>
+
+/*
+ * This is where the classes are
+ */
+
+//Callbacks for fallback if the pool is out of space
+class mempool_callbacks {
+public:
+ typedef void * (*mallocer_t)(size_t);
+ typedef void(*freer_t)(void *);
+ typedef void * (*reallocer_t)(void *, size_t);
+
+ //Allows the user to alter where the fallbacks point to
+ static inline void set(mallocer_t mallocer, reallocer_t reallocer, freer_t freer) pool_nothrow {
+ get_instance()._malloc = mallocer;
+ get_instance()._free = freer;
+ get_instance()._realloc = reallocer;
+ }
+
+ //allocates memory
+ static inline void * allocate(size_t size) pool_nothrow {
+ MEMPOOL_DEBUG("Returing malloced memory:" << size << " bytes");
+ return get_instance()._malloc(size);
+ }
+
+ //frees memory
+ static inline void deallocate(void * ptr) pool_nothrow {
+ MEMPOOL_DEBUG("Freeing malloced memory: " << ptr);
+ get_instance()._free(ptr);
+ }
+
+ static inline void * reallocate(void * ptr, size_t size) pool_nothrow {
+ MEMPOOL_DEBUG("Reallocating memory: " << ptr << " to " << size << " bytes");
+ return get_instance()._realloc(ptr, size);
+ }
+private:
+ //Retrieves a Meyers singleton
+ static inline mempool_callbacks & get_instance(void) pool_nothrow {
+ static mempool_callbacks _single(std::malloc, std::realloc, std::free);
+ return _single;
+ }
+
+ //The constructor
+ inline mempool_callbacks(mallocer_t mallocer, reallocer_t reallocer, freer_t freer) :
+ _malloc(mallocer),
+ _free(freer),
+ _realloc(reallocer){
+ }
+
+ //not copyable
+ mempool_callbacks & operator = (const mempool_callbacks & other);
+ mempool_callbacks(const mempool_callbacks & other);
+
+ //member callbacks
+ mallocer_t _malloc;
+ reallocer_t _realloc;
+ freer_t _free;
+};
+
+//The workhorse of the templates library, a class that holds a pool that it allocates memory from
+template <typename T, size_t size>
+class object_memory_pool; //forward declaration
+
+template <size_t bytes, size_t size>
+class memory_pool_no_fullflag { //forward declaration
+public:
+ memory_pool_no_fullflag<bytes, size>():
+ _link(NULL),
+ current(0),
+ depth(0),
+ threshold((size_t)((float)size * (MEMPOOL_OVERFLOW))),
+ memoryPool_end(memoryPool_start + (size * bytes)),
+ used_end(used_start + size),
+ runningPointer(used_start)
+ {
+ std::memset(used_start, 0, size * sizeof(bool));
+ }
+
+ virtual ~memory_pool_no_fullflag(void){
+ if (_link){
+ _link -> ~memory_pool_no_fullflag();
+ mempool_callbacks::deallocate(_link);
+ }
+ }
+
+ inline size_t load(void) const pool_nothrow {
+ return current;
+ }
+
+ inline void * allocate(void) pool_hot {
+ if (void * res = allocate_nofallback()){
+ return res;
+ }
+ return _link_allocate();
+ }
+
+ inline void deallocate(void * ptr) pool_hot {
+ if (memory_pool_no_fullflag<bytes, size> * container = contains(ptr)){
+ container -> deallocate_nofallback(ptr);
+ } else {
+ mempool_callbacks::deallocate(ptr);
+ }
+ }
+
+ void * allocate_nofallback() pool_hot {
+ if (!(*runningPointer)) return _return_current();
+ if (++runningPointer >= used_end) runningPointer = used_start;
+ if (current < threshold){
+ //make sure it doesnt loop around infinity so point it to itself
+ const bool * position = runningPointer;
+ do {
+ if (!(*runningPointer)) return _return_current();
+ if (++runningPointer >= used_end) runningPointer = used_start;
+ } while (position != runningPointer);
+ MEMPOOL_ASSERT2(false, "Got to impossible code location");
+ }
+
+ MEMPOOL_DEBUG("Returing null");
+ return NULL;
+ }
+
+ void deallocate_nofallback(void * ptr) pool_hot {
+ MEMPOOL_ASSERT2(current, "current not positive");
+ --current;
+ MEMPOOL_DEBUG("Freeing slot " << ((char*)ptr - memoryPool_start) / bytes);
+ MEMPOOL_DEBUG(" pointer=" << ptr);
+ MEMPOOL_ASSERT2((((char*)ptr - memoryPool_start) / bytes) < size, "Freeing slot " << (((char*)ptr - memoryPool_start) / bytes) << " in a pool with only " << size << " items");
+ MEMPOOL_ASSERT2(used_start[((char*)ptr - memoryPool_start) / bytes], "Freeing " << ptr << " and it's already been freed");
+ used_start[(((char*)ptr - memoryPool_start) / bytes)] = false;
+ }
+
+ inline memory_pool_no_fullflag<bytes, size> * contains(void * ptr) pool_hot {
+ if ((ptr >= memoryPool_start) && (ptr < memoryPool_end)) return this;
+ return (_link) ? _link -> contains(ptr) : NULL;
+ }
+
+ #ifdef MEMPOOL_PERFORMANCE_DEBUGGING
+ const char * const getName(void){ return "memory_pool_no_fullflag"; }
+
+ const char * getDepth(){
+ static const char * depths[15] = {
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ "- ",
+ };
+ if (depth > 14) return depths[14];
+ return depths[depth];
+ }
+
+ std::string dump(void){
+ std::stringstream output;
+ output << getDepth() << getName() << "<" << bytes << ", " << size << ">: " << (void*)this << std::endl;
+ output << getDepth() << "Currently holding: " << current << " items." << std::endl;
+ //_____
+ output << getDepth() << "+";
+ for(int i = 0; i < 78; ++i){
+ output << "_";
+ }
+ output << "+" << std::endl << getDepth() << "|";
+
+ //Fill in
+ int i;
+ for(i = 0; i < size; ++i){
+ if ((i % 80 == 0) && (i != 0)){
+ output << "|" << std::endl << getDepth() << "|";
+ }
+ if (i == (runningPointer - used_start)){
+ if (used_start[i]){
+ output << "R";
+ } else {
+ output << "P";
+ }
+ } else if (used_start[i]){
+ output << "X";
+ } else {
+ output << " ";
+ }
+ }
+
+ for(; (i % 80) != 0; ++i){
+ output << "+";
+ }
+
+ //-------
+ output << getDepth() << "+";
+ for(i = 0; i < 78; ++i){
+ output << "-";
+ }
+ output << "+";
+ if (_link){
+ output << "----+" << std::endl;
+ }
+ return output.str();
+ }
+ #endif
+protected:
+ //copy ctors and assignment operator
+ memory_pool_no_fullflag & operator = (const memory_pool_no_fullflag & other);
+ memory_pool_no_fullflag(const memory_pool_no_fullflag & other);
+
+ inline void * _return_current(void) pool_hot {
+ *runningPointer = true;
+ ++current;
+ MEMPOOL_DEBUG("Returning slot " << runningPointer - used_start << " at depth " << depth);
+ MEMPOOL_DEBUG(" memoryPool_start=" << (void*)memoryPool_start);
+ MEMPOOL_DEBUG(" memoryPool_end =" << (void*)memoryPool_end);
+ MEMPOOL_DEBUG(" return value =" << (void*)(memoryPool_start + ((runningPointer - used_start) * bytes)));
+ MEMPOOL_ASSERT2(((memoryPool_start + ((runningPointer - used_start) * bytes))) < memoryPool_end, "Returning pointer outside the high end of the pool");
+ MEMPOOL_ASSERT2(((memoryPool_start + ((runningPointer - used_start) * bytes))) >= memoryPool_start, "Returning pointer outside the low end of the pool");
+ const bool * const pre = runningPointer;
+ if (++runningPointer >= used_end) runningPointer = used_start;
+ return memoryPool_start + ((pre - used_start) * bytes);
+ }
+
+ void * _link_allocate(void) pool_nothrow {
+ if (depth >= MEMPOOL_FALLBACK_DEPTH) return mempool_callbacks::allocate(bytes);
+ if (!_link){
+ _link = new(mempool_callbacks::allocate(sizeof(memory_pool_no_fullflag<bytes, size>))) memory_pool_no_fullflag<bytes, size>();
+ _link -> depth = depth + 1;
+ }
+ return _link -> allocate();
+ }
+
+ size_t current; //The current number of items in the pool
+ size_t threshold; //The number of items in the pool before it starts using fallback
+ char memoryPool_start[size * bytes]; //The memory pool
+ char * memoryPool_end; //The end of the memory pool
+ bool used_start[size]; //A pool to know whether or not an item is currently used
+ bool * used_end; //The end of the boolean flags
+ bool * runningPointer; //A pointer that loops, keeping an eye on what is taken and what isn't
+ memory_pool_no_fullflag<bytes, size> * _link; //Creates a linked list when expanding
+ size_t depth;
+};
+
+template <size_t bytes, size_t size>
+class memory_pool : public memory_pool_no_fullflag<bytes, size> {
+public:
+ memory_pool<bytes, size>() :
+ memory_pool_no_fullflag<bytes, size>(),
+ _full(false){}
+
+ virtual ~memory_pool(void){}
+
+ inline void * allocate(void) pool_hot {
+ if (_full) return mempool_callbacks::allocate(bytes);
+ return memory_pool_no_fullflag<bytes, size>::allocate();
+ }
+
+ inline void deallocate(void * ptr) pool_hot {
+ _full = false;
+ return memory_pool_no_fullflag<bytes, size>::deallocate(ptr);
+ }
+
+ #ifdef MEMPOOL_PERFORMANCE_DEBUGGING
+ const char * const getName(void){ return "memory_pool"; }
+ #endif
+private:
+ //copy ctors and assignment operator
+ memory_pool & operator = (const memory_pool & other);
+ memory_pool(const memory_pool & other);
+
+ bool _full;
+
+ template <typename T, size_t s> friend class object_memory_pool;
+};
+
+
+//A memory pool for a specific type of object
+#define new_object(pool, ctor) new (pool.allocate_noctor()) ctor //allows user to call a specific ctor on the object [ new_object(mypool, T(x, y)) ]
+template <typename T, size_t size>
+class object_memory_pool {
+public:
+ inline size_t load(void) const pool_nothrow {
+ return _pool.load();
+ }
+
+ virtual ~object_memory_pool() pool_nothrow { } //so that it can be overloaded
+
+ inline T * allocate(void) pool_hot { return new (_pool.allocate()) T(); }
+ inline void * allocate_noctor(void) pool_nothrow { return _pool.allocate(); }
+
+ inline void deallocate(T * ptr) pool_hot {
+ ptr -> ~T();
+ _pool.deallocate(ptr);
+ }
+
+ inline memory_pool<sizeof(T), size> * contains(T * ptr) const pool_hot {
+ return _pool.contains((void*)ptr);
+ }
+
+ inline T * alloc_nofallback() pool_hot {
+ if (void * res = _pool.allocate_nofallback()){
+ return new (res) T();
+ }
+ return NULL;
+ }
+
+ inline void deallocate_nofallback(T * ptr) pool_hot {
+ ptr -> ~T();
+ _pool.deallocate_nofallback(ptr);
+ }
+ #ifdef MEMPOOL_PERFORMANCE_DEBUGGING
+ const std::string dump(void){ return _pool.dump(); }
+ #endif
+private:
+ memory_pool<sizeof(T), size> _pool;
+};
+
+
+#define MEMPOOL_TEMPLATE_PAIR(x) size_t bytes ## x , size_t count ## x
+#define MEMPOOL_ALLOC_CHECK(x) if (bytes <= bytes ## x ){ if (void * res = (_pool ## x).allocate_nofallback()) return res; }
+#define MEMPOOL_DEALLOC_CHECK(x) if (memory_pool_no_fullflag< bytes ## x , count ## x > * container = (_pool ## x).contains(ptr)){ container -> deallocate_nofallback(ptr); return; }
+#define MEMPOOL_MEMBER_POOL(x) memory_pool< bytes ## x , count ## x > _pool ## x;
+
+#define MEMPOOL_REALLOC_CHECK(x)\
+ if (memory_pool_no_fullflag< bytes ## x , count ## x > * container = (_pool ## x).contains(ptr)){\
+ if (bytes <= bytes ## x) return ptr;\
+ void * newvalue = allocate(bytes);\
+ std::memcpy(newvalue, ptr, bytes ## x);\
+ container -> deallocate_nofallback(ptr);\
+ return newvalue;\
+ }
+
+
+#ifdef MEMPOOL_DETERMINE_DISTRIBUTION
+ #include <map>
+ #include <iostream>
+ #define MEMPOOL_ALLOC_METHOD(number, code)\
+ bucket_pool_ ## number (void) : _profile_on_delete(0) { }\
+ ~bucket_pool_ ## number (void) { \
+ if (_profile_on_delete){ \
+ dump_atonce(_profile_on_delete, _profile_on_delete / 40); \
+ dump_template(_profile_on_delete); \
+ } \
+ }\
+ void * allocate(size_t bytes) pool_hot {\
+ if (mapping.find(bytes) != mapping.end()){\
+ ++mapping[bytes];\
+ ++current_mapping[bytes];\
+ if (current_mapping[bytes] > max_mapping[bytes]) max_mapping[bytes] = current_mapping[bytes];\
+ } else {\
+ mapping[bytes] = 1;\
+ max_mapping[bytes] = 1;\
+ current_mapping[bytes] = 1;\
+ }\
+ void * res = mempool_callbacks::allocate(bytes);\
+ mem_mapping[res] = bytes;\
+ return res;\
+ }
+ #define MEMPOOL_DEALLOC_METHOD(code)\
+ void deallocate(void * ptr) pool_hot {\
+ --current_mapping[mem_mapping[ptr]];\
+ mem_mapping.erase(ptr);\
+ mempool_callbacks::deallocate(ptr);\
+ }
+
+ #define MEMPOOL_ANALYZERS(macro_count)\
+ inline size_t _max(size_t one, size_t two){ return (one > two) ? one : two; }\
+ void dump_total(size_t max, size_t sep = 16, size_t tlen = 30){\
+ std::cout << "-------- Total --------" << std::endl;\
+ size_t max_amount = 0;\
+ for(size_t i = 0; i < max;){\
+ size_t amount = 0;\
+ for(size_t j = 0; j < sep; ++j, ++i){\
+ if (mapping.find(i) != mapping.end()){\
+ amount += mapping[i];\
+ }\
+ }\
+ if (amount > max_amount) max_amount = amount;\
+ }\
+ float scalar = ((float)max_amount) / ((float)tlen);\
+ \
+ for(size_t i = 0; i < max;){\
+ size_t amount = 0;\
+ for(size_t j = 0; j < sep; ++j, ++i){\
+ if (mapping.find(i) != mapping.end()){\
+ amount += mapping[i];\
+ }\
+ }\
+ \
+ if (i < 10) std::cout << ' ';\
+ if (i < 100) std::cout << ' ';\
+ if (i < 1000) std::cout << ' ';\
+ if (i < 10000) std::cout << ' ';\
+ std::cout << i << ':';\
+ \
+ for(size_t j = 0; j < (size_t)((float)amount / scalar); ++j){\
+ std::cout << '*';\
+ }\
+ std::cout << '(' << amount << ')' << std::endl;\
+ }\
+ }\
+ \
+ void dump_atonce(size_t max, size_t sep = 16, size_t tlen = 30){\
+ std::cout << "------ Distribution for \"" << _str << "\" ------" << std::endl;\
+ size_t max_amount = 0;\
+ for(size_t i = 0; i < max;){\
+ size_t amount = 0;\
+ for(size_t j = 0; j < sep; ++j, ++i){\
+ if (max_mapping.find(i) != max_mapping.end()){\
+ amount += max_mapping[i];\
+ }\
+ }\
+ if (amount > max_amount) max_amount = amount;\
+ }\
+ float scalar = ((float)max_amount) / ((float)tlen);\
+ \
+ for(size_t i = 0; i < max;){\
+ size_t amount = 0;\
+ for(size_t j = 0; j < sep; ++j, ++i){\
+ if (max_mapping.find(i) != max_mapping.end()){\
+ amount += max_mapping[i];\
+ }\
+ }\
+ \
+ if (i < 10) std::cout << ' ';\
+ if (i < 100) std::cout << ' ';\
+ if (i < 1000) std::cout << ' ';\
+ if (i < 10000) std::cout << ' ';\
+ std::cout << i << ':';\
+ \
+ for(size_t j = 0; j < (size_t)((float)amount / scalar); ++j){\
+ std::cout << '*';\
+ }\
+ std::cout << '(' << amount << ')' << std::endl;\
+ }\
+ }\
+ \
+ void dump_template(size_t max){\
+ std::cout << "Recommended Template for \"" << _str << "\" = ";\
+ size_t total_at_once = 0;\
+ size_t highest = 0;\
+ for(size_t i = 0; i < max; ++i){\
+ if (max_mapping.find(i) != max_mapping.end()){\
+ total_at_once += max_mapping[i];\
+ highest = i;\
+ }\
+ }\
+ \
+ size_t count = 0;\
+ size_t total_at_once_part = total_at_once / macro_count;\
+ size_t current = 0;\
+ size_t totalsofar = 0;\
+ std::cout << '<';\
+ for(size_t i = 0; ((i < max) && (count < (macro_count -1))); ++i){\
+ if (max_mapping.find(i) != max_mapping.end()){\
+ current += max_mapping[i];\
+ totalsofar += max_mapping[i];\
+ if (current > total_at_once_part){\
+ std::cout << (i - 1) << ", " << (size_t)(((float)current - max_mapping[i]) * (MEMPOOL_DETERMINE_SCALAR)) << ", ";\
+ current = max_mapping[i];\
+ ++count;\
+ }\
+ }\
+ }\
+ std::cout << max << ", " << _max((size_t)((float)(total_at_once - totalsofar) * (MEMPOOL_DETERMINE_SCALAR)), total_at_once_part / 2) << '>' << std::endl;\
+ }\
+ \
+ inline void profile_on_delete(size_t var, const std::string & str){ _profile_on_delete = var; _str = str; }
+
+ #define MEMPOOL_MEMBERS(code)\
+ std::map<size_t, size_t> mapping;\
+ std::map<size_t, size_t> current_mapping;\
+ std::map<size_t, size_t> max_mapping;\
+ std::map<void *, size_t> mem_mapping;\
+ size_t _profile_on_delete;\
+ std::string _str;
+ #define MEMPOOL_LOAD(number, code) inline size_t * load(void) const pool_nothrow { static size_t _load[number] = {0}; return &_load[0]; }
+#else
+ #define MEMPOOL_ALLOC_METHOD(number, code)\
+ void * allocate(size_t bytes) pool_hot {\
+ code\
+ return mempool_callbacks::allocate(bytes);\
+ }
+ #define MEMPOOL_DEALLOC_METHOD(code)\
+ void deallocate(void * ptr) pool_hot {\
+ code\
+ mempool_callbacks::deallocate(ptr);\
+ }
+ #define MEMPOOL_ANALYZERS(macro_count)
+ #define MEMPOOL_MEMBERS(code) code
+ #define MEMPOOL_LOAD(number, code) inline size_t * load(void) const pool_nothrow { static size_t _load[number]; code return &_load[0]; }
+#endif
+
+template<
+MEMPOOL_TEMPLATE_PAIR(1),
+MEMPOOL_TEMPLATE_PAIR(2)>
+class bucket_pool_2 {
+public:
+ MEMPOOL_ALLOC_METHOD(
+ 2,
+ MEMPOOL_ALLOC_CHECK(1)
+ MEMPOOL_ALLOC_CHECK(2)
+ )
+ void * reallocate(void * ptr, size_t bytes){
+ MEMPOOL_REALLOC_CHECK(1)
+ MEMPOOL_REALLOC_CHECK(2)
+ }
+ MEMPOOL_LOAD(
+ 2,
+ _load[0] = _pool1.load();
+ _load[1] = _pool2.load();
+ )
+ MEMPOOL_DEALLOC_METHOD(
+ MEMPOOL_DEALLOC_CHECK(1)
+ MEMPOOL_DEALLOC_CHECK(2)
+ )
+ MEMPOOL_ANALYZERS(2)
+private:
+ MEMPOOL_MEMBERS(
+ MEMPOOL_MEMBER_POOL(1)
+ MEMPOOL_MEMBER_POOL(2)
+ )
+};
+
+template<
+MEMPOOL_TEMPLATE_PAIR(1),
+MEMPOOL_TEMPLATE_PAIR(2),
+MEMPOOL_TEMPLATE_PAIR(3)>
+class bucket_pool_3 {
+public:
+ MEMPOOL_ALLOC_METHOD(
+ 3,
+ MEMPOOL_ALLOC_CHECK(1)
+ MEMPOOL_ALLOC_CHECK(2)
+ MEMPOOL_ALLOC_CHECK(3)
+ )
+ void * reallocate(void * ptr, size_t bytes){
+ MEMPOOL_REALLOC_CHECK(1)
+ MEMPOOL_REALLOC_CHECK(2)
+ MEMPOOL_REALLOC_CHECK(3)
+ return mempool_callbacks::reallocate(ptr, bytes);
+ }
+ MEMPOOL_LOAD(
+ 3,
+ _load[0] = _pool1.load();
+ _load[1] = _pool2.load();
+ _load[2] = _pool3.load();
+ )
+ MEMPOOL_DEALLOC_METHOD(
+ MEMPOOL_DEALLOC_CHECK(1)
+ MEMPOOL_DEALLOC_CHECK(2)
+ MEMPOOL_DEALLOC_CHECK(3)
+ )
+ MEMPOOL_ANALYZERS(3)
+private:
+ MEMPOOL_MEMBERS(
+ MEMPOOL_MEMBER_POOL(1)
+ MEMPOOL_MEMBER_POOL(2)
+ MEMPOOL_MEMBER_POOL(3)
+ )
+};
+
+template<
+MEMPOOL_TEMPLATE_PAIR(1),
+MEMPOOL_TEMPLATE_PAIR(2),
+MEMPOOL_TEMPLATE_PAIR(3),
+MEMPOOL_TEMPLATE_PAIR(4)>
+class bucket_pool_4 {
+public:
+ MEMPOOL_ALLOC_METHOD(
+ 4,
+ MEMPOOL_ALLOC_CHECK(1)
+ MEMPOOL_ALLOC_CHECK(2)
+ MEMPOOL_ALLOC_CHECK(3)
+ MEMPOOL_ALLOC_CHECK(4)
+ )
+ void * reallocate(void * ptr, size_t bytes){
+ MEMPOOL_REALLOC_CHECK(1)
+ MEMPOOL_REALLOC_CHECK(2)
+ MEMPOOL_REALLOC_CHECK(3)
+ MEMPOOL_REALLOC_CHECK(4)
+ return mempool_callbacks::reallocate(ptr, bytes);
+ }
+ MEMPOOL_LOAD(
+ 4,
+ _load[0] = _pool1.load();
+ _load[1] = _pool2.load();
+ _load[2] = _pool3.load();
+ _load[3] = _pool4.load();
+ )
+ MEMPOOL_DEALLOC_METHOD(
+ MEMPOOL_DEALLOC_CHECK(1)
+ MEMPOOL_DEALLOC_CHECK(2)
+ MEMPOOL_DEALLOC_CHECK(3)
+ MEMPOOL_DEALLOC_CHECK(4)
+ )
+ MEMPOOL_ANALYZERS(4)
+private:
+ MEMPOOL_MEMBERS(
+ MEMPOOL_MEMBER_POOL(1)
+ MEMPOOL_MEMBER_POOL(2)
+ MEMPOOL_MEMBER_POOL(3)
+ MEMPOOL_MEMBER_POOL(4)
+ )
+};
+
+template<
+MEMPOOL_TEMPLATE_PAIR(1),
+MEMPOOL_TEMPLATE_PAIR(2),
+MEMPOOL_TEMPLATE_PAIR(3),
+MEMPOOL_TEMPLATE_PAIR(4),
+MEMPOOL_TEMPLATE_PAIR(5)>
+class bucket_pool_5 {
+public:
+ MEMPOOL_ALLOC_METHOD(
+ 5,
+ MEMPOOL_ALLOC_CHECK(1)
+ MEMPOOL_ALLOC_CHECK(2)
+ MEMPOOL_ALLOC_CHECK(3)
+ MEMPOOL_ALLOC_CHECK(4)
+ MEMPOOL_ALLOC_CHECK(5)
+ )
+ void * reallocate(void * ptr, size_t bytes){
+ MEMPOOL_REALLOC_CHECK(1)
+ MEMPOOL_REALLOC_CHECK(2)
+ MEMPOOL_REALLOC_CHECK(3)
+ MEMPOOL_REALLOC_CHECK(4)
+ MEMPOOL_REALLOC_CHECK(5)
+ return mempool_callbacks::reallocate(ptr, bytes);
+ }
+ MEMPOOL_LOAD(
+ 5,
+ _load[0] = _pool1.load();
+ _load[1] = _pool2.load();
+ _load[2] = _pool3.load();
+ _load[3] = _pool4.load();
+ _load[4] = _pool5.load();
+ )
+ MEMPOOL_DEALLOC_METHOD(
+ MEMPOOL_DEALLOC_CHECK(1)
+ MEMPOOL_DEALLOC_CHECK(2)
+ MEMPOOL_DEALLOC_CHECK(3)
+ MEMPOOL_DEALLOC_CHECK(4)
+ MEMPOOL_DEALLOC_CHECK(5)
+ )
+ MEMPOOL_ANALYZERS(5)
+private:
+ MEMPOOL_MEMBERS(
+ MEMPOOL_MEMBER_POOL(1)
+ MEMPOOL_MEMBER_POOL(2)
+ MEMPOOL_MEMBER_POOL(3)
+ MEMPOOL_MEMBER_POOL(4)
+ MEMPOOL_MEMBER_POOL(5)
+ )
+};
+
+template<
+MEMPOOL_TEMPLATE_PAIR(1),
+MEMPOOL_TEMPLATE_PAIR(2),
+MEMPOOL_TEMPLATE_PAIR(3),
+MEMPOOL_TEMPLATE_PAIR(4),
+MEMPOOL_TEMPLATE_PAIR(5),
+MEMPOOL_TEMPLATE_PAIR(6)>
+class bucket_pool_6 {
+public:
+ MEMPOOL_ALLOC_METHOD(
+ 6,
+ MEMPOOL_ALLOC_CHECK(1)
+ MEMPOOL_ALLOC_CHECK(2)
+ MEMPOOL_ALLOC_CHECK(3)
+ MEMPOOL_ALLOC_CHECK(4)
+ MEMPOOL_ALLOC_CHECK(5)
+ MEMPOOL_ALLOC_CHECK(6)
+ )
+ void * reallocate(void * ptr, size_t bytes){
+ MEMPOOL_REALLOC_CHECK(1)
+ MEMPOOL_REALLOC_CHECK(2)
+ MEMPOOL_REALLOC_CHECK(3)
+ MEMPOOL_REALLOC_CHECK(4)
+ MEMPOOL_REALLOC_CHECK(5)
+ MEMPOOL_REALLOC_CHECK(6)
+ return mempool_callbacks::reallocate(ptr, bytes);
+ }
+ MEMPOOL_LOAD(
+ 6,
+ _load[0] = _pool1.load();
+ _load[1] = _pool2.load();
+ _load[2] = _pool3.load();
+ _load[3] = _pool4.load();
+ _load[4] = _pool5.load();
+ _load[5] = _pool6.load();
+ )
+ MEMPOOL_DEALLOC_METHOD(
+ MEMPOOL_DEALLOC_CHECK(1)
+ MEMPOOL_DEALLOC_CHECK(2)
+ MEMPOOL_DEALLOC_CHECK(3)
+ MEMPOOL_DEALLOC_CHECK(4)
+ MEMPOOL_DEALLOC_CHECK(5)
+ MEMPOOL_DEALLOC_CHECK(6)
+ )
+ MEMPOOL_ANALYZERS(6)
+private:
+ MEMPOOL_MEMBERS(
+ MEMPOOL_MEMBER_POOL(1)
+ MEMPOOL_MEMBER_POOL(2)
+ MEMPOOL_MEMBER_POOL(3)
+ MEMPOOL_MEMBER_POOL(4)
+ MEMPOOL_MEMBER_POOL(5)
+ MEMPOOL_MEMBER_POOL(6)
+ )
+};
+
+template<
+MEMPOOL_TEMPLATE_PAIR(1),
+MEMPOOL_TEMPLATE_PAIR(2),
+MEMPOOL_TEMPLATE_PAIR(3),
+MEMPOOL_TEMPLATE_PAIR(4),
+MEMPOOL_TEMPLATE_PAIR(5),
+MEMPOOL_TEMPLATE_PAIR(6),
+MEMPOOL_TEMPLATE_PAIR(7)>
+class bucket_pool_7 {
+public:
+ MEMPOOL_ALLOC_METHOD(
+ 7,
+ MEMPOOL_ALLOC_CHECK(1)
+ MEMPOOL_ALLOC_CHECK(2)
+ MEMPOOL_ALLOC_CHECK(3)
+ MEMPOOL_ALLOC_CHECK(4)
+ MEMPOOL_ALLOC_CHECK(5)
+ MEMPOOL_ALLOC_CHECK(6)
+ MEMPOOL_ALLOC_CHECK(7)
+ )
+ void * reallocate(void * ptr, size_t bytes){
+ MEMPOOL_REALLOC_CHECK(1)
+ MEMPOOL_REALLOC_CHECK(2)
+ MEMPOOL_REALLOC_CHECK(3)
+ MEMPOOL_REALLOC_CHECK(4)
+ MEMPOOL_REALLOC_CHECK(5)
+ MEMPOOL_REALLOC_CHECK(6)
+ MEMPOOL_REALLOC_CHECK(7)
+ return mempool_callbacks::reallocate(ptr, bytes);
+ }
+ MEMPOOL_LOAD(
+ 7,
+ _load[0] = _pool1.load();
+ _load[1] = _pool2.load();
+ _load[2] = _pool3.load();
+ _load[3] = _pool4.load();
+ _load[4] = _pool5.load();
+ _load[5] = _pool6.load();
+ _load[6] = _pool7.load();
+ )
+ MEMPOOL_DEALLOC_METHOD(
+ MEMPOOL_DEALLOC_CHECK(1)
+ MEMPOOL_DEALLOC_CHECK(2)
+ MEMPOOL_DEALLOC_CHECK(3)
+ MEMPOOL_DEALLOC_CHECK(4)
+ MEMPOOL_DEALLOC_CHECK(5)
+ MEMPOOL_DEALLOC_CHECK(6)
+ MEMPOOL_DEALLOC_CHECK(7)
+ )
+ MEMPOOL_ANALYZERS(7)
+private:
+ MEMPOOL_MEMBERS(
+ MEMPOOL_MEMBER_POOL(1)
+ MEMPOOL_MEMBER_POOL(2)
+ MEMPOOL_MEMBER_POOL(3)
+ MEMPOOL_MEMBER_POOL(4)
+ MEMPOOL_MEMBER_POOL(5)
+ MEMPOOL_MEMBER_POOL(6)
+ MEMPOOL_MEMBER_POOL(7)
+ )
+};
+
+template<
+MEMPOOL_TEMPLATE_PAIR(1),
+MEMPOOL_TEMPLATE_PAIR(2),
+MEMPOOL_TEMPLATE_PAIR(3),
+MEMPOOL_TEMPLATE_PAIR(4),
+MEMPOOL_TEMPLATE_PAIR(5),
+MEMPOOL_TEMPLATE_PAIR(6),
+MEMPOOL_TEMPLATE_PAIR(7),
+MEMPOOL_TEMPLATE_PAIR(8)>
+class bucket_pool_8 {
+public:
+ MEMPOOL_ALLOC_METHOD(
+ 8,
+ MEMPOOL_ALLOC_CHECK(1)
+ MEMPOOL_ALLOC_CHECK(2)
+ MEMPOOL_ALLOC_CHECK(3)
+ MEMPOOL_ALLOC_CHECK(4)
+ MEMPOOL_ALLOC_CHECK(5)
+ MEMPOOL_ALLOC_CHECK(6)
+ MEMPOOL_ALLOC_CHECK(7)
+ MEMPOOL_ALLOC_CHECK(8)
+ )
+ void * reallocate(void * ptr, size_t bytes){
+ MEMPOOL_REALLOC_CHECK(1)
+ MEMPOOL_REALLOC_CHECK(2)
+ MEMPOOL_REALLOC_CHECK(3)
+ MEMPOOL_REALLOC_CHECK(4)
+ MEMPOOL_REALLOC_CHECK(5)
+ MEMPOOL_REALLOC_CHECK(6)
+ MEMPOOL_REALLOC_CHECK(7)
+ MEMPOOL_REALLOC_CHECK(8)
+ return mempool_callbacks::reallocate(ptr, bytes);
+ }
+ MEMPOOL_LOAD(
+ 8,
+ _load[0] = _pool1.load();
+ _load[1] = _pool2.load();
+ _load[2] = _pool3.load();
+ _load[3] = _pool4.load();
+ _load[4] = _pool5.load();
+ _load[5] = _pool6.load();
+ _load[6] = _pool7.load();
+ _load[7] = _pool8.load();
+ )
+ MEMPOOL_DEALLOC_METHOD(
+ MEMPOOL_DEALLOC_CHECK(1)
+ MEMPOOL_DEALLOC_CHECK(2)
+ MEMPOOL_DEALLOC_CHECK(3)
+ MEMPOOL_DEALLOC_CHECK(4)
+ MEMPOOL_DEALLOC_CHECK(5)
+ MEMPOOL_DEALLOC_CHECK(6)
+ MEMPOOL_DEALLOC_CHECK(7)
+ MEMPOOL_DEALLOC_CHECK(8)
+ )
+ MEMPOOL_ANALYZERS(8)
+private:
+ MEMPOOL_MEMBERS(
+ MEMPOOL_MEMBER_POOL(1)
+ MEMPOOL_MEMBER_POOL(2)
+ MEMPOOL_MEMBER_POOL(3)
+ MEMPOOL_MEMBER_POOL(4)
+ MEMPOOL_MEMBER_POOL(5)
+ MEMPOOL_MEMBER_POOL(6)
+ MEMPOOL_MEMBER_POOL(7)
+ MEMPOOL_MEMBER_POOL(8)
+ )
+};
+
+template<
+MEMPOOL_TEMPLATE_PAIR(1),
+MEMPOOL_TEMPLATE_PAIR(2),
+MEMPOOL_TEMPLATE_PAIR(3),
+MEMPOOL_TEMPLATE_PAIR(4),
+MEMPOOL_TEMPLATE_PAIR(5),
+MEMPOOL_TEMPLATE_PAIR(6),
+MEMPOOL_TEMPLATE_PAIR(7),
+MEMPOOL_TEMPLATE_PAIR(8),
+MEMPOOL_TEMPLATE_PAIR(9)>
+class bucket_pool_9 {
+public:
+ MEMPOOL_ALLOC_METHOD(
+ 9,
+ MEMPOOL_ALLOC_CHECK(1)
+ MEMPOOL_ALLOC_CHECK(2)
+ MEMPOOL_ALLOC_CHECK(3)
+ MEMPOOL_ALLOC_CHECK(4)
+ MEMPOOL_ALLOC_CHECK(5)
+ MEMPOOL_ALLOC_CHECK(6)
+ MEMPOOL_ALLOC_CHECK(7)
+ MEMPOOL_ALLOC_CHECK(8)
+ MEMPOOL_ALLOC_CHECK(9)
+ )
+ void * reallocate(void * ptr, size_t bytes){
+ MEMPOOL_REALLOC_CHECK(1)
+ MEMPOOL_REALLOC_CHECK(2)
+ MEMPOOL_REALLOC_CHECK(3)
+ MEMPOOL_REALLOC_CHECK(4)
+ MEMPOOL_REALLOC_CHECK(5)
+ MEMPOOL_REALLOC_CHECK(6)
+ MEMPOOL_REALLOC_CHECK(7)
+ MEMPOOL_REALLOC_CHECK(8)
+ MEMPOOL_REALLOC_CHECK(9)
+ return mempool_callbacks::reallocate(ptr, bytes);
+ }
+ MEMPOOL_LOAD(
+ 9,
+ _load[0] = _pool1.load();
+ _load[1] = _pool2.load();
+ _load[2] = _pool3.load();
+ _load[3] = _pool4.load();
+ _load[4] = _pool5.load();
+ _load[5] = _pool6.load();
+ _load[6] = _pool7.load();
+ _load[7] = _pool8.load();
+ _load[8] = _pool9.load();
+ )
+ MEMPOOL_DEALLOC_METHOD(
+ MEMPOOL_DEALLOC_CHECK(1)
+ MEMPOOL_DEALLOC_CHECK(2)
+ MEMPOOL_DEALLOC_CHECK(3)
+ MEMPOOL_DEALLOC_CHECK(4)
+ MEMPOOL_DEALLOC_CHECK(5)
+ MEMPOOL_DEALLOC_CHECK(6)
+ MEMPOOL_DEALLOC_CHECK(7)
+ MEMPOOL_DEALLOC_CHECK(8)
+ MEMPOOL_DEALLOC_CHECK(9)
+ )
+ MEMPOOL_ANALYZERS(9)
+private:
+ MEMPOOL_MEMBERS(
+ MEMPOOL_MEMBER_POOL(1)
+ MEMPOOL_MEMBER_POOL(2)
+ MEMPOOL_MEMBER_POOL(3)
+ MEMPOOL_MEMBER_POOL(4)
+ MEMPOOL_MEMBER_POOL(5)
+ MEMPOOL_MEMBER_POOL(6)
+ MEMPOOL_MEMBER_POOL(7)
+ MEMPOOL_MEMBER_POOL(8)
+ MEMPOOL_MEMBER_POOL(9)
+ )
+};
+
+template<
+MEMPOOL_TEMPLATE_PAIR(1),
+MEMPOOL_TEMPLATE_PAIR(2),
+MEMPOOL_TEMPLATE_PAIR(3),
+MEMPOOL_TEMPLATE_PAIR(4),
+MEMPOOL_TEMPLATE_PAIR(5),
+MEMPOOL_TEMPLATE_PAIR(6),
+MEMPOOL_TEMPLATE_PAIR(7),
+MEMPOOL_TEMPLATE_PAIR(8),
+MEMPOOL_TEMPLATE_PAIR(9),
+MEMPOOL_TEMPLATE_PAIR(10)>
+class bucket_pool_10 {
+public:
+ MEMPOOL_ALLOC_METHOD(
+ 10,
+ MEMPOOL_ALLOC_CHECK(1)
+ MEMPOOL_ALLOC_CHECK(2)
+ MEMPOOL_ALLOC_CHECK(3)
+ MEMPOOL_ALLOC_CHECK(4)
+ MEMPOOL_ALLOC_CHECK(5)
+ MEMPOOL_ALLOC_CHECK(6)
+ MEMPOOL_ALLOC_CHECK(7)
+ MEMPOOL_ALLOC_CHECK(8)
+ MEMPOOL_ALLOC_CHECK(9)
+ MEMPOOL_ALLOC_CHECK(10)
+ )
+ void * reallocate(void * ptr, size_t bytes){
+ MEMPOOL_REALLOC_CHECK(1)
+ MEMPOOL_REALLOC_CHECK(2)
+ MEMPOOL_REALLOC_CHECK(3)
+ MEMPOOL_REALLOC_CHECK(4)
+ MEMPOOL_REALLOC_CHECK(5)
+ MEMPOOL_REALLOC_CHECK(6)
+ MEMPOOL_REALLOC_CHECK(7)
+ MEMPOOL_REALLOC_CHECK(8)
+ MEMPOOL_REALLOC_CHECK(9)
+ MEMPOOL_REALLOC_CHECK(10)
+ return mempool_callbacks::reallocate(ptr, bytes);
+ }
+ MEMPOOL_LOAD(
+ 10,
+ _load[0] = _pool1.load();
+ _load[1] = _pool2.load();
+ _load[2] = _pool3.load();
+ _load[3] = _pool4.load();
+ _load[4] = _pool5.load();
+ _load[5] = _pool6.load();
+ _load[6] = _pool7.load();
+ _load[7] = _pool8.load();
+ _load[8] = _pool9.load();
+ _load[9] = _pool10.load();
+ )
+ MEMPOOL_DEALLOC_METHOD(
+ MEMPOOL_DEALLOC_CHECK(1)
+ MEMPOOL_DEALLOC_CHECK(2)
+ MEMPOOL_DEALLOC_CHECK(3)
+ MEMPOOL_DEALLOC_CHECK(4)
+ MEMPOOL_DEALLOC_CHECK(5)
+ MEMPOOL_DEALLOC_CHECK(6)
+ MEMPOOL_DEALLOC_CHECK(7)
+ MEMPOOL_DEALLOC_CHECK(8)
+ MEMPOOL_DEALLOC_CHECK(9)
+ MEMPOOL_DEALLOC_CHECK(10)
+ )
+ MEMPOOL_ANALYZERS(10)
+private:
+ MEMPOOL_MEMBERS(
+ MEMPOOL_MEMBER_POOL(1)
+ MEMPOOL_MEMBER_POOL(2)
+ MEMPOOL_MEMBER_POOL(3)
+ MEMPOOL_MEMBER_POOL(4)
+ MEMPOOL_MEMBER_POOL(5)
+ MEMPOOL_MEMBER_POOL(6)
+ MEMPOOL_MEMBER_POOL(7)
+ MEMPOOL_MEMBER_POOL(8)
+ MEMPOOL_MEMBER_POOL(9)
+ MEMPOOL_MEMBER_POOL(10)
+ )
+};
+
+#endif
BIN  ext/libjson/Documentation.pdf
Binary file not shown
43 ext/libjson/Getting Started/C++ Interface/array.htm
@@ -0,0 +1,43 @@
+<HTML>
+<HEAD>
+<title>libjson Array Example</title>
+<script type="text/javascript" src="../Library Interface/scripts/shCore.js"></script>
+<script type="text/javascript" src="../Library Interface/scripts/shBrushCpp.js"></script>
+ <link type="text/css" rel="stylesheet" href="../Library Interface/styles/shCoreDefault.css"/>
+ <script type="text/javascript">SyntaxHighlighter.all();</script>
+
+</HEAD>
+<BODY>
+<h1>libjson Array Example</h1>
+<p>This quick example will show you how to add an array to your JSON tree.</p>
+<p><span id="more-120"></span></p>
+<pre class="brush:cpp;wrap-lines:true">JSONNode n(JSON_NODE);
+n.push_back(JSONNode(&quot;RootA&quot;, &quot;Hello World&quot;));
+JSONNode c(JSON_ARRAY);
+c.set_name(&quot;ArrayOfNumbers&quot;);
+c.push_back(JSONNode(&quot;&quot;, 16));
+c.push_back(JSONNode(&quot;&quot;, 42));
+c.push_back(JSONNode(&quot;&quot;, 128));
+n.push_back(c);
+std::string jc = n.write_formatted();
+std::cout &lt;&lt; jc &lt;&lt; std::endl;</pre>
+
+<p>The result will look like this:</p>
+<pre class="brush:cpp;wrap-lines:true">{
+ &quot;RootA&quot; : &quot;Hello World&quot;,
+ &quot;ArrayOfNumbers&quot; : [
+ 16,
+ 42,
+ 128
+ ]
+}</pre>
+<p>The first line generates a new root node for us to work with. This node will contain the entire JSON structure we want to create. Because this is created on the stack, there is no need to clean it up, it will do that when it goes out of scope.</p>
+
+<p>Line 2 creates a new JSON_STRING node, i.e. a node that will have a string value, and attaches the new node to the end of our original root node <em>n</em>.</p>
+<p>Line 3 creates a new child node and this time we&#39;re declaring a type of JSON_ARRAY that states the node will contain a number of nameless children nodes. While it&#39;s possible to have different data types in the same array, you should keep them all the same and treat it as if it were a typed array. Note that you can have an array of JSON_NODE objects, so you&#39;re not limited to simple data types, just be aware that the array will ignore any node names if you have them set.</p>
+<p>Lines 5 through 7 add values to the array, in this case they&#39;re all integer values. Because a JSON array cannot contain named values, the name parameter is set to &quot;&quot;.</p>
+
+<p>Line 8 appends the array to our root node.</p>
+<p>9 and 10 retrieve the formatted JSON string and dump it to stdout.</p>
+<BODY>
+</HTML>
57 ext/libjson/Getting Started/C++ Interface/basic_parser.htm
@@ -0,0 +1,57 @@
+<HTML>
+<HEAD>
+<title>libjson Basic Parser Example</title>
+<script type="text/javascript" src="../Library Interface/scripts/shCore.js"></script>
+<script type="text/javascript" src="../Library Interface/scripts/shBrushCpp.js"></script>
+ <link type="text/css" rel="stylesheet" href="../Library Interface/styles/shCoreDefault.css"/>
+ <script type="text/javascript">SyntaxHighlighter.all();</script>
+
+</HEAD>
+<BODY>
+<h1>libjson Basic Parser</h1>
+<p>Previously we looked at how to create a new JSON node tree programmatically that could be sent over the wire to consumer. Now we&#39;ll look at the consumer side and see how to parse the JSON string into our application.</p>
+<p><span id="more-135"></span></p>
+<p>First we&#39;ll look at the main function in our program that will take a JSON string as input, parse it using the library and pass the tree to a function that will extract useful data.</p>
+<pre class="brush:cpp;wrap-lines:true">std::string json = &quot;{\&quot;RootA\&quot;:\&quot;Value in parent node\&quot;,\&quot;ChildNode\&quot;:{\&quot;ChildA\&quot;:\&quot;String Value\&quot;,\&quot;ChildB\&quot;:42}}&quot;;
+JSONNode n = libjson::parse(json);
+ParseJSON(n);</pre>
+
+<p>The first line is just a simple JSON string containing a child object. You&#39;ll likely get a string from a web service, message buss or even a file.</p>
+<p>Line 2 is where the magic happens in the library. We just pass the string to <em>libjson::parse</em> and if all is well, we&#39;ll receive a node tree in return. NOTE that the parser is going to allocate memory on the stack, so do not try and delete it, let it go out of scope.</p>
+<p>Line 3 is a function call that we define for iterating through the JSON tree. While mine isn&#39;t pretty, it gets the job done for simple JSON objects.</p>
+<pre class="brush:cpp;wrap-lines:true">void ParseJSON(const JSONNode &amp; n){
+ JSONNode::const_iterator i = n.begin();
+ while (i != n.end()){
+ // recursively call ourselves to dig deeper into the tree
+ if (i -> type() == JSON_ARRAY || i -> type() == JSON_NODE){
+ ParseJSON(*i);
+ }
+
+ // get the node name and value as a string
+ std::string node_name = i -> name();
+
+ // find out where to store the values
+ if (node_name == &quot;RootA&quot;){
+ rootA = i -> as_string();
+ }
+ else if (node_name == &quot;ChildA&quot;){
+ childA = i -> as_string();
+ }
+ else if (node_name == &quot;ChildB&quot;)
+ childB = i -> as_int();
+
+ //increment the iterator
+ ++i;
+ }
+}</pre>
+
+<p>Next on line 7 we get a pointer to the first iterator of the node we&#39;re currently dealing with. The iterator lets us navigate through the child nodes, one by one.</p>
+<p>Line 8 begins a while loop that will continue until we&#39;ve reached the final iterator returned by <em>json_end</em>.</p>
+<p>If the iterator is currenly pointing to a node of type JSON_ARRAY or JSON_NODE, that means we are at a branch that requires a new iterator for processing. Thus line 16 makes a recursive call to the function so that we can start processing on the child node. Without this call, we would get the name of the node but trying to get a value would return nothing.</p>
+<p>On line 20 we call the <em>name</em> method that will return a string with the name of the node. If the node is not named or it&#39;s an array&#39;s value, the string will be empty, so check for that.</p>
+
+<p>Lines 23 through 34 are a simple decision tree that attempt to match the name of the node to known values and if a match is made, we use one of the library functions to extract the value of the node. <em>as_string</em> naturally returns the value of the node as a string. This is probably the easiest to use in that it doesn&#39;t care if the value of the node is encased in quotation marks or not, it will always return a string. You can read any node as a string and then typecast to whatever need.</p>
+<p>Line 38 increments our iterator to the next node.</p>
+<p>So there you have a very simple little parser that will iterate through your tree and grab extract the data. Naturally you&#39;ll want to add error handling and tweak it for your own use.</p>
+<BODY>
+</HTML>
46 ext/libjson/Getting Started/C++ Interface/child_node.htm
@@ -0,0 +1,46 @@
+<HTML>
+<HEAD>
+<title>libjson Child Node Example</title>
+<script type="text/javascript" src="../Library Interface/scripts/shCore.js"></script>
+<script type="text/javascript" src="../Library Interface/scripts/shBrushCpp.js"></script>
+ <link type="text/css" rel="stylesheet" href="../Library Interface/styles/shCoreDefault.css"/>
+ <script type="text/javascript">SyntaxHighlighter.all();</script>
+
+</HEAD>
+<BODY>
+<h1>libjson Child Node Example</h1>
+<p>Now we&#39;ll look at how to create a branch off the main tree.</p>
+<p><span id="more-114"></span></p>
+<pre class="brush:cpp;wrap-lines:true">JSONNode n(JSON_NODE);
+n.push_back(JSONNode(&quot;RootA&quot;, &quot;Value in parent node&quot;));
+JSONNode c(JSON_NODE);
+c.set_name(&quot;ChildNode&quot;);
+c.push_back(JSONNode(&quot;ChildA&quot;, &quot;String Value&quot;));
+c.push_back(JSONNode(&quot;ChildB&quot;, 42));
+n.push_back(c);
+std::string jc = n.write_formatted();
+std::cout &lt;&lt; jc &lt;&lt; std::endl;</pre>
+
+<p>The result will look like this:</p>
+<pre class="brush:cpp;wrap-lines:true">{
+ &quot;RootA&quot; : &quot;Value in parent node&quot;,
+ &quot;ChildNode&quot; : {
+ &quot;ChildA&quot; : &quot;String Value&quot;,
+ &quot;ChildB&quot; : 42
+ }
+}</pre>
+
+<p>As in the previous example, we create a root node to hold all of our child nodes on line one using the constructor.</p>
+<p>Line 2 adds to the root a string node with the name &quot;RootA&quot; and a value of &quot;Value in parent node&quot;.</p>
+<p>On line 3 we&#39;re creating a new, floating node that will be a branch off the root. It&#39;s the same type as our root, JSON_NODE.</p>
+<p><em>set_name</em> lets us name the node that we&#39;ve just created. If your branch is an object of some kind, you&#39;ll likely want to name it properly. Note that if you try to name the root node (<em>n</em> in our case), it won&#39;t be written out. The name will only appear if the JSON_NODE is a child of another node.</p>
+
+<p>Lines 5 and 6 add new nodes with values to our branch node <em>c</em>.</p>
+<p>Line 7 attaches our branch node <em>c</em> to the root node <em>n</em> after the string node named &quot;RootA&quot;.</p>
+<p>Line 8 returns the <em>json_string</em> nicely formatted and 9 prints it to stdout.</p>
+
+<p>With these tools, we can create complicated JSON structures and mimick objects with child properties.</p>
+
+
+<BODY>
+</HTML>
36 ext/libjson/Getting Started/C++ Interface/simple_write.htm
@@ -0,0 +1,36 @@
+<HTML>
+<HEAD>
+<title>libjson Simple Write Example</title>
+<script type="text/javascript" src="../Library Interface/scripts/shCore.js"></script>
+<script type="text/javascript" src="../Library Interface/scripts/shBrushCpp.js"></script>
+ <link type="text/css" rel="stylesheet" href="../Library Interface/styles/shCoreDefault.css"/>
+ <script type="text/javascript">SyntaxHighlighter.all();</script>
+
+</HEAD>
+<BODY>
+<h1>libjson Simple Write Example</h1>
+<p>This example uses the C interface to create a set of JSON nodes that you can then dump to a string and use however you like.</p>
+<pre class="brush:cpp;wrap-lines:true">JSONNode n(JSON_NODE);
+n.push_back(JSONNode(&quot;String Node&quot;, &quot;String Value&quot;));
+n.push_back(JSONNode(&quot;Integer Node&quot;, 42));
+n.push_back(JSONNode(&quot;Floating Point Node&quot;, 3.14));
+n.push_back(JSONNode(&quot;Boolean Node&quot;, true));
+std::string jc = n.write_formatted();
+std::cout &lt;&lt; jc &lt;&lt; std::endl;</pre>
+
+<p>The result will look like this:</p>
+<pre class="brush:cpp;wrap-lines:true">{
+ &quot;String Node&quot; : &quot;String Value&quot;,
+ &quot;Integer Node&quot; : 42,
+ &quot;Floating Point Node&quot; : 3.14,
+ &quot;Boolean Node&quot; : true
+}</pre>
+
+<p>The first line generates a new root node for us to work with. This node will contain the entire JSON structure we want to create.</p>
+<p>Line 2 creates a new JSON_STRING node, i.e. a node that will have a string value, and attaches the new node to the end of our original root node <em>n</em>.</p>
+<p>Line 3, 4 and 5 create and add new integer, floating point and boolean nodes respctively and add them to the root node. Both the integer and floating point methods will create JSON_NUMBER nodes where the numeric values will be printed to a JSON string without any quotation marks. The boolean method will take a true or a false and print a &quot;true&quot; or &quot;false&quot; in the final JSON string.</p>
+
+<p>Line 6 returns a <em>json_string</em> that contains nicely formatted JSON code from the structure we just created. The string will be nicely tabbed and returned for human readability. Use this for debugging purposes. If you are going into production, use the <em>write </em>method instead which will compact the JSON into a single line that saves space for transmission over the Net or between components.</p>
+
+<BODY>
+</HTML>
48 ext/libjson/Getting Started/Library Interface/array.htm
@@ -0,0 +1,48 @@
+<HTML>
+<HEAD>
+<title>libjson Array Example</title>
+<script type="text/javascript" src="scripts/shCore.js"></script>
+<script type="text/javascript" src="scripts/shBrushCpp.js"></script>
+ <link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/>
+ <script type="text/javascript">SyntaxHighlighter.all();</script>
+
+</HEAD>
+<BODY>
+<h1>libjson Array Example</h1>
+<p>This quick example will show you how to add an array to your JSON tree.</p>
+<p><span id="more-120"></span></p>
+<pre class="brush:cpp;wrap-lines:true">JSONNODE *n = json_new(JSON_NODE);
+json_push_back(n, json_new_a(&quot;RootA&quot;, &quot;Hello World&quot;));
+JSONNODE *c = json_new(JSON_ARRAY);
+json_set_name(c, &quot;ArrayOfNumbers&quot;);
+json_push_back(c, json_new_i(NULL, 16));
+json_push_back(c, json_new_i(NULL, 42));
+json_push_back(c, json_new_i(NULL, 128));
+json_push_back(n, c);
+json_char *jc = json_write_formatted(n);
+printf(&quot;%s\n&quot;, jc);
+json_free(jc);
+json_delete(n);</pre>
+
+<p>The result will look like this:</p>
+<pre class="brush:cpp;wrap-lines:true">{
+ &quot;RootA&quot; : &quot;Hello World&quot;,
+ &quot;ArrayOfNumbers&quot; : [
+ 16,
+ 42,
+ 128
+ ]
+}</pre>
+<p>The first line generates a new root node for us to work with. This node will contain the entire JSON structure we want to create. Note that, as mentioned in the documentation, any time you call a <em>json_new&#8230;</em> method, you are responsbile for freeing the memory allocated by the method. You can do this manually or by attaching the resulting node pointer to an existing node.</p>
+
+<p>Line 2 creates a new JSON_STRING node, i.e. a node that will have a string value, and attaches the new node to the end of our original root node <em>n</em>. The <em>json_new_a</em> method will escape your string values when you go to write the final string.</p>
+<p>Line 3 creates a new child node and this time we&#39;re declaring a type of JSON_ARRAY that states the node will contain a number of nameless children nodes. While it&#39;s possible to have different data types in the same array, you should keep them all the same and treat it as if it were a typed array. Note that you can have an array of JSON_NODE objects, so you&#39;re not limited to simple data types, just be aware that the array will ignore any node names if you have them set.</p>
+<p>Lines 5 through 7 add values to the array, in this case they&#39;re all integer values. Because a JSON array cannot contain named values, the name parameter of <em>json_new_i</em> is set to NULL.</p>
+
+<p>Line 8 appends the array to our root node.</p>
+<p>9 and 10 retrieve the formatted JSON string and dump it to stdout.</p>
+<p>11 frees memory allocated for our JSON string and 12 frees the entire tree structure.</p>
+
+<p>Chris Larsen 2010-10-08</p>
+<BODY>
+</HTML>
77 ext/libjson/Getting Started/Library Interface/basic_parser.htm
@@ -0,0 +1,77 @@
+<HTML>
+<HEAD>
+<title>libjson Basic Parser Example</title>
+<script type="text/javascript" src="scripts/shCore.js"></script>
+<script type="text/javascript" src="scripts/shBrushCpp.js"></script>
+ <link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/>
+ <script type="text/javascript">SyntaxHighlighter.all();</script>
+
+</HEAD>
+<BODY>
+<h1>libjson Basic Parser</h1>
+<p>Previously we looked at how to create a new JSON node tree programmatically that could be sent over the wire to consumer. Now we&#39;ll look at the consumer side and see how to parse the JSON string into our application.</p>
+<p><span id="more-135"></span></p>
+<p>First we&#39;ll look at the main function in our program that will take a JSON string as input, parse it using the library and pass the tree to a function that will extract useful data.</p>
+<pre class="brush:cpp;wrap-lines:true">char *json = &quot;{\&quot;RootA\&quot;:\&quot;Value in parent node\&quot;,\&quot;ChildNode\&quot;:{\&quot;ChildA\&quot;:\&quot;String Value\&quot;,\&quot;ChildB\&quot;:42}}&quot;;
+JSONNODE *n = json_parse(json);
+ParseJSON(n);
+json_delete(n);</pre>
+
+<p>The first line is just a simple JSON string containing a child object. You&#39;ll likely get a string from a web service, message buss or even a file.</p>
+<p>Line 2 is where the magic happens in the library. We just pass the string to <em>json_parse</em> and if all is well, we&#39;ll receive a pointer to a node tree in return. NOTE that the parser is going to allocate memory for the node tree, so you have to free it on your own as we do in line 4.</p>
+<p>Line 3 is a function call that we define for iterating through the JSON tree. While mine isn&#39;t pretty, it gets the job done for simple JSON objects.</p>
+<pre class="brush:cpp;wrap-lines:true">void ParseJSON(JSONNODE *n){
+ if (n == NULL){
+ printf(&quot;Invalid JSON Node\n&quot;);
+ return;
+ }
+
+ JSONNODE_ITERATOR i = json_begin(n);
+ while (i != json_end(n)){
+ if (*i == NULL){
+ printf(&quot;Invalid JSON Node\n&quot;);
+ return;
+ }
+
+ // recursively call ourselves to dig deeper into the tree
+ if (json_type(*i) == JSON_ARRAY || json_type(*i) == JSON_NODE){
+ ParseJSON(*i);
+ }
+
+ // get the node name and value as a string
+ json_char *node_name = json_name(*i);
+
+ // find out where to store the values
+ if (strcmp(node_name, &quot;RootA&quot;) == 0){
+ json_char *node_value = json_as_string(*i);
+ strcpy(rootA, node_value);
+ json_free(node_value);
+ }
+ else if (strcmp(node_name, &quot;ChildA&quot;) == 0){
+ json_char *node_value = json_as_string(*i);
+ strcpy(childA, node_value);
+ json_free(node_value);
+ }
+ else if (strcmp(node_name, &quot;ChildB&quot;) == 0)
+ childB = json_as_int(*i);
+
+ // cleanup and increment the iterator
+ json_free(node_name);
+ ++i;
+ }
+}</pre>
+
+<p>The first thing you want to do is check for NULL. If at any point in the parsing you run into a NULL value, then its likely that the JSON string wasn&#39;t formatted properly.</p>
+<p>Next on line 7 we get a pointer to the first iterator of the node we&#39;re currently dealing with. The iterator lets us navigate through the child nodes, one by one.</p>
+<p>Line 8 begins a while loop that will continue until we&#39;ve reached the final iterator returned by <em>json_end</em>.</p>
+<p>Again, we should check for an invalid iterator in case something went screwey, and we do so on line 9.</p>
+<p>If the iterator is currenly pointing to a node of type JSON_ARRAY or JSON_NODE, that means we are at a branch that requires a new iterator for processing. Thus line 16 makes a recursive call to the function so that we can start processing on the child node. Without this call, we would get the name of the node but trying to get a value would return nothing.</p>
+<p>On line 20 we call the <em>json_name</em> method that will return a string with the name of the node. If the node is not named or it&#39;s an array&#39;s value, the string will be empty, so check for that. Also note that you MUST free the memory returned by <em>json_name</em> as we do on line 37.</p>
+
+<p>Lines 23 through 34 are a simple decision tree that attempt to match the name of the node to known values and if a match is made, we use one of the library functions to extract the value of the node. <em>json_as_string</em> naturally returns the value of the node as a string. This is probably the easiest to use in that it doesn&#39;t care if the value of the node is encased in quotation marks or not, it will always return a string. You can read any node as a string and then typecast to whatever need.</p>
+<p>Line 37 frees up the node name allocation.</p>
+<p>Line 38 increments our iterator to the next node.</p>
+<p>So there you have a very simple little parser that will iterate through your tree and grab extract the data. Naturally you&#39;ll want to add error handling and tweak it for your own use.</p>
+<p>Chris Larsen 2010-10-08</p>
+<BODY>
+</HTML>
50 ext/libjson/Getting Started/Library Interface/child_node.htm
@@ -0,0 +1,50 @@
+<HTML>
+<HEAD>
+<title>libjson Child Node Example</title>
+<script type="text/javascript" src="scripts/shCore.js"></script>
+<script type="text/javascript" src="scripts/shBrushCpp.js"></script>
+ <link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/>
+ <script type="text/javascript">SyntaxHighlighter.all();</script>
+
+</HEAD>
+<BODY>
+<h1>libjson Child Node Example</h1>
+<p>Now we&#39;ll look at how to create a branch off the main tree.</p>
+<p><span id="more-114"></span></p>
+<pre class="brush:cpp;wrap-lines:true">JSONNODE *n = json_new(JSON_NODE);
+json_push_back(n, json_new_a(&quot;RootA&quot;, &quot;Value in parent node&quot;));
+JSONNODE *c = json_new(JSON_NODE);
+json_set_name(c, &quot;ChildNode&quot;);
+json_push_back(c, json_new_a(&quot;ChildA&quot;, &quot;String Value&quot;));
+json_push_back(c, json_new_i(&quot;ChildB&quot;, 42));
+json_push_back(n, c);
+json_char *jc = json_write_formatted(n);
+printf(&quot;%s\n&quot;, jc);
+json_free(jc);
+json_delete(n);</pre>
+
+<p>The result will look like this:</p>
+<pre class="brush:cpp;wrap-lines:true">{
+ &quot;RootA&quot; : &quot;Value in parent node&quot;,
+ &quot;ChildNode&quot; : {
+ &quot;ChildA&quot; : &quot;String Value&quot;,
+ &quot;ChildB&quot; : 42
+ }
+}</pre>
+
+<p>As in the previous example, we create a root node to hold all of our child nodes on line one using <em>json_new</em>.</p>
+<p>Line 2 adds to the root a string node with the name &quot;RootA&quot; and a value of &quot;Value in parent node&quot;.</p>
+<p>On line 3 we&#39;re creating a new, floating node that will be a branch off the root. It&#39;s the same type as our root, JSON_NODE.</p>
+<p><em>json_set_name</em> lets us name the node that we&#39;ve just created. If your branch is an object of some kind, you&#39;ll likely want to name it properly. Note that if you try to name the root node (<em>n</em> in our case), it won&#39;t be written out. The name will only appear if the JSON_NODE is a child of another node.</p>
+
+<p>Lines 5 and 6 add new nodes with values to our branch node <em>c</em>.</p>
+<p>Line 7 attaches our branch node <em>c</em> to the root node <em>n</em> after the string node named &quot;RootA&quot;. Note that if you fail to attach the branch to another node, you&#39;ll have to delete it manually or risk a memory leak.</p>
+<p>Line 8 returns the <em>json_char</em> string nicely formatted and 9 prints it to stdout.</p>
+
+<p>Line 10 frees our JSON string and line 11 loops through our root tree and frees up the memory we&#39;ve used.</p>
+<p>With these tools, we can create complicated JSON structures and mimick objects with child properties.</p>
+
+
+<p>Chris Larsen 2010-10-08</p>
+<BODY>
+</HTML>
17 ext/libjson/Getting Started/Library Interface/scripts/shAutoloader.js
@@ -0,0 +1,17 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ *
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(2(){1 h=5;h.I=2(){2 n(c,a){4(1 d=0;d<c.9;d++)i[c[d]]=a}2 o(c){1 a=r.H("J"),d=3;a.K=c;a.M="L/t";a.G="t";a.u=a.v=2(){6(!d&&(!8.7||8.7=="F"||8.7=="z")){d=q;e[c]=q;a:{4(1 p y e)6(e[p]==3)B a;j&&5.C(k)}a.u=a.v=x;a.D.O(a)}};r.N.R(a)}1 f=Q,l=h.P(),i={},e={},j=3,k=x,b;5.T=2(c){k=c;j=q};4(b=0;b<f.9;b++){1 m=f[b].w?f[b]:f[b].S(/\\s+/),g=m.w();n(m,g)}4(b=0;b<l.9;b++)6(g=i[l[b].E.A]){e[g]=3;o(g)}}})();',56,56,'|var|function|false|for|SyntaxHighlighter|if|readyState|this|length|||||||||||||||||true|document||javascript|onload|onreadystatechange|pop|null|in|complete|brush|break|highlight|parentNode|params|loaded|language|createElement|autoloader|script|src|text|type|body|removeChild|findElements|arguments|appendChild|split|all'.split('|'),0,{}))
97 ext/libjson/Getting Started/Library Interface/scripts/shBrushCpp.js
@@ -0,0 +1,97 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ *
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.
+ */
+;(function()
+{
+ // CommonJS
+ typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
+
+ function Brush()
+ {
+ // Copyright 2006 Shin, YoungJin
+
+ var datatypes = 'ATOM BOOL BOOLEAN BYTE CHAR COLORREF DWORD DWORDLONG DWORD_PTR ' +
+ 'DWORD32 DWORD64 FLOAT HACCEL HALF_PTR HANDLE HBITMAP HBRUSH ' +
+ 'HCOLORSPACE HCONV HCONVLIST HCURSOR HDC HDDEDATA HDESK HDROP HDWP ' +
+ 'HENHMETAFILE HFILE HFONT HGDIOBJ HGLOBAL HHOOK HICON HINSTANCE HKEY ' +
+ 'HKL HLOCAL HMENU HMETAFILE HMODULE HMONITOR HPALETTE HPEN HRESULT ' +
+ 'HRGN HRSRC HSZ HWINSTA HWND INT INT_PTR INT32 INT64 LANGID LCID LCTYPE ' +
+ 'LGRPID LONG LONGLONG LONG_PTR LONG32 LONG64 LPARAM LPBOOL LPBYTE LPCOLORREF ' +
+ 'LPCSTR LPCTSTR LPCVOID LPCWSTR LPDWORD LPHANDLE LPINT LPLONG LPSTR LPTSTR ' +
+ 'LPVOID LPWORD LPWSTR LRESULT PBOOL PBOOLEAN PBYTE PCHAR PCSTR PCTSTR PCWSTR ' +
+ 'PDWORDLONG PDWORD_PTR PDWORD32 PDWORD64 PFLOAT PHALF_PTR PHANDLE PHKEY PINT ' +
+ 'PINT_PTR PINT32 PINT64 PLCID PLONG PLONGLONG PLONG_PTR PLONG32 PLONG64 POINTER_32 ' +
+ 'POINTER_64 PSHORT PSIZE_T PSSIZE_T PSTR PTBYTE PTCHAR PTSTR PUCHAR PUHALF_PTR ' +
+ 'PUINT PUINT_PTR PUINT32 PUINT64 PULONG PULONGLONG PULONG_PTR PULONG32 PULONG64 ' +
+ 'PUSHORT PVOID PWCHAR PWORD PWSTR SC_HANDLE SC_LOCK SERVICE_STATUS_HANDLE SHORT ' +
+ 'SIZE_T SSIZE_T TBYTE TCHAR UCHAR UHALF_PTR UINT UINT_PTR UINT32 UINT64 ULONG ' +
+ 'ULONGLONG ULONG_PTR ULONG32 ULONG64 USHORT USN VOID WCHAR WORD WPARAM WPARAM WPARAM ' +
+ 'char bool short int __int32 __int64 __int8 __int16 long float double __wchar_t ' +
+ 'clock_t _complex _dev_t _diskfree_t div_t ldiv_t _exception _EXCEPTION_POINTERS ' +
+ 'FILE _finddata_t _finddatai64_t _wfinddata_t _wfinddatai64_t __finddata64_t ' +
+ '__wfinddata64_t _FPIEEE_RECORD fpos_t _HEAPINFO _HFILE lconv intptr_t ' +
+ 'jmp_buf mbstate_t _off_t _onexit_t _PNH ptrdiff_t _purecall_handler ' +
+ 'sig_atomic_t size_t _stat __stat64 _stati64 terminate_function ' +
+ 'time_t __time64_t _timeb __timeb64 tm uintptr_t _utimbuf ' +
+ 'va_list wchar_t wctrans_t wctype_t wint_t signed';
+
+ var keywords = 'break case catch class const __finally __exception __try ' +
+ 'const_cast continue private public protected __declspec ' +
+ 'default delete deprecated dllexport dllimport do dynamic_cast ' +
+ 'else enum explicit extern if for friend goto inline ' +
+ 'mutable naked namespace new noinline noreturn nothrow ' +
+ 'register reinterpret_cast return selectany ' +
+ 'sizeof static static_cast struct switch template this ' +
+ 'thread throw true false try typedef typeid typename union ' +
+ 'using uuid virtual void volatile whcar_t while';
+
+ var functions = 'assert isalnum isalpha iscntrl isdigit isgraph islower isprint' +
+ 'ispunct isspace isupper isxdigit tolower toupper errno localeconv ' +
+ 'setlocale acos asin atan atan2 ceil cos cosh exp fabs floor fmod ' +
+ 'frexp ldexp log log10 modf pow sin sinh sqrt tan tanh jmp_buf ' +
+ 'longjmp setjmp raise signal sig_atomic_t va_arg va_end va_start ' +
+ 'clearerr fclose feof ferror fflush fgetc fgetpos fgets fopen ' +
+ 'fprintf fputc fputs fread freopen fscanf fseek fsetpos ftell ' +
+ 'fwrite getc getchar gets perror printf putc putchar puts remove ' +
+ 'rename rewind scanf setbuf setvbuf sprintf sscanf tmpfile tmpnam ' +
+ 'ungetc vfprintf vprintf vsprintf abort abs atexit atof atoi atol ' +
+ 'bsearch calloc div exit free getenv labs ldiv malloc mblen mbstowcs ' +
+ 'mbtowc qsort rand realloc srand strtod strtol strtoul system ' +
+ 'wcstombs wctomb memchr memcmp memcpy memmove memset strcat strchr ' +
+ 'strcmp strcoll strcpy strcspn strerror strlen strncat strncmp ' +
+ 'strncpy strpbrk strrchr strspn strstr strtok strxfrm asctime ' +
+ 'clock ctime difftime gmtime localtime mktime strftime time';
+
+ this.regexList = [
+ { regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comments' }, // one line comments
+ { regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comments' }, // multiline comments
+ { regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // strings
+ { regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // strings
+ { regex: /^ *#.*/gm, css: 'preprocessor' },
+ { regex: new RegExp(this.getKeywords(datatypes), 'gm'), css: 'color1 bold' },
+ { regex: new RegExp(this.getKeywords(functions), 'gm'), css: 'functions bold' },
+ { regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword bold' }
+ ];
+ };
+
+ Brush.prototype = new SyntaxHighlighter.Highlighter();
+ Brush.aliases = ['cpp', 'c'];
+
+ SyntaxHighlighter.brushes.Cpp = Brush;
+
+ // CommonJS
+ typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
+})();
17 ext/libjson/Getting Started/Library Interface/scripts/shCore.js
@@ -0,0 +1,17 @@
+/**
+ * SyntaxHighlighter
+ * http://alexgorbatchev.com/SyntaxHighlighter
+ *
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
+ *
+ * @version
+ * 3.0.83 (July 02 2010)
+ *
+ * @copyright
+ * Copyright (C) 2004-2010 Alex Gorbatchev.
+ *
+ * @license
+ * Dual licensed under the MIT and GPL licenses.