You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

873 lines
25 KiB

1 year ago
  1. /**
  2. * @file ISettingsProvider.h
  3. * @brief Settings provider interface.
  4. * @copyright VisionLabs LLC
  5. * @date 06.11.2015
  6. * */
  7. #pragma once
  8. #include <fsdk/IObject.h>
  9. #include <fsdk/Types.h>
  10. #include "FSDKError.h"
  11. #include <cstring>
  12. #include <string>
  13. namespace fsdk {
  14. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  15. DECLARE_SMARTPTR(ISettingsProvider);
  16. #endif
  17. /**
  18. * @addtogroup CoreGroup SDK core interfaces
  19. * @brief Common interfaces and macros shared across all SDK objects.
  20. * @{
  21. * */
  22. /**
  23. * @brief SDK settings provider interface.
  24. * @details Takes care of loading and parsing of SDK configuration files.
  25. * */
  26. struct FSDK_API ISettingsProvider : IRefCounted {
  27. /**
  28. * @brief Config parsing error codes.
  29. * */
  30. enum class Error : uint32_t {
  31. Ok, //!< No error
  32. IOError, //!< Error reading from file/stream
  33. Memory, //!< Could not allocate memory
  34. Internal, //!< Internal error occurred
  35. InvalidPi, //!< Parsing error occurred while parsing document declaration/processing instruction
  36. InvalidTag, //!< Parser could not determine tag type
  37. InvalidCdata, //!< Parsing error occurred while parsing CDATA section
  38. FileNotFound, //!< File was not found during load_file()
  39. InvalidPcdata, //!< Parsing error occurred while parsing PCDATA section
  40. InvalidDocType, //!< Parsing error occurred while parsing document type declaration
  41. InvalidSettings, //!< Settings section is invalid or absent.
  42. InvalidComment, //!< Parsing error occurred while parsing comment
  43. InvalidAttribute, //!< Parsing error occurred while parsing element attribute
  44. InvalidEndElement, //!< Parsing error occurred while parsing end element tag
  45. AppendInvalidRoot, //!< Unable to append nodes since root type is not node_element or node_document (exclusive to xml_node::append_buffer)
  46. NoDocumentElement, //!< Parsing resulted in a document without element nodes
  47. EndElementMismatch, //!< There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or there was an excessive closing tag)
  48. InvalidStartElement, //!< Parsing error occurred while parsing start element tag
  49. MemoryAllocationFailed, //!< memory allocation failed for internal data
  50. };
  51. /**
  52. * @brief Get settings path this provider is bound to.
  53. * @details This is the same path that was given to load().
  54. * @returns path string.
  55. * */
  56. virtual const char* getDefaultPath() const noexcept = 0;
  57. /**
  58. * @brief Load settings from given path.
  59. * @details if `path` is null, load from the default path; @see getDefaultPath().
  60. * @return Result with error code specified by ISettingsProvider::ParseError.
  61. * @see Result and ISettingsProvider::ParseError.
  62. * */
  63. virtual Result<Error> load(const char* path) noexcept = 0;
  64. /**
  65. * @brief Save settings values using the default path.
  66. * @details path may be null, in this case a path from getDefaultPath() will be used.
  67. * @returns true if succeded, false otherwise.
  68. * */
  69. virtual bool save(const char* path) const noexcept = 0;
  70. /**
  71. * @brief Clear settings.
  72. * @returns true if succeded, false otherwise.
  73. * */
  74. virtual void clear() noexcept = 0;
  75. /**
  76. * Check if there are loaded settings.
  77. * @returns true if provider is empty.
  78. * */
  79. virtual bool isEmpty() const noexcept = 0;
  80. /**
  81. * @brief Configuration parameter value.
  82. * */
  83. struct FSDK_API Value {
  84. /**
  85. * @brief Value data.
  86. * */
  87. union Data {
  88. struct Int1 { int m_value; } m_int1; //!< Data as integer.
  89. struct Int2 { int m_value[2]; } m_int2; //!< Data as 2D integer.
  90. struct Int3 { int m_value[3]; } m_int3; //!< Data as 3D integer.
  91. struct Int4 { int m_value[4]; } m_int4; //!< Data as 4D integer.
  92. struct Float1 { float m_value; } m_float1; //!< Data as float.
  93. struct Float2 { float m_value[2]; } m_float2; //!< Data as 2D float.
  94. struct Float3 { float m_value[3]; } m_float3; //!< Data as 3D float.
  95. struct Float4 { float m_value[4]; } m_float4; //!< Data as 4D float.
  96. struct String { char* m_value; } m_string; //!< Data as string.
  97. } m_data; //!< Data storage.
  98. /**
  99. * @brief Value type.
  100. * */
  101. enum Type {
  102. Undefined, //!< Unkown value type.
  103. Int1, //!< Integer.
  104. Int2, //!< 2D integer.
  105. Int3, //!< 3D integer.
  106. Int4, //!< 4D integer.
  107. Float1, //!< floating point.
  108. Float2, //!< 2D floating point.
  109. Float3, //!< 3D floating point.
  110. Float4, //!< 4D floating point.
  111. String //!< Short string.
  112. } m_type; //!< Data type..
  113. /**
  114. * @brief Initialize an empty value.
  115. * @details Value type will be set to `Undefined`.
  116. * */
  117. Value() noexcept;
  118. /**
  119. * @brief Initialize an integer value.
  120. * @param x integer value.
  121. * */
  122. Value(int x) noexcept;
  123. /**
  124. * @brief Initialize a 2d integer value.
  125. * @param x 1st value.
  126. * @param y 2nd value.
  127. * */
  128. Value(int x, int y) noexcept;
  129. /**
  130. * @brief Initialize a 3d integer value.
  131. * @param x 1st value.
  132. * @param y 2nd value.
  133. * @param z 3rd value.
  134. * */
  135. Value(int x, int y, int z) noexcept;
  136. /**
  137. * @brief Initialize a 4d integer value.
  138. * @param x 1st value.
  139. * @param y 2nd value.
  140. * @param z 3rd value.
  141. * @param w 4th value.
  142. * */
  143. Value(int x, int y, int z, int w) noexcept;
  144. /**
  145. * @brief Initialize a float value.
  146. * @param x float value.
  147. * */
  148. Value(float x) noexcept;
  149. /**
  150. * @brief Initialize a 2d float value.
  151. * @param x 1st value.
  152. * @param y 2nd value.
  153. * */
  154. Value(float x, float y) noexcept;
  155. /**
  156. * @brief Initialize a 3d float value.
  157. * @param x 1st value.
  158. * @param y 2nd value.
  159. * @param z 3rd value.
  160. * */
  161. Value(float x, float y, float z) noexcept;
  162. /**
  163. * @brief Initialize a 4d float value.
  164. * @param x 1st value.
  165. * @param y 2nd value.
  166. * @param z 3rd value.
  167. * @param w 4th value.
  168. * */
  169. Value(float x, float y, float z, float w) noexcept;
  170. /**
  171. * @brief Initialize a string value.
  172. * @note Only short strings (<64 chars) are supported.
  173. * @param string string value.
  174. * */
  175. Value(const char* string) noexcept;
  176. /**
  177. * @brief Initialize a rect value.
  178. * @param rect rect value.
  179. * */
  180. Value(const Rect& rect) noexcept;
  181. /**
  182. * @brief Initialize a size value.
  183. * @param size size value.
  184. * */
  185. Value(const Size& size) noexcept;
  186. /**
  187. * @brief Initialize a point value.
  188. * @param point point value.
  189. * */
  190. Value(const Point2f& point) noexcept;
  191. /**
  192. * @brief Initialize a bool value.
  193. * @param x bool value.
  194. * */
  195. Value(bool x) noexcept;
  196. /**
  197. * @brief Check if value type is not `Undefined`.
  198. * @returns true if value type is not `Undefined`.
  199. * */
  200. operator bool() const noexcept;
  201. /**
  202. * @brief Check if value type is of concrete type.
  203. * @param type type to check.
  204. * @returns true if value type is equal to `type`.
  205. * */
  206. bool is(Type type) const noexcept;
  207. /**
  208. * @brief Set a string value.
  209. * @param string the value.
  210. * */
  211. bool setString(const char* string) noexcept;
  212. /**
  213. * @brief Get a string value.
  214. * @param [out] string the value.
  215. * @note function fails if actual value type is not string; in this case `string` isn't modified.
  216. * @returns true if succeeded; false otherwise.
  217. * */
  218. bool getString(char* string) const noexcept;
  219. /**
  220. * @brief Set a rect value.
  221. * @param rect the value.
  222. * */
  223. void setRect(const Rect& rect) noexcept;
  224. /**
  225. * @brief Get a rect value.
  226. * @param [out] rect the value.
  227. * @note function fails if actual value type is not convertible to rect; in this case `rect` isn't modified.
  228. * @returns true if succeeded; false otherwise.
  229. * */
  230. bool getRect(Rect* rect) const noexcept;
  231. /**
  232. * @brief Set a size value.
  233. * @param size the value.
  234. * */
  235. void setSize(const Size& size) noexcept;
  236. /**
  237. * @brief Get a size value.
  238. * @param [out] size the value.
  239. * @note function fails if actual value type is not convertible to size; in this case `size` isn't modified.
  240. * @returns true if succeeded; false otherwise.
  241. * */
  242. bool getSize(Size* size) const noexcept;
  243. /**
  244. * @brief Set a Point2i value.
  245. * @param point the value.
  246. * */
  247. void setPoint2i(const Point2i& point) noexcept;
  248. /**
  249. * @brief Get a Point2i value.
  250. * @param [out] point the value.
  251. * @note function fails if actual value type is not convertible to Point2i; in this case `point` isn't modified.
  252. * @returns true if succeeded; false otherwise.
  253. * */
  254. bool getPoint2i(Point2i* point) const noexcept;
  255. /**
  256. * @brief Set a setPoint2f value.
  257. * @param point the value.
  258. * */
  259. void setPoint2f(const Point2f& point) noexcept;
  260. /**
  261. * @brief Get a Point2f value.
  262. * @param [out] point the value.
  263. * @note function fails if actual value type is not convertible to Point2f; in this case `point` isn't modified.
  264. * @returns true if succeeded; false otherwise.
  265. * */
  266. bool getPoint2f(Point2f* point) const noexcept;
  267. /**
  268. * @brief Set a bool value.
  269. * @param x the value.
  270. * */
  271. void setBool(bool x) noexcept;
  272. /**
  273. * @brief Get a bool value.
  274. * @param [out] x the value.
  275. * @note function fails if actual value type is not convertible to bool; in this case `x` isn't modified.
  276. * @returns true if succeeded; false otherwise.
  277. * */
  278. bool getBool(bool* x) const noexcept;
  279. /**
  280. * @brief Set an int value.
  281. * @param x the value.
  282. * */
  283. void setInt(int x) noexcept;
  284. /**
  285. * @brief Get an int value.
  286. * @param [out] x the value.
  287. * @note function fails if actual value type is not an int; in this case `x` isn't modified.
  288. * @returns true if succeeded; false otherwise.
  289. * */
  290. bool getInt(int* x) const noexcept;
  291. /**
  292. * @brief Set a 2d int value.
  293. * @param x 1st value.
  294. * @param y 2nd value.
  295. * */
  296. void setInt(int x, int y) noexcept;
  297. /**
  298. * @brief Get a 2d int value.
  299. * @param [out] x 1st value.
  300. * @param [out] y 2nd value.
  301. * @note function fails if actual value type is not a 2d int; in this case output parameters aren't modified.
  302. * @returns true if succeeded; false otherwise.
  303. * */
  304. bool getInt(int* x, int* y) const noexcept;
  305. /**
  306. * @brief Set a 3d int value.
  307. * @param x 1st value.
  308. * @param y 2nd value.
  309. * @param z 3rd value.
  310. * */
  311. void setInt(int x, int y, int z) noexcept;
  312. /**
  313. * @brief Get a 3d int value.
  314. * @param [out] x 1st value.
  315. * @param [out] y 2nd value.
  316. * @param [out] z 3rd value.
  317. * @note function fails if actual value type is not a 3d int; in this case output parameters aren't modified.
  318. * @returns true if succeeded; false otherwise.
  319. * */
  320. bool getInt(int* x, int* y, int* z) const noexcept;
  321. /**
  322. * @brief Set a 4d int value.
  323. * @param x 1st value.
  324. * @param y 2nd value.
  325. * @param z 3rd value.
  326. * @param w 4th value.
  327. * */
  328. void setInt(int x, int y, int z, int w) noexcept;
  329. /**
  330. * @brief Get a 4d int value.
  331. * @param [out] x 1st value.
  332. * @param [out] y 2nd value.
  333. * @param [out] z 3rd value.
  334. * @param [out] w 4th value.
  335. * @note function fails if actual value type is not a 4d int; in this case output parameters aren't modified.
  336. * @returns true if succeeded; false otherwise.
  337. * */
  338. bool getInt(int* x, int* y, int* z, int* w) const noexcept;
  339. /**
  340. * @brief Set a float value.
  341. * @param x the value.
  342. * */
  343. void setFloat(float x) noexcept;
  344. /**
  345. * @brief Get a float value.
  346. * @param [out] x the value.
  347. * @note function fails if actual value type is not a float; in this case 'x' isn't modified.
  348. * @returns true if succeeded; false otherwise.
  349. * */
  350. bool getFloat(float* x) const noexcept;
  351. /**
  352. * @brief Set a 2d float value.
  353. * @param x 1st value.
  354. * @param y 2nd value.
  355. * */
  356. void setFloat(float x, float y) noexcept;
  357. /**
  358. * @brief Get a 2d float value.
  359. * @param [out] x 1st value.
  360. * @param [out] y 2nd value.
  361. * @note function fails if actual value type is not a 2d float; in this case output parameters aren't modified.
  362. * @returns true if succeeded; false otherwise.
  363. * */
  364. bool getFloat(float* x, float* y) const noexcept;
  365. /**
  366. * @brief Set a 3d float value.
  367. * @param x 1st value.
  368. * @param y 2nd value.
  369. * @param z 3rd value.
  370. * */
  371. void setFloat(float x, float y, float z) noexcept;
  372. /**
  373. * @brief Get a 3d float value.
  374. * @param [out] x 1st value.
  375. * @param [out] y 2nd value.
  376. * @param [out] z 3rd value.
  377. * @note function fails if actual value type is not a 3d float; in this case output parameters aren't modified.
  378. * @returns true if succeeded; false otherwise.
  379. * */
  380. bool getFloat(float* x, float* y, float* z) const noexcept;
  381. /**
  382. * @brief Set a 4d float value.
  383. * @param x 1st value.
  384. * @param y 2nd value.
  385. * @param z 3rd value.
  386. * @param w 4th value.
  387. * */
  388. void setFloat(float x, float y, float z, float w) noexcept;
  389. /**
  390. * @brief Get a 4d float value.
  391. * @param [out] x 1st value.
  392. * @param [out] y 2nd value.
  393. * @param [out] z 3rd value.
  394. * @param [out] w 4th value.
  395. * @note function fails if actual value type is not a 4d float; in this case output parameters aren't modified.
  396. * @returns true if succeeded; false otherwise.
  397. * */
  398. bool getFloat(float* x, float* y, float* z, float* w) const noexcept;
  399. /**
  400. * @brief Safely get a float.
  401. * @details If actual value type is float, the value is returned; if not a fallback value is returned.
  402. * @param defaultValue fallback value (optional).
  403. * @returns value.
  404. * */
  405. float asFloat(float defaultValue = 0.f) const noexcept;
  406. /**
  407. * @brief Safely get a Point2f.
  408. * @details If actual value type is convertible to Point2f, the value is returned; if not a fallback value is returned.
  409. * @param defaultValue fallback value (optional).
  410. * @returns value.
  411. * */
  412. Point2f asPoint2f(const Point2f& defaultValue = Point2f()) const noexcept;
  413. /**
  414. * @brief Safely get a boolean.
  415. * @details If actual value type is convertible to bool, the value is returned; if not a fallback value is returned.
  416. * @param defaultValue fallback value (optional).
  417. * @returns value.
  418. * */
  419. bool asBool(bool defaultValue = false) const noexcept;
  420. /**
  421. * @brief Safely get an integer.
  422. * @details If actual value type is Int, the value is returned; if not a fallback value is returned.
  423. * @param defaultValue fallback value (optional).
  424. * @returns value.
  425. * */
  426. int asInt(int defaultValue = 0) const noexcept;
  427. /**
  428. * @brief Safely get a Size.
  429. * @details If actual value type is convertible to Size, the value is returned; if not a fallback value is returned.
  430. * @param defaultValue fallback value (optional).
  431. * @returns value.
  432. * */
  433. Size asSize(const Size& defaultValue = Size()) const noexcept;
  434. /**
  435. * @brief Safely get a Point2i.
  436. * @details If actual value type is convertible to Point2i, the value is returned; if not a fallback value is returned.
  437. * @param defaultValue fallback value (optional).
  438. * @returns value.
  439. * */
  440. Point2i asPoint2i(const Point2i& defaultValue = Point2i()) const noexcept;
  441. /**
  442. * @brief Safely get a Rect.
  443. * @details If actual value type is convertible to Rect, the value is returned; if not a fallback value is returned.
  444. * @param defaultValue fallback value (optional).
  445. * @returns value.
  446. * */
  447. Rect asRect(const Rect& defaultValue = Rect()) const noexcept;
  448. /**
  449. * @brief Safely get a string.
  450. * @details If actual value type is String, the value is returned; if not a fallback value is returned.
  451. * @note Doesn't allocate or copy memory.
  452. * @param defaultValue fallback value (optional).
  453. * @returns value.
  454. * */
  455. const char* asString(const char* defaultValue = "") const noexcept;
  456. inline Value(const Value& other) = delete;
  457. Value(Value&& other);
  458. inline Value& operator=(const Value& other) = delete;
  459. Value& operator=(Value&& other);
  460. void swap(Value& first, Value& second);
  461. ~Value();
  462. };
  463. /** @brief Configuration parameter key. */
  464. struct FSDK_API Key {
  465. /** @brief Initialize an empty key. */
  466. Key() noexcept;
  467. /**
  468. * @brief Initialize a key.
  469. * @param section section name.
  470. * @param parameter parameter name.
  471. * */
  472. Key(const char* section, const char* parameter) noexcept;
  473. /**
  474. * @brief Get section name.
  475. * @returns section name.
  476. * */
  477. const char* getSection() const noexcept;
  478. /**
  479. * @brief Get parameter name.
  480. * @returns parameter name.
  481. * */
  482. const char* getParameter() const noexcept;
  483. /**
  484. * @brief Set section name.
  485. * @param section section name.
  486. * */
  487. void setSection(const char* section) noexcept;
  488. /**
  489. * @brief Set parameter name.
  490. * @param parameter parameter name.
  491. * */
  492. void setParameter(const char* parameter) noexcept;
  493. /**
  494. * @brief Operator `Less`.
  495. * @param other other key.
  496. * @returns comparison result.
  497. * */
  498. bool operator < (const ISettingsProvider::Key& other) const noexcept;
  499. protected:
  500. static const unsigned int m_bufferLength = 128;
  501. char m_section [m_bufferLength]; //!< Config section name.
  502. char m_parameter [m_bufferLength]; //!< Config parameter name.
  503. };
  504. /** @brief Configuration parameter description. */
  505. struct FSDK_API Desc {
  506. /** @brief Initialize an empty description. */
  507. Desc() noexcept;
  508. /**
  509. * @brief Initialize a description.
  510. * @param desc description text.
  511. * */
  512. Desc(const char* desc) noexcept;
  513. /**
  514. * @brief Get description text.
  515. * @returns description text.
  516. * */
  517. const char* getDesc() const noexcept;
  518. /**
  519. * @brief Set description text.
  520. * @param desc description text.
  521. * */
  522. void setDesc(const char* desc) noexcept;
  523. protected:
  524. static const unsigned int m_bufferLength = 256;
  525. char m_desc [m_bufferLength]; //!< Parameter description text.
  526. };
  527. /** @brief Configuration parameter entry. */
  528. struct FSDK_API Entry {
  529. Value m_value; //!< Parameter value.
  530. Desc m_desc; //!< Parameter description.
  531. /** @brief Initialize an empty entry. */
  532. Entry() noexcept = default;
  533. Entry(Entry&& right);
  534. Entry& operator=(Entry&& right);
  535. void swap(Entry& first, Entry& second);
  536. /**
  537. * @brief Initialize an entry.
  538. * @param desc description.
  539. * @param value value.
  540. * */
  541. Entry(const Desc& desc, Value&& value) noexcept;
  542. /**
  543. * @brief Set description.
  544. * @param desc description.
  545. * */
  546. void setDesc(const Desc& desc) noexcept;
  547. /**
  548. * @brief Set value.
  549. * @param value value.
  550. * */
  551. void setValue(Value&& value) noexcept;
  552. /**
  553. * @brief Get description.
  554. * @returns description.
  555. * */
  556. const Desc& getDesc() const noexcept;
  557. /**
  558. * @brief Get value.
  559. * @returns value.
  560. * */
  561. const Value& getValue() const noexcept;
  562. };
  563. /**
  564. * @brief Set parameter description.
  565. * @details Lookup parameter by key.
  566. * Creates a parameter if it does not already exist.
  567. * @param key parameter key.
  568. * @param desc parameter description.
  569. * */
  570. virtual void setDesc(const Key& key, const Desc& desc) noexcept = 0;
  571. /**
  572. * @brief Set parameter description.
  573. * @details Lookup parameter by key.
  574. * Creates a parameter if it does not already exist.
  575. * @param section parameter section.
  576. * @param parameter parameter name.
  577. * @param desc parameter description.
  578. * */
  579. void setDesc(
  580. const char* section,
  581. const char* parameter,
  582. const Desc& desc) noexcept;
  583. /**
  584. * @brief Set parameter value.
  585. * @details Lookup parameter by key.
  586. * Creates a parameter if it does not already exist.
  587. * @param key parameter key.
  588. * @param value parameter value.
  589. * */
  590. virtual void setValue(const Key& key, Value&& value) noexcept = 0;
  591. /**
  592. * @brief Set parameter value.
  593. * @details Lookup parameter by key.
  594. * Creates a parameter if it does not already exist.
  595. * @param section parameter section.
  596. * @param parameter parameter name.
  597. * @param value parameter value.
  598. * */
  599. void setValue(
  600. const char* section,
  601. const char* parameter,
  602. Value&& value) noexcept;
  603. /**
  604. * @brief Set parameter.
  605. * @details Lookup parameter by key.
  606. * Creates a parameter if it does not already exist.
  607. * @param key parameter key.
  608. * @param entry parameter entry.
  609. * */
  610. virtual void setEntry(const Key& key, Entry&& entry) noexcept = 0;
  611. /**
  612. * @brief Set parameter.
  613. * @details Lookup parameter by key.
  614. * Creates a parameter if it does not already exist.
  615. * @param key parameter key.
  616. * @param desc parameter description.
  617. * @param value parameter value.
  618. * */
  619. void setEntry(
  620. const Key& key,
  621. const Desc& desc,
  622. Value&& value) noexcept;
  623. /**
  624. * @brief Set parameter.
  625. * @details Lookup parameter by key.
  626. * Creates a parameter if it does not already exist.
  627. * @param section parameter section.
  628. * @param parameter parameter name.
  629. * @param desc parameter description.
  630. * @param value parameter value.
  631. * */
  632. void setEntry(
  633. const char* section,
  634. const char* parameter,
  635. const Desc& desc,
  636. Value&& value) noexcept;
  637. /**
  638. * @brief Find parameter entry.
  639. * @details Lookup parameter by key.
  640. * Return empty entry if the parameters does not exist.
  641. * @param key parameter key.
  642. * @returns parameter entry.
  643. * */
  644. virtual const Entry& getEntry(const Key& key) const noexcept = 0;
  645. /**
  646. * @brief Get parameter description.
  647. * @details Lookup parameter by key.
  648. * Return empty description if the parameters does not exist.
  649. * @param key parameter key.
  650. * @returns parameter description.
  651. * */
  652. Desc getDesc(const Key& key) const noexcept;
  653. /**
  654. * @brief Get parameter description.
  655. * @details Lookup parameter by key.
  656. * Return empty description if the parameters does not exist.
  657. * @param section parameter section.
  658. * @param parameter parameter name.
  659. * @returns parameter description.
  660. * */
  661. Desc getDesc(const char* section, const char* parameter) const noexcept;
  662. /**
  663. * @brief Get parameter value.
  664. * @details Lookup parameter by key.
  665. * Return empty value if the parameters does not exist.
  666. * @param key parameter key.
  667. * @returns parameter value.
  668. * */
  669. const Value& getValue(const Key& key) const noexcept;
  670. /**
  671. * @brief Get parameter value.
  672. * @details Lookup parameter by key.
  673. * Return empty value if the parameters does not exist.
  674. * @param section parameter section.
  675. * @param parameter parameter name.
  676. * @returns parameter value.
  677. * */
  678. const Value& getValue(const char* section, const char* parameter) const noexcept;
  679. };
  680. /**
  681. * @brief Create a settings provider.
  682. * @param [in] path configuration file path.
  683. * @return settings provider object if succeeded, null if failed.
  684. * */
  685. FSDK_API fsdk::ResultValue<fsdk::FSDKError, fsdk::ISettingsProviderPtr>
  686. createSettingsProvider(const char* path) noexcept;
  687. /**
  688. * @brief Specialized for ISettingsProvider::ParseError.
  689. * */
  690. template<>
  691. struct ErrorTraits<ISettingsProvider::Error> {
  692. static bool isOk(ISettingsProvider::Error error) noexcept {
  693. return error == ISettingsProvider::Error::Ok;
  694. }
  695. static const char* toString (ISettingsProvider::Error error) noexcept {
  696. switch(error) {
  697. case ISettingsProvider::Error::Ok:
  698. return "Ok";
  699. case ISettingsProvider::Error::Memory:
  700. return "Could not allocate memory";
  701. case ISettingsProvider::Error::IOError:
  702. return "Error reading from file";
  703. case ISettingsProvider::Error::Internal:
  704. return "Internal error";
  705. case ISettingsProvider::Error::InvalidPi:
  706. return "Error during document declaration/processing instruction parsing";
  707. case ISettingsProvider::Error::InvalidTag:
  708. return "Parser could not determine tag type";
  709. case ISettingsProvider::Error::InvalidCdata:
  710. return "Error during CDATA section parsing";
  711. case ISettingsProvider::Error::FileNotFound:
  712. return "File was not found";
  713. case ISettingsProvider::Error::InvalidPcdata:
  714. return "Error during PCDATA section parsing";
  715. case ISettingsProvider::Error::InvalidComment:
  716. return "Error during comment parsing";
  717. case ISettingsProvider::Error::InvalidDocType:
  718. return "Error during document type declaration parsing";
  719. case ISettingsProvider::Error::InvalidSettings:
  720. return "Settings sections is invalid or absent";
  721. case ISettingsProvider::Error::InvalidAttribute:
  722. return "Error during element attribute parsing";
  723. case ISettingsProvider::Error::InvalidEndElement:
  724. return "Error during end element tag parsing";
  725. case ISettingsProvider::Error::AppendInvalidRoot:
  726. return "Root type is not node_element or node_document";
  727. case ISettingsProvider::Error::NoDocumentElement:
  728. return "Document without element nodes";
  729. case ISettingsProvider::Error::EndElementMismatch:
  730. return "Mismatch of start-end tags";
  731. case ISettingsProvider::Error::InvalidStartElement:
  732. return "Error during start element tag parsing";
  733. default: return "Unknown error";
  734. }
  735. }
  736. };
  737. /** @} */
  738. }