simpleble 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +88 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +350 -0
  5. data/ext/simpleble/extconf.rb +57 -0
  6. data/ext/simpleble/simpleble_ruby.c +682 -0
  7. data/lib/simpleble/adapter.rb +10 -0
  8. data/lib/simpleble/characteristic.rb +36 -0
  9. data/lib/simpleble/descriptor.rb +8 -0
  10. data/lib/simpleble/exceptions.rb +25 -0
  11. data/lib/simpleble/peripheral.rb +64 -0
  12. data/lib/simpleble/service.rb +16 -0
  13. data/lib/simpleble/version.rb +3 -0
  14. data/lib/simpleble.rb +40 -0
  15. data/vendor/simpleble/build_simplecble/CMakeFiles/4.0.3/CompilerIdCXX/CMakeCXXCompilerId.cpp +920 -0
  16. data/vendor/simpleble/build_simplecble/CMakeFiles/4.0.3/CompilerIdCXX/apple-sdk.cpp +1 -0
  17. data/vendor/simpleble/build_simplecble/CMakeFiles/4.1.0/CompilerIdCXX/CMakeCXXCompilerId.cpp +949 -0
  18. data/vendor/simpleble/build_simplecble/CMakeFiles/4.1.0/CompilerIdCXX/apple-sdk.cpp +1 -0
  19. data/vendor/simpleble/build_simplecble/export/simplecble/export.h +43 -0
  20. data/vendor/simpleble/build_simplecble/simpleble/export/simpleble/export.h +43 -0
  21. data/vendor/simpleble/dependencies/external/kvn/kvn_bytearray.h +222 -0
  22. data/vendor/simpleble/dependencies/external/kvn/kvn_safe_callback.hpp +66 -0
  23. data/vendor/simpleble/dependencies/external/kvn/logfwd.hpp +35 -0
  24. data/vendor/simpleble/dependencies/internal/fmt/args.h +220 -0
  25. data/vendor/simpleble/dependencies/internal/fmt/base.h +2962 -0
  26. data/vendor/simpleble/dependencies/internal/fmt/chrono.h +2338 -0
  27. data/vendor/simpleble/dependencies/internal/fmt/color.h +610 -0
  28. data/vendor/simpleble/dependencies/internal/fmt/compile.h +539 -0
  29. data/vendor/simpleble/dependencies/internal/fmt/core.h +5 -0
  30. data/vendor/simpleble/dependencies/internal/fmt/format-inl.h +1949 -0
  31. data/vendor/simpleble/dependencies/internal/fmt/format.h +4244 -0
  32. data/vendor/simpleble/dependencies/internal/fmt/os.h +427 -0
  33. data/vendor/simpleble/dependencies/internal/fmt/ostream.h +166 -0
  34. data/vendor/simpleble/dependencies/internal/fmt/printf.h +633 -0
  35. data/vendor/simpleble/dependencies/internal/fmt/ranges.h +850 -0
  36. data/vendor/simpleble/dependencies/internal/fmt/std.h +726 -0
  37. data/vendor/simpleble/dependencies/internal/fmt/xchar.h +373 -0
  38. data/vendor/simpleble/dependencies/internal/simplejni/Common.hpp +579 -0
  39. data/vendor/simpleble/dependencies/internal/simplejni/References.hpp +151 -0
  40. data/vendor/simpleble/dependencies/internal/simplejni/Registry.hpp +183 -0
  41. data/vendor/simpleble/dependencies/internal/simplejni/VM.hpp +88 -0
  42. data/vendor/simpleble/examples/simpleble/src/connect.cpp +67 -0
  43. data/vendor/simpleble/examples/simpleble/src/connect_safe.cpp +91 -0
  44. data/vendor/simpleble/examples/simpleble/src/list_adapters.cpp +22 -0
  45. data/vendor/simpleble/examples/simpleble/src/list_adapters_safe.cpp +33 -0
  46. data/vendor/simpleble/examples/simpleble/src/list_paired.cpp +27 -0
  47. data/vendor/simpleble/examples/simpleble/src/multiconnect.cpp +60 -0
  48. data/vendor/simpleble/examples/simpleble/src/notify.cpp +85 -0
  49. data/vendor/simpleble/examples/simpleble/src/notify_multi.cpp +101 -0
  50. data/vendor/simpleble/examples/simpleble/src/power_cycle.cpp +43 -0
  51. data/vendor/simpleble/examples/simpleble/src/read.cpp +82 -0
  52. data/vendor/simpleble/examples/simpleble/src/scan.cpp +62 -0
  53. data/vendor/simpleble/examples/simpleble/src/utils.cpp +59 -0
  54. data/vendor/simpleble/examples/simpleble/src/utils.hpp +27 -0
  55. data/vendor/simpleble/examples/simpleble/src/write.cpp +81 -0
  56. data/vendor/simpleble/examples/simplebluez/ble_nus/ble_nus.cpp +138 -0
  57. data/vendor/simpleble/examples/simplebluez/connect/connect.cpp +119 -0
  58. data/vendor/simpleble/examples/simplebluez/list_adapters/list_adapters.cpp +44 -0
  59. data/vendor/simpleble/examples/simplebluez/list_paired/list_paired.cpp +48 -0
  60. data/vendor/simpleble/examples/simplebluez/notify/notify.cpp +145 -0
  61. data/vendor/simpleble/examples/simplebluez/pair/pair.cpp +181 -0
  62. data/vendor/simpleble/examples/simplebluez/read/read.cpp +141 -0
  63. data/vendor/simpleble/examples/simplebluez/scan/scan.cpp +85 -0
  64. data/vendor/simpleble/examples/simplecble/c/connect.c +163 -0
  65. data/vendor/simpleble/examples/simplecble/c/notify.c +217 -0
  66. data/vendor/simpleble/examples/simplecble/c/scan.c +164 -0
  67. data/vendor/simpleble/examples/simpledbus/notification.cpp +24 -0
  68. data/vendor/simpleble/hitl/src/test_sanity.cpp +48 -0
  69. data/vendor/simpleble/install_simplecble/include/simpleble/Adapter.h +102 -0
  70. data/vendor/simpleble/install_simplecble/include/simpleble/AdapterSafe.h +58 -0
  71. data/vendor/simpleble/install_simplecble/include/simpleble/Advanced.h +50 -0
  72. data/vendor/simpleble/install_simplecble/include/simpleble/Characteristic.h +39 -0
  73. data/vendor/simpleble/install_simplecble/include/simpleble/Config.h +55 -0
  74. data/vendor/simpleble/install_simplecble/include/simpleble/Descriptor.h +30 -0
  75. data/vendor/simpleble/install_simplecble/include/simpleble/Exceptions.h +72 -0
  76. data/vendor/simpleble/install_simplecble/include/simpleble/Logging.h +73 -0
  77. data/vendor/simpleble/install_simplecble/include/simpleble/Peripheral.h +82 -0
  78. data/vendor/simpleble/install_simplecble/include/simpleble/PeripheralSafe.h +64 -0
  79. data/vendor/simpleble/install_simplecble/include/simpleble/Service.h +34 -0
  80. data/vendor/simpleble/install_simplecble/include/simpleble/SimpleBLE.h +8 -0
  81. data/vendor/simpleble/install_simplecble/include/simpleble/Types.h +49 -0
  82. data/vendor/simpleble/install_simplecble/include/simpleble/Utils.h +13 -0
  83. data/vendor/simpleble/install_simplecble/include/simpleble/export.h +43 -0
  84. data/vendor/simpleble/install_simplecble/include/simpleble/kvn/kvn_bytearray.h +222 -0
  85. data/vendor/simpleble/install_simplecble/include/simplecble/adapter.h +188 -0
  86. data/vendor/simpleble/install_simplecble/include/simplecble/logging.h +37 -0
  87. data/vendor/simpleble/install_simplecble/include/simplecble/peripheral.h +304 -0
  88. data/vendor/simpleble/install_simplecble/include/simplecble/simpleble.h +21 -0
  89. data/vendor/simpleble/install_simplecble/include/simplecble/types.h +73 -0
  90. data/vendor/simpleble/install_simplecble/include/simplecble/utils.h +27 -0
  91. data/vendor/simpleble/simpleble/include/simpleble/Adapter.h +102 -0
  92. data/vendor/simpleble/simpleble/include/simpleble/AdapterSafe.h +58 -0
  93. data/vendor/simpleble/simpleble/include/simpleble/Characteristic.h +39 -0
  94. data/vendor/simpleble/simpleble/include/simpleble/Config.h +55 -0
  95. data/vendor/simpleble/simpleble/include/simpleble/Descriptor.h +30 -0
  96. data/vendor/simpleble/simpleble/include/simpleble/Exceptions.h +72 -0
  97. data/vendor/simpleble/simpleble/include/simpleble/Logging.h +73 -0
  98. data/vendor/simpleble/simpleble/include/simpleble/Peripheral.h +82 -0
  99. data/vendor/simpleble/simpleble/include/simpleble/PeripheralSafe.h +64 -0
  100. data/vendor/simpleble/simpleble/include/simpleble/Service.h +34 -0
  101. data/vendor/simpleble/simpleble/include/simpleble/SimpleBLE.h +8 -0
  102. data/vendor/simpleble/simpleble/include/simpleble/Types.h +49 -0
  103. data/vendor/simpleble/simpleble/include/simpleble/Utils.h +13 -0
  104. data/vendor/simpleble/simpleble/include/simpleble_c/adapter.h +188 -0
  105. data/vendor/simpleble/simpleble/include/simpleble_c/logging.h +37 -0
  106. data/vendor/simpleble/simpleble/include/simpleble_c/peripheral.h +304 -0
  107. data/vendor/simpleble/simpleble/include/simpleble_c/simpleble.h +21 -0
  108. data/vendor/simpleble/simpleble/include/simpleble_c/types.h +73 -0
  109. data/vendor/simpleble/simpleble/include/simpleble_c/utils.h +27 -0
  110. data/vendor/simpleble/simpleble/src/CommonUtils.h +63 -0
  111. data/vendor/simpleble/simpleble/src/Exceptions.cpp +31 -0
  112. data/vendor/simpleble/simpleble/src/Logging.cpp +136 -0
  113. data/vendor/simpleble/simpleble/src/LoggingInternal.h +85 -0
  114. data/vendor/simpleble/simpleble/src/Utils.cpp +24 -0
  115. data/vendor/simpleble/simpleble/src/backends/android/AdapterAndroid.cpp +101 -0
  116. data/vendor/simpleble/simpleble/src/backends/android/AdapterAndroid.h +70 -0
  117. data/vendor/simpleble/simpleble/src/backends/android/BackendAndroid.cpp +40 -0
  118. data/vendor/simpleble/simpleble/src/backends/android/BackendAndroid.h +20 -0
  119. data/vendor/simpleble/simpleble/src/backends/android/PeripheralAndroid.cpp +365 -0
  120. data/vendor/simpleble/simpleble/src/backends/android/PeripheralAndroid.h +90 -0
  121. data/vendor/simpleble/simpleble/src/backends/android/bridge/BluetoothGattCallback.cpp +432 -0
  122. data/vendor/simpleble/simpleble/src/backends/android/bridge/BluetoothGattCallback.h +102 -0
  123. data/vendor/simpleble/simpleble/src/backends/android/bridge/ScanCallback.cpp +142 -0
  124. data/vendor/simpleble/simpleble/src/backends/android/bridge/ScanCallback.h +55 -0
  125. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.cpp +107 -0
  126. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.h +55 -0
  127. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.cpp +68 -0
  128. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.h +54 -0
  129. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.cpp +115 -0
  130. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.h +75 -0
  131. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.cpp +142 -0
  132. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.h +66 -0
  133. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.cpp +67 -0
  134. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.h +46 -0
  135. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.cpp +106 -0
  136. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.h +47 -0
  137. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.cpp +47 -0
  138. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.h +37 -0
  139. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.cpp +69 -0
  140. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.h +41 -0
  141. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.cpp +63 -0
  142. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.h +42 -0
  143. data/vendor/simpleble/simpleble/src/backends/android/types/android/os/ParcelUUID.cpp +32 -0
  144. data/vendor/simpleble/simpleble/src/backends/android/types/android/os/ParcelUUID.h +30 -0
  145. data/vendor/simpleble/simpleble/src/backends/android/types/android/util/SparseArray.cpp +54 -0
  146. data/vendor/simpleble/simpleble/src/backends/android/types/android/util/SparseArray.h +37 -0
  147. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Iterator.cpp +36 -0
  148. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Iterator.h +28 -0
  149. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/List.cpp +29 -0
  150. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/List.h +27 -0
  151. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Set.cpp +33 -0
  152. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Set.h +28 -0
  153. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/UUID.cpp +26 -0
  154. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/UUID.h +29 -0
  155. data/vendor/simpleble/simpleble/src/backends/common/AdapterBase.cpp +53 -0
  156. data/vendor/simpleble/simpleble/src/backends/common/AdapterBase.h +81 -0
  157. data/vendor/simpleble/simpleble/src/backends/common/AdapterBaseTypes.h +22 -0
  158. data/vendor/simpleble/simpleble/src/backends/common/BackendBase.h +20 -0
  159. data/vendor/simpleble/simpleble/src/backends/common/BackendUtils.h +33 -0
  160. data/vendor/simpleble/simpleble/src/backends/common/CharacteristicBase.cpp +28 -0
  161. data/vendor/simpleble/simpleble/src/backends/common/CharacteristicBase.h +38 -0
  162. data/vendor/simpleble/simpleble/src/backends/common/DescriptorBase.cpp +7 -0
  163. data/vendor/simpleble/simpleble/src/backends/common/DescriptorBase.h +19 -0
  164. data/vendor/simpleble/simpleble/src/backends/common/PeripheralBase.h +82 -0
  165. data/vendor/simpleble/simpleble/src/backends/common/ServiceBase.cpp +18 -0
  166. data/vendor/simpleble/simpleble/src/backends/common/ServiceBase.h +28 -0
  167. data/vendor/simpleble/simpleble/src/backends/linux/AdapterLinux.cpp +102 -0
  168. data/vendor/simpleble/simpleble/src/backends/linux/AdapterLinux.h +55 -0
  169. data/vendor/simpleble/simpleble/src/backends/linux/BackendBluez.cpp +87 -0
  170. data/vendor/simpleble/simpleble/src/backends/linux/PeripheralLinux.cpp +376 -0
  171. data/vendor/simpleble/simpleble/src/backends/linux/PeripheralLinux.h +90 -0
  172. data/vendor/simpleble/simpleble/src/backends/macos/AdapterBaseMacOS.h +29 -0
  173. data/vendor/simpleble/simpleble/src/backends/macos/AdapterMac.h +78 -0
  174. data/vendor/simpleble/simpleble/src/backends/macos/PeripheralBaseMacOS.h +49 -0
  175. data/vendor/simpleble/simpleble/src/backends/macos/PeripheralMac.h +81 -0
  176. data/vendor/simpleble/simpleble/src/backends/macos/Utils.h +9 -0
  177. data/vendor/simpleble/simpleble/src/backends/plain/AdapterPlain.cpp +65 -0
  178. data/vendor/simpleble/simpleble/src/backends/plain/AdapterPlain.h +49 -0
  179. data/vendor/simpleble/simpleble/src/backends/plain/BackendPlain.cpp +30 -0
  180. data/vendor/simpleble/simpleble/src/backends/plain/PeripheralPlain.cpp +159 -0
  181. data/vendor/simpleble/simpleble/src/backends/plain/PeripheralPlain.h +72 -0
  182. data/vendor/simpleble/simpleble/src/backends/windows/AdapterWindows.cpp +330 -0
  183. data/vendor/simpleble/simpleble/src/backends/windows/AdapterWindows.h +89 -0
  184. data/vendor/simpleble/simpleble/src/backends/windows/BackendWinRT.cpp +67 -0
  185. data/vendor/simpleble/simpleble/src/backends/windows/BackendWinRT.h +18 -0
  186. data/vendor/simpleble/simpleble/src/backends/windows/MtaManager.cpp +49 -0
  187. data/vendor/simpleble/simpleble/src/backends/windows/MtaManager.h +90 -0
  188. data/vendor/simpleble/simpleble/src/backends/windows/PeripheralWindows.cpp +487 -0
  189. data/vendor/simpleble/simpleble/src/backends/windows/PeripheralWindows.h +129 -0
  190. data/vendor/simpleble/simpleble/src/backends/windows/Utils.cpp +146 -0
  191. data/vendor/simpleble/simpleble/src/backends/windows/Utils.h +47 -0
  192. data/vendor/simpleble/simpleble/src/builders/BuildVec.h +32 -0
  193. data/vendor/simpleble/simpleble/src/builders/BuilderBase.h +87 -0
  194. data/vendor/simpleble/simpleble/src/external/TaskRunner.hpp +99 -0
  195. data/vendor/simpleble/simpleble/src/external/ThreadRunner.h +52 -0
  196. data/vendor/simpleble/simpleble/src/external/kvn_safe_callback.hpp +66 -0
  197. data/vendor/simpleble/simpleble/src/external/kvn_safe_map.hpp +94 -0
  198. data/vendor/simpleble/simpleble/src/external/kvn_threadrunner.hpp +70 -0
  199. data/vendor/simpleble/simpleble/src/external/logfwd.hpp +35 -0
  200. data/vendor/simpleble/simpleble/src/frontends/base/Adapter.cpp +111 -0
  201. data/vendor/simpleble/simpleble/src/frontends/base/Backend.cpp +83 -0
  202. data/vendor/simpleble/simpleble/src/frontends/base/Backend.h +76 -0
  203. data/vendor/simpleble/simpleble/src/frontends/base/Characteristic.cpp +56 -0
  204. data/vendor/simpleble/simpleble/src/frontends/base/Descriptor.cpp +21 -0
  205. data/vendor/simpleble/simpleble/src/frontends/base/Peripheral.cpp +113 -0
  206. data/vendor/simpleble/simpleble/src/frontends/base/Service.cpp +26 -0
  207. data/vendor/simpleble/simpleble/src/frontends/safe/AdapterSafe.cpp +158 -0
  208. data/vendor/simpleble/simpleble/src/frontends/safe/PeripheralSafe.cpp +219 -0
  209. data/vendor/simpleble/simpleble/src_c/adapter.cpp +204 -0
  210. data/vendor/simpleble/simpleble/src_c/logging.cpp +19 -0
  211. data/vendor/simpleble/simpleble/src_c/peripheral.cpp +444 -0
  212. data/vendor/simpleble/simpleble/src_c/simpleble.cpp +5 -0
  213. data/vendor/simpleble/simpleble/src_c/utils.cpp +15 -0
  214. data/vendor/simpleble/simpleble/test/src/main.cpp +8 -0
  215. data/vendor/simpleble/simpleble/test/src/test_bytearray.cpp +246 -0
  216. data/vendor/simpleble/simpleble/test/src/test_utils.cpp +24 -0
  217. data/vendor/simpleble/simplebluez/include/simplebluez/Adapter.h +46 -0
  218. data/vendor/simpleble/simplebluez/include/simplebluez/Agent.h +52 -0
  219. data/vendor/simpleble/simplebluez/include/simplebluez/Bluez.h +37 -0
  220. data/vendor/simpleble/simplebluez/include/simplebluez/BluezOrg.h +22 -0
  221. data/vendor/simpleble/simplebluez/include/simplebluez/BluezOrgBluez.h +26 -0
  222. data/vendor/simpleble/simplebluez/include/simplebluez/BluezRoot.h +32 -0
  223. data/vendor/simpleble/simplebluez/include/simplebluez/Characteristic.h +46 -0
  224. data/vendor/simpleble/simplebluez/include/simplebluez/Descriptor.h +33 -0
  225. data/vendor/simpleble/simplebluez/include/simplebluez/Device.h +64 -0
  226. data/vendor/simpleble/simplebluez/include/simplebluez/Exceptions.h +43 -0
  227. data/vendor/simpleble/simplebluez/include/simplebluez/Service.h +27 -0
  228. data/vendor/simpleble/simplebluez/include/simplebluez/Types.h +9 -0
  229. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Adapter1.h +49 -0
  230. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Agent1.h +100 -0
  231. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/AgentManager1.h +24 -0
  232. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Battery1.h +32 -0
  233. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Device1.h +62 -0
  234. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattCharacteristic1.h +48 -0
  235. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattDescriptor1.h +41 -0
  236. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattService1.h +28 -0
  237. data/vendor/simpleble/simplebluez/src/Adapter.cpp +78 -0
  238. data/vendor/simpleble/simplebluez/src/Agent.cpp +72 -0
  239. data/vendor/simpleble/simplebluez/src/Bluez.cpp +45 -0
  240. data/vendor/simpleble/simplebluez/src/BluezOrg.cpp +20 -0
  241. data/vendor/simpleble/simplebluez/src/BluezOrgBluez.cpp +23 -0
  242. data/vendor/simpleble/simplebluez/src/BluezRoot.cpp +44 -0
  243. data/vendor/simpleble/simplebluez/src/Characteristic.cpp +64 -0
  244. data/vendor/simpleble/simplebluez/src/Descriptor.cpp +27 -0
  245. data/vendor/simpleble/simplebluez/src/Device.cpp +104 -0
  246. data/vendor/simpleble/simplebluez/src/Exceptions.cpp +29 -0
  247. data/vendor/simpleble/simplebluez/src/Logging.cpp +52 -0
  248. data/vendor/simpleble/simplebluez/src/Logging.h +57 -0
  249. data/vendor/simpleble/simplebluez/src/Service.cpp +33 -0
  250. data/vendor/simpleble/simplebluez/src/interfaces/Adapter1.cpp +123 -0
  251. data/vendor/simpleble/simplebluez/src/interfaces/Agent1.cpp +143 -0
  252. data/vendor/simpleble/simplebluez/src/interfaces/AgentManager1.cpp +34 -0
  253. data/vendor/simpleble/simplebluez/src/interfaces/Battery1.cpp +30 -0
  254. data/vendor/simpleble/simplebluez/src/interfaces/Device1.cpp +170 -0
  255. data/vendor/simpleble/simplebluez/src/interfaces/GattCharacteristic1.cpp +118 -0
  256. data/vendor/simpleble/simplebluez/src/interfaces/GattDescriptor1.cpp +78 -0
  257. data/vendor/simpleble/simplebluez/src/interfaces/GattService1.cpp +28 -0
  258. data/vendor/simpleble/simplebluez/test/src/helpers/PythonRunner.cpp +53 -0
  259. data/vendor/simpleble/simplebluez/test/src/helpers/PythonRunner.h +24 -0
  260. data/vendor/simpleble/simplebluez/test/src/main.cpp +16 -0
  261. data/vendor/simpleble/simplecble/include/simplecble/adapter.h +188 -0
  262. data/vendor/simpleble/simplecble/include/simplecble/logging.h +37 -0
  263. data/vendor/simpleble/simplecble/include/simplecble/peripheral.h +304 -0
  264. data/vendor/simpleble/simplecble/include/simplecble/simpleble.h +21 -0
  265. data/vendor/simpleble/simplecble/include/simplecble/types.h +73 -0
  266. data/vendor/simpleble/simplecble/include/simplecble/utils.h +27 -0
  267. data/vendor/simpleble/simplecble/src/adapter.cpp +204 -0
  268. data/vendor/simpleble/simplecble/src/logging.cpp +19 -0
  269. data/vendor/simpleble/simplecble/src/peripheral.cpp +444 -0
  270. data/vendor/simpleble/simplecble/src/simpleble.cpp +5 -0
  271. data/vendor/simpleble/simplecble/src/utils.cpp +15 -0
  272. data/vendor/simpleble/simpledbus/include/simpledbus/advanced/Interface.h +67 -0
  273. data/vendor/simpleble/simpledbus/include/simpledbus/advanced/InterfaceRegistry.h +64 -0
  274. data/vendor/simpleble/simpledbus/include/simpledbus/advanced/Proxy.h +117 -0
  275. data/vendor/simpleble/simpledbus/include/simpledbus/base/Connection.h +50 -0
  276. data/vendor/simpleble/simpledbus/include/simpledbus/base/Exceptions.h +56 -0
  277. data/vendor/simpleble/simpledbus/include/simpledbus/base/Holder.h +147 -0
  278. data/vendor/simpleble/simpledbus/include/simpledbus/base/Logging.h +57 -0
  279. data/vendor/simpleble/simpledbus/include/simpledbus/base/Message.h +89 -0
  280. data/vendor/simpleble/simpledbus/include/simpledbus/base/Path.h +24 -0
  281. data/vendor/simpleble/simpledbus/include/simpledbus/interfaces/ObjectManager.h +26 -0
  282. data/vendor/simpleble/simpledbus/src/advanced/Interface.cpp +155 -0
  283. data/vendor/simpleble/simpledbus/src/advanced/Proxy.cpp +375 -0
  284. data/vendor/simpleble/simpledbus/src/base/Connection.cpp +222 -0
  285. data/vendor/simpleble/simpledbus/src/base/Exceptions.cpp +39 -0
  286. data/vendor/simpleble/simpledbus/src/base/Holder.cpp +739 -0
  287. data/vendor/simpleble/simpledbus/src/base/Logging.cpp +52 -0
  288. data/vendor/simpleble/simpledbus/src/base/Message.cpp +622 -0
  289. data/vendor/simpleble/simpledbus/src/base/Path.cpp +129 -0
  290. data/vendor/simpleble/simpledbus/src/interfaces/ObjectManager.cpp +58 -0
  291. data/vendor/simpleble/simpledbus/test/src/helpers/PythonRunner.cpp +53 -0
  292. data/vendor/simpleble/simpledbus/test/src/helpers/PythonRunner.h +24 -0
  293. data/vendor/simpleble/simpledbus/test/src/main.cpp +16 -0
  294. data/vendor/simpleble/simpledbus/test/src/test_holder.cpp +184 -0
  295. data/vendor/simpleble/simpledbus/test/src/test_message.cpp +397 -0
  296. data/vendor/simpleble/simpledbus/test/src/test_path.cpp +76 -0
  297. data/vendor/simpleble/simpledbus/test/src/test_proxy_children.cpp +109 -0
  298. data/vendor/simpleble/simpledbus/test/src/test_proxy_interfaces.cpp +102 -0
  299. data/vendor/simpleble/simpledbus/test/src/test_proxy_lifetime.cpp +18 -0
  300. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/ThreadRunner.h +89 -0
  301. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/android_utils.cpp +55 -0
  302. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/android_utils.h +18 -0
  303. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/simpleble_android.cpp +813 -0
  304. data/vendor/simpleble/simplejavable/cpp/src/core/AdapterWrapper.cpp +37 -0
  305. data/vendor/simpleble/simplejavable/cpp/src/core/AdapterWrapper.h +23 -0
  306. data/vendor/simpleble/simplejavable/cpp/src/core/Cache.cpp +58 -0
  307. data/vendor/simpleble/simplejavable/cpp/src/core/Cache.h +34 -0
  308. data/vendor/simpleble/simplejavable/cpp/src/core/PeripheralWrapper.cpp +17 -0
  309. data/vendor/simpleble/simplejavable/cpp/src/core/PeripheralWrapper.h +19 -0
  310. data/vendor/simpleble/simplejavable/cpp/src/java/lang/ArrayList.cpp +257 -0
  311. data/vendor/simpleble/simplejavable/cpp/src/java/lang/ArrayList.h +78 -0
  312. data/vendor/simpleble/simplejavable/cpp/src/java/lang/HashMap.cpp +96 -0
  313. data/vendor/simpleble/simplejavable/cpp/src/java/lang/HashMap.h +54 -0
  314. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Integer.cpp +93 -0
  315. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Integer.h +49 -0
  316. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Iterator.cpp +85 -0
  317. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Iterator.h +48 -0
  318. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/AdapterCallback.cpp +91 -0
  319. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/AdapterCallback.h +90 -0
  320. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Characteristic.cpp +35 -0
  321. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Characteristic.h +60 -0
  322. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/DataCallback.cpp +33 -0
  323. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/DataCallback.h +45 -0
  324. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Descriptor.cpp +30 -0
  325. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Descriptor.h +49 -0
  326. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/PeripheralCallback.cpp +41 -0
  327. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/PeripheralCallback.h +51 -0
  328. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Service.cpp +33 -0
  329. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Service.h +54 -0
  330. data/vendor/simpleble/simplejavable/cpp/src/simplejavable.cpp +361 -0
  331. data/vendor/simpleble/simplepyble/src/main.cpp +55 -0
  332. data/vendor/simpleble/simplepyble/src/wrap_adapter.cpp +106 -0
  333. data/vendor/simpleble/simplepyble/src/wrap_characteristic.cpp +56 -0
  334. data/vendor/simpleble/simplepyble/src/wrap_config.cpp +136 -0
  335. data/vendor/simpleble/simplepyble/src/wrap_descriptor.cpp +21 -0
  336. data/vendor/simpleble/simplepyble/src/wrap_peripheral.cpp +217 -0
  337. data/vendor/simpleble/simplepyble/src/wrap_service.cpp +32 -0
  338. data/vendor/simpleble/simplepyble/src/wrap_types.cpp +21 -0
  339. data/vendor/simpleble/simplersble/src/bindings/Bindings.cpp +338 -0
  340. data/vendor/simpleble/simplersble/src/bindings/Bindings.hpp +178 -0
  341. metadata +430 -0
