dict CHANGE split dictionary API to private and public part
Make part of the dictionary API public and usable by library users.
It should allow more effective way of memory usage.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a905209..0049e2e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,7 +73,8 @@
src/libyang.h
src/tree_schema.h
src/tree_data.h
- src/xml.h)
+ src/xml.h
+ src/dict.h)
add_library(yang SHARED ${libsrc})
set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION})
diff --git a/Doxyfile.in b/Doxyfile.in
index b683b94..608ee4b 100644
--- a/Doxyfile.in
+++ b/Doxyfile.in
@@ -766,7 +766,8 @@
INPUT = ./src/libyang.h \
./src/tree_data.h \
./src/tree_schema.h \
- ./src/xml.h
+ ./src/xml.h \
+ ./src/dict.h
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
diff --git a/src/common.h b/src/common.h
index ee46411..41e3c1f 100644
--- a/src/common.h
+++ b/src/common.h
@@ -24,9 +24,9 @@
#include <stdint.h>
+#include "dict_private.h"
#include "libyang.h"
#include "resolve.h"
-#include "dict.h"
#ifdef __GNUC__
# define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
diff --git a/src/context.c b/src/context.c
index 201739e..f1cc47a 100644
--- a/src/context.c
+++ b/src/context.c
@@ -31,7 +31,7 @@
#include "common.h"
#include "context.h"
-#include "dict.h"
+#include "dict_private.h"
#include "parser.h"
#include "tree_internal.h"
diff --git a/src/context.h b/src/context.h
index 8cd996a..e73ab66 100644
--- a/src/context.h
+++ b/src/context.h
@@ -22,7 +22,7 @@
#ifndef LY_CONTEXT_H_
#define LY_CONTEXT_H_
-#include "dict.h"
+#include "dict_private.h"
#include "tree_schema.h"
struct ly_modules_list {
diff --git a/src/dict.c b/src/dict.c
index 4a6ec46..c02a0a3 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -24,8 +24,8 @@
#include <stdlib.h>
#include "common.h"
-#include "dict.h"
#include "context.h"
+#include "dict_private.h"
void
lydict_init(struct dict_table *dict)
diff --git a/src/dict.h b/src/dict.h
index ac0c993..69d565d 100644
--- a/src/dict.h
+++ b/src/dict.h
@@ -24,50 +24,22 @@
#include <stdint.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* structure definition from context.h
*/
struct ly_ctx;
/**
- * size of the dictionary for each context
- */
-#define DICT_SIZE 1024
-
-/**
- * record of the dictionary
- * TODO: save the next pointer by different collision strategy, will need to
- * make dictionary size dynamic
- */
-struct dict_rec {
- char *value;
- uint32_t refcount;
- struct dict_rec *next;
-};
-
-/**
- * dictionary to store repeating strings
- * TODO: make it variable size
- */
-struct dict_table {
- struct dict_rec recs[DICT_SIZE];
- int hash_mask;
- uint32_t used;
-};
-
-/**
- * @brief Initiate content (non-zero values) of the dictionary
+ * @defgroup dict Dictionary
+ * @{
*
- * @param[in] dict Dictionary table to initiate
+ * Publicly visible functions and values of the libyang dictionary. They provide
+ * access to the strings stored in the libyang context.
*/
-void lydict_init(struct dict_table *dict);
-
-/**
- * @brief Cleanup the dictionary content
- *
- * @param[in] dict Dictionary table to cleanup
- */
-void lydict_clean(struct dict_table *dict);
/**
* @brief Insert string into dictionary. If the string is already present,
@@ -111,4 +83,10 @@
*/
void lydict_remove(struct ly_ctx *ctx, const char *value);
+/**@} dict */
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* LY_DICT_H_ */
diff --git a/src/dict_private.h b/src/dict_private.h
new file mode 100644
index 0000000..955bfc8
--- /dev/null
+++ b/src/dict_private.h
@@ -0,0 +1,69 @@
+/**
+ * @file dict.h
+ * @author Radek Krejci <rkrejci@cesnet.cz>
+ * @brief libyang dictionary
+ *
+ * Copyright (c) 2015 CESNET, z.s.p.o.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of the Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ */
+
+#ifndef LY_DICT_PRIVATE_H_
+#define LY_DICT_PRIVATE_H_
+
+#include <stdint.h>
+
+#include "dict.h"
+
+/**
+ * size of the dictionary for each context
+ */
+#define DICT_SIZE 1024
+
+/**
+ * record of the dictionary
+ * TODO: save the next pointer by different collision strategy, will need to
+ * make dictionary size dynamic
+ */
+struct dict_rec {
+ char *value;
+ uint32_t refcount;
+ struct dict_rec *next;
+};
+
+/**
+ * dictionary to store repeating strings
+ * TODO: make it variable size
+ */
+struct dict_table {
+ struct dict_rec recs[DICT_SIZE];
+ int hash_mask;
+ uint32_t used;
+};
+
+/**
+ * @brief Initiate content (non-zero values) of the dictionary
+ *
+ * @param[in] dict Dictionary table to initiate
+ */
+void lydict_init(struct dict_table *dict);
+
+/**
+ * @brief Cleanup the dictionary content
+ *
+ * @param[in] dict Dictionary table to cleanup
+ */
+void lydict_clean(struct dict_table *dict);
+
+#endif /* LY_DICT_PRIVATE_H_ */
diff --git a/src/libyang.h b/src/libyang.h
index 59ce5b3..4b5d906 100644
--- a/src/libyang.h
+++ b/src/libyang.h
@@ -27,6 +27,7 @@
#include "tree_schema.h"
#include "tree_data.h"
#include "xml.h"
+#include "dict.h"
#ifdef __cplusplus
extern "C" {
diff --git a/src/parser_yin.c b/src/parser_yin.c
index 4315bd0..5ea60f1 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -33,8 +33,8 @@
#include "libyang.h"
#include "common.h"
#include "context.h"
+#include "dict_private.h"
#include "xpath.h"
-#include "dict.h"
#include "parser.h"
#include "resolve.h"
#include "tree_internal.h"
diff --git a/src/resolve.c b/src/resolve.c
index b27f592..778a09b 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -31,7 +31,7 @@
#include "resolve.h"
#include "common.h"
#include "xpath.h"
-#include "dict.h"
+#include "dict_private.h"
#include "tree_internal.h"
/**
diff --git a/src/xml.c b/src/xml.c
index c1abf37..6f8a7c8 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -28,7 +28,7 @@
#include <unistd.h>
#include "common.h"
-#include "dict.h"
+#include "dict_private.h"
#include "printer.h"
#include "tree_schema.h"
#include "xml_private.h"
diff --git a/src/xpath.c b/src/xpath.c
index 19de233..fd7014b 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -1,3 +1,4 @@
+
/**
* @file xpath.c
* @author Michal Vasko <mvasko@cesnet.cz>
@@ -39,7 +40,7 @@
#include "tree_internal.h"
#include "common.h"
#include "resolve.h"
-#include "dict.h"
+#include "dict_private.h"
static struct lyd_node *moveto_get_root(struct lyd_node *cur_node, enum lyxp_node_type *root_type);
static int reparse_expr(struct lyxp_expr *exp, uint16_t *exp_idx, uint32_t line);