Add Doxygen libConfig documentation. 65/46865/4
authorPawel Kubik <p.kubik@samsung.com>
Wed, 19 Aug 2015 15:28:08 +0000 (17:28 +0200)
committerPawel Kubik <p.kubik@samsung.com>
Thu, 27 Aug 2015 08:40:48 +0000 (10:40 +0200)
[Feature]       libConfig documentation
[Cause]         Explain the library usage
[Verification]  Built HTML using generate_documentation.sh and rendered
                it in browser

Change-Id: I459756566055023f357fb2037b3409410129f53e

libs/config/fields-union.hpp
libs/config/fields.hpp
libs/config/manager.hpp

index 67720e7..edc2b80 100644 (file)
 #include <utility>
 #include <boost/any.hpp>
 
+class DisableMoveAnyWrapper : public boost::any
+{
+    public:
+        DisableMoveAnyWrapper() {}
+        DisableMoveAnyWrapper(const DisableMoveAnyWrapper& any)
+            : boost::any(static_cast<const boost::any&>(any)) {};
+        DisableMoveAnyWrapper& operator=(DisableMoveAnyWrapper&& any) = delete;
+        DisableMoveAnyWrapper& operator=(const DisableMoveAnyWrapper& any) {
+            static_cast<boost::any&>(*this) = static_cast<const boost::any&>(any);
+            return *this;
+        }
+};
+
 /**
- * Use this macro to declare and register config fields
+ * @ingroup libConfig
  *
- * Example:
+ * Use this macro to declare and register config fields.
+ *
+ * Example of fields registration:
+ * @code
  *  struct Foo {
  *      std::string bar;
  *
  *          int
  *      )
  *  };
+ * @endcode
  *
- *  Example of valid configuration:
+ * Example of valid configuration:
+ * @code
  *   1. {
  *        "type": "Foo",
  *        "value": { "bar": "some string" }
  *        "type": "int",
  *        "value": 1
  *      }
+ * @endcode
  *
- *
- *  Usage:
+ * Usage of existing bindings:
+ * @code
  *   Config config;
  *   // ...
  *   if (config.isSet()) {
  *     config.set(std::move(foo));         //< copy sic!
  *     config.set(Foo({"some string"}));
  *   }
+ * @endcode
  */
-
-class DisbaleMoveAnyWrapper : public boost::any
-{
-    public:
-        DisbaleMoveAnyWrapper() {}
-        DisbaleMoveAnyWrapper(const DisbaleMoveAnyWrapper& any)
-            : boost::any(static_cast<const boost::any&>(any)) {};
-        DisbaleMoveAnyWrapper& operator=(DisbaleMoveAnyWrapper&& any) = delete;
-        DisbaleMoveAnyWrapper& operator=(const DisbaleMoveAnyWrapper& any) {
-            static_cast<boost::any&>(*this) = static_cast<const boost::any&>(any);
-            return *this;
-        }
-};
-
 #define CONFIG_DECLARE_UNION(...)                                                               \
 private:                                                                                        \
-    DisbaleMoveAnyWrapper mConfigDeclareField;                                                  \
+    DisableMoveAnyWrapper mConfigDeclareField;                                                  \
                                                                                                 \
     template<typename Visitor>                                                                  \
     void visitOption(Visitor& v, const std::string& name) {                                     \
index d1fc4be..7a43bf6 100644 (file)
@@ -18,8 +18,9 @@
 
 /**
  * @file
- * @author  Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
- * @brief   Macros for registering configuration fields
+ * @author     Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
+ * @addtogroup libConfig libConfig
+ * @brief      C++ library for handling configurations
  */
 
 #ifndef COMMON_CONFIG_FIELDS_HPP
 #endif
 
 /**
- * Use this macro to register config fields.
+ * @ingroup libConfig
+ * Register empty config class
+ */
+#define CONFIG_REGISTER_EMPTY                                      \
+    template<typename Visitor>                                     \
+    static void accept(Visitor ) {                                 \
+    }                                                              \
+
+/**
+ * @ingroup libConfig
+ *
+ * Registers config fields within class.
  *
  * Example:
+ * @code
  *   struct Foo
  *   {
  *       std::string bar;
  *           sub_a
  *       )
  *   };
+ * @endcode
  */
-
-#define CONFIG_REGISTER_EMPTY                                      \
-    template<typename Visitor>                                     \
-    static void accept(Visitor ) {                                 \
-    }                                                              \
-
 #define CONFIG_REGISTER(...)                                       \
     template<typename Visitor>                                     \
     void accept(Visitor v) {                                       \
index f3bac43..e2877df 100644 (file)
 /**
  * @file
  * @author  Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
+ * @defgroup manager Manager
+ * @ingroup libConfig
  * @brief   Configuration management functions
+ *
+ * Example of various data formats operations:
+ *
+ * @code
+ * #include "config/fields.hpp"
+ * #include "config/manager.hpp"
+ * #include <iostream>
+ * #include <cstdio>
+ *
+ * struct Foo
+ * {
+ *     std::string bar = "plain-text";
+ *     std::vector<int> tab = std::vector<int>{1, 2, 4, 8};
+ *     double number = 3.14;
+ *
+ *     CONFIG_REGISTER
+ *     (
+ *         bar,
+ *         tab,
+ *         number
+ *     )
+ * };
+ *
+ * int main()
+ * {
+ *     Foo foo;
+ *
+ *     const std::string jsonString = config::saveToJsonString(foo);
+ *     config::loadFromJsonString(jsonString, foo);
+ *
+ *     const GVariant* gVariantPointer = config::saveToGVariant(foo);
+ *     config::loadFromGVariant(gVariantPointer, foo);
+ *     g_variant_unref(gVariantPointer);
+ *
+ *     constexpr std::string jsonFile = "foo.json";
+ *     config::saveToJsonFile(jsonFile, foo);
+ *     config::loadFromJsonFile(jsonFile, foo);
+ *
+ *     constexpr std::string kvDBPath = "kvdb";
+ *     constexpr std::string key = "foo";
+ *     config::saveToKVStore(kvDBPath, foo, key);
+ *     config::loadFromKVStore(kvDBPath, foo, key);
+ *
+ *     config::loadFromKVStoreWithJson(kvDBPath, jsonString, foo, key);
+ *     config::loadFromKVStoreWithJsonFile(kvDBPath, jsonFile, foo, key);
+ *
+ *     FILE* file = fopen("blob", "wb");
+ *     if (!file)
+ *     {
+ *         return EXIT_FAILURE;
+ *     }
+ *     const int fd = ::fileno(file);
+ *     config::saveToFD(fd, foo);
+ *     ::fclose(file);
+ *     file = ::fopen("blob", "rb");
+ *     if(!file) {
+ *         return EXIT_FAILURE;
+ *     }
+ *     config::loadFromFD(fd, foo);
+ *     ::fclose(file);
+ *
+ *     return 0;
+ * }
+ * @endcode
  */
 
 #ifndef COMMON_CONFIG_MANAGER_HPP
 
 namespace config {
 
+/*@{*/
+
 /**
  * Fills the configuration with data stored in the GVariant
  *
@@ -254,4 +322,6 @@ void saveToFD(const int fd, const Config& config)
 
 } // namespace config
 
+/*@}*/
+
 #endif // COMMON_CONFIG_MANAGER_HPP