@@ -0,0 +1,633 @@
1
+ // Formatting library for C++ - legacy printf implementation
2
+ //
3
+ // Copyright (c) 2012 - 2016, Victor Zverovich
4
+ // All rights reserved.
5
+ //
6
+ // For the license information refer to format.h.
7
+
8
+ #ifndef FMT_PRINTF_H_
9
+ #define FMT_PRINTF_H_
10
+
11
+ #ifndef FMT_MODULE
12
+ # include <algorithm> // std::max
13
+ # include <limits> // std::numeric_limits
14
+ #endif
15
+
16
+ #include "format.h"
17
+
18
+ FMT_BEGIN_NAMESPACE
19
+ FMT_BEGIN_EXPORT
20
+
21
+ template <typename T> struct printf_formatter {
22
+ printf_formatter() = delete;
23
+ };
24
+
25
+ template <typename Char> class basic_printf_context {
26
+ private:
27
+ basic_appender<Char> out_;
28
+ basic_format_args<basic_printf_context> args_;
29
+
30
+ static_assert(std::is_same<Char, char>::value ||
31
+ std::is_same<Char, wchar_t>::value,
32
+ "Unsupported code unit type.");
33
+
34
+ public:
35
+ using char_type = Char;
36
+ using parse_context_type = parse_context<Char>;
37
+ template <typename T> using formatter_type = printf_formatter<T>;
38
+ enum { builtin_types = 1 };
39
+
40
+ /// Constructs a `printf_context` object. References to the arguments are
41
+ /// stored in the context object so make sure they have appropriate lifetimes.
42
+ basic_printf_context(basic_appender<Char> out,
43
+ basic_format_args<basic_printf_context> args)
44
+ : out_(out), args_(args) {}
45
+
46
+ auto out() -> basic_appender<Char> { return out_; }
47
+ void advance_to(basic_appender<Char>) {}
48
+
49
+ auto locale() -> detail::locale_ref { return {}; }
50
+
51
+ auto arg(int id) const -> basic_format_arg<basic_printf_context> {
52
+ return args_.get(id);
53
+ }
54
+ };
55
+
56
+ namespace detail {
57
+
58
+ // Return the result via the out param to workaround gcc bug 77539.
59
+ template <bool IS_CONSTEXPR, typename T, typename Ptr = const T*>
60
+ FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr& out) -> bool {
61
+ for (out = first; out != last; ++out) {
62
+ if (*out == value) return true;
63
+ }
64
+ return false;
65
+ }
66
+
67
+ template <>
68
+ inline auto find<false, char>(const char* first, const char* last, char value,
69
+ const char*& out) -> bool {
70
+ out =
71
+ static_cast<const char*>(memchr(first, value, to_unsigned(last - first)));
72
+ return out != nullptr;
73
+ }
74
+
75
+ // Checks if a value fits in int - used to avoid warnings about comparing
76
+ // signed and unsigned integers.
77
+ template <bool IsSigned> struct int_checker {
78
+ template <typename T> static auto fits_in_int(T value) -> bool {
79
+ unsigned max = to_unsigned(max_value<int>());
80
+ return value <= max;
81
+ }
82
+ inline static auto fits_in_int(bool) -> bool { return true; }
83
+ };
84
+
85
+ template <> struct int_checker<true> {
86
+ template <typename T> static auto fits_in_int(T value) -> bool {
87
+ return value >= (std::numeric_limits<int>::min)() &&
88
+ value <= max_value<int>();
89
+ }
90
+ inline static auto fits_in_int(int) -> bool { return true; }
91
+ };
92
+
93
+ struct printf_precision_handler {
94
+ template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
95
+ auto operator()(T value) -> int {
96
+ if (!int_checker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
97
+ report_error("number is too big");
98
+ return (std::max)(static_cast<int>(value), 0);
99
+ }
100
+
101
+ template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
102
+ auto operator()(T) -> int {
103
+ report_error("precision is not integer");
104
+ return 0;
105
+ }
106
+ };
107
+
108
+ // An argument visitor that returns true iff arg is a zero integer.
109
+ struct is_zero_int {
110
+ template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
111
+ auto operator()(T value) -> bool {
112
+ return value == 0;
113
+ }
114
+
115
+ template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
116
+ auto operator()(T) -> bool {
117
+ return false;
118
+ }
119
+ };
120
+
121
+ template <typename T> struct make_unsigned_or_bool : std::make_unsigned<T> {};
122
+
123
+ template <> struct make_unsigned_or_bool<bool> {
124
+ using type = bool;
125
+ };
126
+
127
+ template <typename T, typename Context> class arg_converter {
128
+ private:
129
+ using char_type = typename Context::char_type;
130
+
131
+ basic_format_arg<Context>& arg_;
132
+ char_type type_;
133
+
134
+ public:
135
+ arg_converter(basic_format_arg<Context>& arg, char_type type)
136
+ : arg_(arg), type_(type) {}
137
+
138
+ void operator()(bool value) {
139
+ if (type_ != 's') operator()<bool>(value);
140
+ }
141
+
142
+ template <typename U, FMT_ENABLE_IF(std::is_integral<U>::value)>
143
+ void operator()(U value) {
144
+ bool is_signed = type_ == 'd' || type_ == 'i';
145
+ using target_type = conditional_t<std::is_same<T, void>::value, U, T>;
146
+ if (const_check(sizeof(target_type) <= sizeof(int))) {
147
+ // Extra casts are used to silence warnings.
148
+ using unsigned_type = typename make_unsigned_or_bool<target_type>::type;
149
+ if (is_signed)
150
+ arg_ = static_cast<int>(static_cast<target_type>(value));
151
+ else
152
+ arg_ = static_cast<unsigned>(static_cast<unsigned_type>(value));
153
+ } else {
154
+ // glibc's printf doesn't sign extend arguments of smaller types:
155
+ // std::printf("%lld", -42); // prints "4294967254"
156
+ // but we don't have to do the same because it's a UB.
157
+ if (is_signed)
158
+ arg_ = static_cast<long long>(value);
159
+ else
160
+ arg_ = static_cast<typename make_unsigned_or_bool<U>::type>(value);
161
+ }
162
+ }
163
+
164
+ template <typename U, FMT_ENABLE_IF(!std::is_integral<U>::value)>
165
+ void operator()(U) {} // No conversion needed for non-integral types.
166
+ };
167
+
168
+ // Converts an integer argument to T for printf, if T is an integral type.
169
+ // If T is void, the argument is converted to corresponding signed or unsigned
170
+ // type depending on the type specifier: 'd' and 'i' - signed, other -
171
+ // unsigned).
172
+ template <typename T, typename Context, typename Char>
173
+ void convert_arg(basic_format_arg<Context>& arg, Char type) {
174
+ arg.visit(arg_converter<T, Context>(arg, type));
175
+ }
176
+
177
+ // Converts an integer argument to char for printf.
178
+ template <typename Context> class char_converter {
179
+ private:
180
+ basic_format_arg<Context>& arg_;
181
+
182
+ public:
183
+ explicit char_converter(basic_format_arg<Context>& arg) : arg_(arg) {}
184
+
185
+ template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
186
+ void operator()(T value) {
187
+ arg_ = static_cast<typename Context::char_type>(value);
188
+ }
189
+
190
+ template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
191
+ void operator()(T) {} // No conversion needed for non-integral types.
192
+ };
193
+
194
+ // An argument visitor that return a pointer to a C string if argument is a
195
+ // string or null otherwise.
196
+ template <typename Char> struct get_cstring {
197
+ template <typename T> auto operator()(T) -> const Char* { return nullptr; }
198
+ auto operator()(const Char* s) -> const Char* { return s; }
199
+ };
200
+
201
+ // Checks if an argument is a valid printf width specifier and sets
202
+ // left alignment if it is negative.
203
+ class printf_width_handler {
204
+ private:
205
+ format_specs& specs_;
206
+
207
+ public:
208
+ inline explicit printf_width_handler(format_specs& specs) : specs_(specs) {}
209
+
210
+ template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
211
+ auto operator()(T value) -> unsigned {
212
+ auto width = static_cast<uint32_or_64_or_128_t<T>>(value);
213
+ if (detail::is_negative(value)) {
214
+ specs_.set_align(align::left);
215
+ width = 0 - width;
216
+ }
217
+ unsigned int_max = to_unsigned(max_value<int>());
218
+ if (width > int_max) report_error("number is too big");
219
+ return static_cast<unsigned>(width);
220
+ }
221
+
222
+ template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
223
+ auto operator()(T) -> unsigned {
224
+ report_error("width is not integer");
225
+ return 0;
226
+ }
227
+ };
228
+
229
+ // Workaround for a bug with the XL compiler when initializing
230
+ // printf_arg_formatter's base class.
231
+ template <typename Char>
232
+ auto make_arg_formatter(basic_appender<Char> iter, format_specs& s)
233
+ -> arg_formatter<Char> {
234
+ return {iter, s, locale_ref()};
235
+ }
236
+
237
+ // The `printf` argument formatter.
238
+ template <typename Char>
239
+ class printf_arg_formatter : public arg_formatter<Char> {
240
+ private:
241
+ using base = arg_formatter<Char>;
242
+ using context_type = basic_printf_context<Char>;
243
+
244
+ context_type& context_;
245
+
246
+ void write_null_pointer(bool is_string = false) {
247
+ auto s = this->specs;
248
+ s.set_type(presentation_type::none);
249
+ write_bytes<Char>(this->out, is_string ? "(null)" : "(nil)", s);
250
+ }
251
+
252
+ template <typename T> void write(T value) {
253
+ detail::write<Char>(this->out, value, this->specs, this->locale);
254
+ }
255
+
256
+ public:
257
+ printf_arg_formatter(basic_appender<Char> iter, format_specs& s,
258
+ context_type& ctx)
259
+ : base(make_arg_formatter(iter, s)), context_(ctx) {}
260
+
261
+ void operator()(monostate value) { write(value); }
262
+
263
+ template <typename T, FMT_ENABLE_IF(detail::is_integral<T>::value)>
264
+ void operator()(T value) {
265
+ // MSVC2013 fails to compile separate overloads for bool and Char so use
266
+ // std::is_same instead.
267
+ if (!std::is_same<T, Char>::value) {
268
+ write(value);
269
+ return;
270
+ }
271
+ format_specs s = this->specs;
272
+ if (s.type() != presentation_type::none &&
273
+ s.type() != presentation_type::chr) {
274
+ return (*this)(static_cast<int>(value));
275
+ }
276
+ s.set_sign(sign::none);
277
+ s.clear_alt();
278
+ s.set_fill(' '); // Ignore '0' flag for char types.
279
+ // align::numeric needs to be overwritten here since the '0' flag is
280
+ // ignored for non-numeric types
281
+ if (s.align() == align::none || s.align() == align::numeric)
282
+ s.set_align(align::right);
283
+ detail::write<Char>(this->out, static_cast<Char>(value), s);
284
+ }
285
+
286
+ template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
287
+ void operator()(T value) {
288
+ write(value);
289
+ }
290
+
291
+ void operator()(const char* value) {
292
+ if (value)
293
+ write(value);
294
+ else
295
+ write_null_pointer(this->specs.type() != presentation_type::pointer);
296
+ }
297
+
298
+ void operator()(const wchar_t* value) {
299
+ if (value)
300
+ write(value);
301
+ else
302
+ write_null_pointer(this->specs.type() != presentation_type::pointer);
303
+ }
304
+
305
+ void operator()(basic_string_view<Char> value) { write(value); }
306
+
307
+ void operator()(const void* value) {
308
+ if (value)
309
+ write(value);
310
+ else
311
+ write_null_pointer();
312
+ }
313
+
314
+ void operator()(typename basic_format_arg<context_type>::handle handle) {
315
+ auto parse_ctx = parse_context<Char>({});
316
+ handle.format(parse_ctx, context_);
317
+ }
318
+ };
319
+
320
+ template <typename Char>
321
+ void parse_flags(format_specs& specs, const Char*& it, const Char* end) {
322
+ for (; it != end; ++it) {
323
+ switch (*it) {
324
+ case '-': specs.set_align(align::left); break;
325
+ case '+': specs.set_sign(sign::plus); break;
326
+ case '0': specs.set_fill('0'); break;
327
+ case ' ':
328
+ if (specs.sign() != sign::plus) specs.set_sign(sign::space);
329
+ break;
330
+ case '#': specs.set_alt(); break;
331
+ default: return;
332
+ }
333
+ }
334
+ }
335
+
336
+ template <typename Char, typename GetArg>
337
+ auto parse_header(const Char*& it, const Char* end, format_specs& specs,
338
+ GetArg get_arg) -> int {
339
+ int arg_index = -1;
340
+ Char c = *it;
341
+ if (c >= '0' && c <= '9') {
342
+ // Parse an argument index (if followed by '$') or a width possibly
343
+ // preceded with '0' flag(s).
344
+ int value = parse_nonnegative_int(it, end, -1);
345
+ if (it != end && *it == '$') { // value is an argument index
346
+ ++it;
347
+ arg_index = value != -1 ? value : max_value<int>();
348
+ } else {
349
+ if (c == '0') specs.set_fill('0');
350
+ if (value != 0) {
351
+ // Nonzero value means that we parsed width and don't need to
352
+ // parse it or flags again, so return now.
353
+ if (value == -1) report_error("number is too big");
354
+ specs.width = value;
355
+ return arg_index;
356
+ }
357
+ }
358
+ }
359
+ parse_flags(specs, it, end);
360
+ // Parse width.
361
+ if (it != end) {
362
+ if (*it >= '0' && *it <= '9') {
363
+ specs.width = parse_nonnegative_int(it, end, -1);
364
+ if (specs.width == -1) report_error("number is too big");
365
+ } else if (*it == '*') {
366
+ ++it;
367
+ specs.width = static_cast<int>(
368
+ get_arg(-1).visit(detail::printf_width_handler(specs)));
369
+ }
370
+ }
371
+ return arg_index;
372
+ }
373
+
374
+ inline auto parse_printf_presentation_type(char c, type t, bool& upper)
375
+ -> presentation_type {
376
+ using pt = presentation_type;
377
+ constexpr auto integral_set = sint_set | uint_set | bool_set | char_set;
378
+ switch (c) {
379
+ case 'd': return in(t, integral_set) ? pt::dec : pt::none;
380
+ case 'o': return in(t, integral_set) ? pt::oct : pt::none;
381
+ case 'X': upper = true; FMT_FALLTHROUGH;
382
+ case 'x': return in(t, integral_set) ? pt::hex : pt::none;
383
+ case 'E': upper = true; FMT_FALLTHROUGH;
384
+ case 'e': return in(t, float_set) ? pt::exp : pt::none;
385
+ case 'F': upper = true; FMT_FALLTHROUGH;
386
+ case 'f': return in(t, float_set) ? pt::fixed : pt::none;
387
+ case 'G': upper = true; FMT_FALLTHROUGH;
388
+ case 'g': return in(t, float_set) ? pt::general : pt::none;
389
+ case 'A': upper = true; FMT_FALLTHROUGH;
390
+ case 'a': return in(t, float_set) ? pt::hexfloat : pt::none;
391
+ case 'c': return in(t, integral_set) ? pt::chr : pt::none;
392
+ case 's': return in(t, string_set | cstring_set) ? pt::string : pt::none;
393
+ case 'p': return in(t, pointer_set | cstring_set) ? pt::pointer : pt::none;
394
+ default: return pt::none;
395
+ }
396
+ }
397
+
398
+ template <typename Char, typename Context>
399
+ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
400
+ basic_format_args<Context> args) {
401
+ using iterator = basic_appender<Char>;
402
+ auto out = iterator(buf);
403
+ auto context = basic_printf_context<Char>(out, args);
404
+ auto parse_ctx = parse_context<Char>(format);
405
+
406
+ // Returns the argument with specified index or, if arg_index is -1, the next
407
+ // argument.
408
+ auto get_arg = [&](int arg_index) {
409
+ if (arg_index < 0)
410
+ arg_index = parse_ctx.next_arg_id();
411
+ else
412
+ parse_ctx.check_arg_id(--arg_index);
413
+ return detail::get_arg(context, arg_index);
414
+ };
415
+
416
+ const Char* start = parse_ctx.begin();
417
+ const Char* end = parse_ctx.end();
418
+ auto it = start;
419
+ while (it != end) {
420
+ if (!find<false, Char>(it, end, '%', it)) {
421
+ it = end; // find leaves it == nullptr if it doesn't find '%'.
422
+ break;
423
+ }
424
+ Char c = *it++;
425
+ if (it != end && *it == c) {
426
+ write(out, basic_string_view<Char>(start, to_unsigned(it - start)));
427
+ start = ++it;
428
+ continue;
429
+ }
430
+ write(out, basic_string_view<Char>(start, to_unsigned(it - 1 - start)));
431
+
432
+ auto specs = format_specs();
433
+ specs.set_align(align::right);
434
+
435
+ // Parse argument index, flags and width.
436
+ int arg_index = parse_header(it, end, specs, get_arg);
437
+ if (arg_index == 0) report_error("argument not found");
438
+
439
+ // Parse precision.
440
+ if (it != end && *it == '.') {
441
+ ++it;
442
+ c = it != end ? *it : 0;
443
+ if ('0' <= c && c <= '9') {
444
+ specs.precision = parse_nonnegative_int(it, end, 0);
445
+ } else if (c == '*') {
446
+ ++it;
447
+ specs.precision =
448
+ static_cast<int>(get_arg(-1).visit(printf_precision_handler()));
449
+ } else {
450
+ specs.precision = 0;
451
+ }
452
+ }
453
+
454
+ auto arg = get_arg(arg_index);
455
+ // For d, i, o, u, x, and X conversion specifiers, if a precision is
456
+ // specified, the '0' flag is ignored
457
+ if (specs.precision >= 0 && is_integral_type(arg.type())) {
458
+ // Ignore '0' for non-numeric types or if '-' present.
459
+ specs.set_fill(' ');
460
+ }
461
+ if (specs.precision >= 0 && arg.type() == type::cstring_type) {
462
+ auto str = arg.visit(get_cstring<Char>());
463
+ auto str_end = str + specs.precision;
464
+ auto nul = std::find(str, str_end, Char());
465
+ auto sv = basic_string_view<Char>(
466
+ str, to_unsigned(nul != str_end ? nul - str : specs.precision));
467
+ arg = sv;
468
+ }
469
+ if (specs.alt() && arg.visit(is_zero_int())) specs.clear_alt();
470
+ if (specs.fill_unit<Char>() == '0') {
471
+ if (is_arithmetic_type(arg.type()) && specs.align() != align::left) {
472
+ specs.set_align(align::numeric);
473
+ } else {
474
+ // Ignore '0' flag for non-numeric types or if '-' flag is also present.
475
+ specs.set_fill(' ');
476
+ }
477
+ }
478
+
479
+ // Parse length and convert the argument to the required type.
480
+ c = it != end ? *it++ : 0;
481
+ Char t = it != end ? *it : 0;
482
+ switch (c) {
483
+ case 'h':
484
+ if (t == 'h') {
485
+ ++it;
486
+ t = it != end ? *it : 0;
487
+ convert_arg<signed char>(arg, t);
488
+ } else {
489
+ convert_arg<short>(arg, t);
490
+ }
491
+ break;
492
+ case 'l':
493
+ if (t == 'l') {
494
+ ++it;
495
+ t = it != end ? *it : 0;
496
+ convert_arg<long long>(arg, t);
497
+ } else {
498
+ convert_arg<long>(arg, t);
499
+ }
500
+ break;
501
+ case 'j': convert_arg<intmax_t>(arg, t); break;
502
+ case 'z': convert_arg<size_t>(arg, t); break;
503
+ case 't': convert_arg<std::ptrdiff_t>(arg, t); break;
504
+ case 'L':
505
+ // printf produces garbage when 'L' is omitted for long double, no
506
+ // need to do the same.
507
+ break;
508
+ default: --it; convert_arg<void>(arg, c);
509
+ }
510
+
511
+ // Parse type.
512
+ if (it == end) report_error("invalid format string");
513
+ char type = static_cast<char>(*it++);
514
+ if (is_integral_type(arg.type())) {
515
+ // Normalize type.
516
+ switch (type) {
517
+ case 'i':
518
+ case 'u': type = 'd'; break;
519
+ case 'c':
520
+ arg.visit(char_converter<basic_printf_context<Char>>(arg));
521
+ break;
522
+ }
523
+ }
524
+ bool upper = false;
525
+ specs.set_type(parse_printf_presentation_type(type, arg.type(), upper));
526
+ if (specs.type() == presentation_type::none)
527
+ report_error("invalid format specifier");
528
+ if (upper) specs.set_upper();
529
+
530
+ start = it;
531
+
532
+ // Format argument.
533
+ arg.visit(printf_arg_formatter<Char>(out, specs, context));
534
+ }
535
+ write(out, basic_string_view<Char>(start, to_unsigned(it - start)));
536
+ }
537
+ } // namespace detail
538
+
539
+ using printf_context = basic_printf_context<char>;
540
+ using wprintf_context = basic_printf_context<wchar_t>;
541
+
542
+ using printf_args = basic_format_args<printf_context>;
543
+ using wprintf_args = basic_format_args<wprintf_context>;
544
+
545
+ /// Constructs an `format_arg_store` object that contains references to
546
+ /// arguments and can be implicitly converted to `printf_args`.
547
+ template <typename Char = char, typename... T>
548
+ inline auto make_printf_args(T&... args)
549
+ -> decltype(fmt::make_format_args<basic_printf_context<Char>>(args...)) {
550
+ return fmt::make_format_args<basic_printf_context<Char>>(args...);
551
+ }
552
+
553
+ template <typename Char> struct vprintf_args {
554
+ using type = basic_format_args<basic_printf_context<Char>>;
555
+ };
556
+
557
+ template <typename Char>
558
+ inline auto vsprintf(basic_string_view<Char> fmt,
559
+ typename vprintf_args<Char>::type args)
560
+ -> std::basic_string<Char> {
561
+ auto buf = basic_memory_buffer<Char>();
562
+ detail::vprintf(buf, fmt, args);
563
+ return {buf.data(), buf.size()};
564
+ }
565
+
566
+ /**
567
+ * Formats `args` according to specifications in `fmt` and returns the result
568
+ * as as string.
569
+ *
570
+ * **Example**:
571
+ *
572
+ * std::string message = fmt::sprintf("The answer is %d", 42);
573
+ */
574
+ template <typename S, typename... T, typename Char = detail::char_t<S>>
575
+ inline auto sprintf(const S& fmt, const T&... args) -> std::basic_string<Char> {
576
+ return vsprintf(detail::to_string_view(fmt),
577
+ fmt::make_format_args<basic_printf_context<Char>>(args...));
578
+ }
579
+
580
+ template <typename Char>
581
+ inline auto vfprintf(std::FILE* f, basic_string_view<Char> fmt,
582
+ typename vprintf_args<Char>::type args) -> int {
583
+ auto buf = basic_memory_buffer<Char>();
584
+ detail::vprintf(buf, fmt, args);
585
+ size_t size = buf.size();
586
+ return std::fwrite(buf.data(), sizeof(Char), size, f) < size
587
+ ? -1
588
+ : static_cast<int>(size);
589
+ }
590
+
591
+ /**
592
+ * Formats `args` according to specifications in `fmt` and writes the output
593
+ * to `f`.
594
+ *
595
+ * **Example**:
596
+ *
597
+ * fmt::fprintf(stderr, "Don't %s!", "panic");
598
+ */
599
+ template <typename S, typename... T, typename Char = detail::char_t<S>>
600
+ inline auto fprintf(std::FILE* f, const S& fmt, const T&... args) -> int {
601
+ return vfprintf(f, detail::to_string_view(fmt),
602
+ make_printf_args<Char>(args...));
603
+ }
604
+
605
+ template <typename Char>
606
+ FMT_DEPRECATED inline auto vprintf(basic_string_view<Char> fmt,
607
+ typename vprintf_args<Char>::type args)
608
+ -> int {
609
+ return vfprintf(stdout, fmt, args);
610
+ }
611
+
612
+ /**
613
+ * Formats `args` according to specifications in `fmt` and writes the output
614
+ * to `stdout`.
615
+ *
616
+ * **Example**:
617
+ *
618
+ * fmt::printf("Elapsed time: %.2f seconds", 1.23);
619
+ */
620
+ template <typename... T>
621
+ inline auto printf(string_view fmt, const T&... args) -> int {
622
+ return vfprintf(stdout, fmt, make_printf_args(args...));
623
+ }
624
+ template <typename... T>
625
+ FMT_DEPRECATED inline auto printf(basic_string_view<wchar_t> fmt,
626
+ const T&... args) -> int {
627
+ return vfprintf(stdout, fmt, make_printf_args<wchar_t>(args...));
628
+ }
629
+
630
+ FMT_END_EXPORT
631
+ FMT_END_NAMESPACE
632
+
633
+ #endif // FMT_PRINTF_H_