(一)存儲選擇:微型對象資料庫 這裡是隨筆,不會詳述內容,下麵都是用實驗樣例來解釋說明。不明白的可以閃人了。 1。微型對象資料庫 例: { "食指":{ "對象名":"食指" "左右手":"左手" "屬性":[ {"重量":"0.1公斤"}, {"膚色":"黃"}, {"皮膚面積":"0.05平米" ...
(一)存儲選擇:微型對象資料庫
這裡是隨筆,不會詳述內容,下麵都是用實驗樣例來解釋說明。
1。微型對象資料庫
例:
{ "食指":{ "對象名":"食指" "左右手":"左手" "屬性":[ {"重量":"0.1公斤"}, {"膚色":"黃"}, {"皮膚面積":"0.05平米"}, {"血":"0.001公斤"}, {"骨":"0.002公斤"}, {"皮":"0.001公斤"}, {"肉":"0.005公斤"}, {"指甲":{...}}, 。。。 ] "行為":[ {"掌":""}, {"拳":""}, {"1":"手勢"}, {"指示方向":"手勢"}, {"勾勾手":"手勢,來我這兒"}, 。。。 ] } }
1.1 NOSQL庫實現
1.1.1 對象類型
1 enum OB_ENDOBJ_TYPE_T { 2 OB_ENDOBJ_UNKNOWN = -1, 3 OB_ENDOBJ_NULL = 1, 4 OB_ENDOBJ_BOOL = 2, 5 OB_ENDOBJ_INTEGER = 3, 6 OB_ENDOBJ_DOUBLE = 4, 7 OB_ENDOBJ_STRING = 5, 8 OB_ENDOBJ_ARRAY = 6, 9 OB_ENDOBJ_OBJECT = 7 10 };
1.1.2 結構定義
1 typedef struct _OB_RESULT_T { 2 3 bool result; 4 5 unsigned char* msg; 6 7 unsigned int code; 8 9 }OB_RESULT_T, *POB_RESULT_T; 10 11 typedef struct _OB_ENDOBJ_T { 12 13 enum OBJ_TYPE type; 14 15 size_t len; 16 17 unsigned char * name; 18 19 unsigned char * value; 20 21 }OB_ENDOBJ_T, *POB_ENDOBJ_T; 22 23 typedef struct _OB_TREE_NODE_T { 24 25 POB_ENDOBJ_T obj; 26 27 struct _OB_TREE_NODE_T* before; 28 29 struct _OB_TREE_NODE_T* next; 30 31 struct _OB_TREE_NODE_T* parent; 32 33 struct _OB_TREE_NODE_T* child; 34 35 }OB_TREE_NODE_T, *POB_TREE_NODE_T; 36 37 typedef struct _OB_TREE_HEAD_T { 38 39 unsigned char ob_name[256]; 40 41 unsigned char ob_hash[1024]; 42 43 unsigned char ob_version[10][256]; 44 45 POB_TREE_NODE_T root; 46 47 }OB_TREE_HEAD_T, *POB_TREE_HEAD_T;
1.1.3 數據操作方法
1.1.3.1 方法定義
1 // 創建對象 操作方法定義 2 3 OB_API bool __stdcall ob_new_obj_null(POB_ENDOBJ_T* ppobj, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_NULL_T data); 4 OB_API bool __stdcall ob_new_obj_bool(POB_ENDOBJ_T* ppobj, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_BOOL_T data); 5 OB_API bool __stdcall ob_new_obj_integer(POB_ENDOBJ_T* ppobj, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_INT_T data); 6 OB_API bool __stdcall ob_new_obj_double(POB_ENDOBJ_T* ppobj, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_DOUBLE_T data); 7 OB_API bool __stdcall ob_new_obj_string(POB_ENDOBJ_T* ppobj, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_STRING_T data, OB_UINT_T datalen); 8 OB_API bool __stdcall ob_new_obj_array(POB_ENDOBJ_T* ppobj, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_ARRAY_T data, enum OB_ENDOBJ_TYPE_T type, OB_UINT_T count); 9 OB_API bool __stdcall ob_new_obj_array_string(POB_ENDOBJ_T* ppobj, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_ARRAY_STRING_T data, OB_UINT_T count); 10 11 // 創建對象節點 操作方法定義 12 13 OB_API bool __stdcall ob_new_node_null(POB_TREE_NODE_T* ppnode, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_NULL_T data); 14 OB_API bool __stdcall ob_new_node_bool(POB_TREE_NODE_T* ppnode, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_BOOL_T data); 15 OB_API bool __stdcall ob_new_node_integer(POB_TREE_NODE_T* ppnode, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_INT_T data); 16 OB_API bool __stdcall ob_new_node_double(POB_TREE_NODE_T* ppnode, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_DOUBLE_T data); 17 OB_API bool __stdcall ob_new_node_string(POB_TREE_NODE_T* ppnode, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_STRING_T data, OB_UINT_T stringlen); 18 OB_API bool __stdcall ob_new_node_array(POB_TREE_NODE_T* ppnode, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_ARRAY_T data, enum OB_ENDOBJ_TYPE_T type, OB_UINT_T count); 19 OB_API bool __stdcall ob_new_node_array_string(POB_TREE_NODE_T* ppnode, POB_RESULT_T* ppresult, OB_STRING_T name, OB_UINT_T len, OB_ARRAY_STRING_T data, OB_UINT_T count); 20 21 // 遍歷 22 23 OB_API POB_TREE_NODE_T _stdcall root(POB_TREE_HEAD_T head); 24 OB_API POB_TREE_NODE_T __stdcall next(POB_TREE_NODE_T pnode); 25 OB_API POB_TREE_NODE_T __stdcall before(POB_TREE_NODE_T pnode); 26 OB_API POB_TREE_NODE_T __stdcall child(POB_TREE_NODE_T pnode); 27 OB_API POB_TREE_NODE_T __stdcall parent(POB_TREE_NODE_T pnode); 28 29 30 31 // 創建對象存儲 32 33 OB_API POB_TREE_HEAD_T __stdcall new_ob(POB_RESULT_T*ppresult, OB_STRING_T ob_name, OB_UINT_T name_len, OB_STRING_T ob_version, OB_UINT_T ver_len); 34 OB_API bool __stdcall delete_ob(POB_TREE_HEAD_T head); 35 36 // 對象節點 增刪改操作方法定義 37 38 OB_API bool __stdcall new_root(POB_TREE_HEAD_T head, POB_TREE_NODE_T* ppnode, POB_RESULT_T* ppresult); 39 OB_API bool __stdcall insert_node(POB_TREE_NODE_T pcurrentnode, POB_TREE_NODE_T* ppnode, POB_RESULT_T* ppresult); 40 OB_API bool __stdcall delete_node(POB_TREE_NODE_T* ppnode, POB_RESULT_T* ppresult);