mirror of https://gitee.com/bigwinds/arangodb
First draft of legend generator.
This commit is contained in:
parent
029b7333ba
commit
b5df264cdb
|
@ -29,6 +29,7 @@
|
||||||
#define TRIAGENS_WAL_LOG_SLOT_H 1
|
#define TRIAGENS_WAL_LOG_SLOT_H 1
|
||||||
|
|
||||||
#include "Basics/Common.h"
|
#include "Basics/Common.h"
|
||||||
|
#include "ShapedJson/Legends.h"
|
||||||
#include "Wal/Logfile.h"
|
#include "Wal/Logfile.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -89,6 +89,7 @@ lib_libarango_a_SOURCES = \
|
||||||
lib/Rest/InitialiseRest.cpp \
|
lib/Rest/InitialiseRest.cpp \
|
||||||
lib/Rest/SslInterface.cpp \
|
lib/Rest/SslInterface.cpp \
|
||||||
lib/Rest/Version.cpp \
|
lib/Rest/Version.cpp \
|
||||||
|
lib/ShapedJson/Legends.cpp \
|
||||||
lib/ShapedJson/json-shaper.cpp \
|
lib/ShapedJson/json-shaper.cpp \
|
||||||
lib/ShapedJson/shape-accessor.cpp \
|
lib/ShapedJson/shape-accessor.cpp \
|
||||||
lib/ShapedJson/shaped-json.cpp \
|
lib/ShapedJson/shaped-json.cpp \
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief legends for shaped JSON objects to make them self-contained
|
||||||
|
///
|
||||||
|
/// @file
|
||||||
|
/// Code for legends.
|
||||||
|
///
|
||||||
|
/// DISCLAIMER
|
||||||
|
///
|
||||||
|
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
/// you may not use this file except in compliance with the License.
|
||||||
|
/// You may obtain a copy of the License at
|
||||||
|
///
|
||||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
///
|
||||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
/// See the License for the specific language governing permissions and
|
||||||
|
/// limitations under the License.
|
||||||
|
///
|
||||||
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// @author Max Neunhoeffer
|
||||||
|
/// @author Copyright 2014-2014, triAGENS GmbH, Cologne, Germany
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "ShapedJson/Legends.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace triagens;
|
||||||
|
using namespace triagens::basics;
|
||||||
|
|
||||||
|
|
||||||
|
void JsonLegend::clear () {
|
||||||
|
_have_attribute.clear();
|
||||||
|
_attribs.clear();
|
||||||
|
_att_data.clear();
|
||||||
|
_have_shape.clear();
|
||||||
|
_shapes.clear();
|
||||||
|
_shape_data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JsonLegend::addAttributeId (TRI_shape_aid_t aid) {
|
||||||
|
unordered_set<TRI_shape_aid_t>::const_iterator it = _have_attribute.find(aid);
|
||||||
|
if (it != _have_attribute.end()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
char const* p = _shaper->lookupAttributeId(_shaper, aid);
|
||||||
|
if (0 == p) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_have_attribute.insert(aid);
|
||||||
|
size_t len = strlen(p);
|
||||||
|
_attribs.emplace_back(aid, _att_data.length());
|
||||||
|
_att_data.appendText(p, len+1); // including the zero byte
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JsonLegend::addShape (TRI_shape_sid_t sid,
|
||||||
|
char const* data, uint32_t len) {
|
||||||
|
// data can be 0, then no data is associated, note that if the shape
|
||||||
|
// contains an inhomogeneous list as one of its subobjects, then the
|
||||||
|
// shape legend could be incomplete, because the actual shapes of
|
||||||
|
// the subobject(s) are held only in the data and not in the shaper.
|
||||||
|
|
||||||
|
TRI_shape_t const* shape = 0;
|
||||||
|
|
||||||
|
// First the trivial cases:
|
||||||
|
if (sid < TRI_FirstCustomShapeIdShaper()) {
|
||||||
|
shape = TRI_LookupSidBasicShapeShaper(sid);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unordered_set<TRI_shape_sid_t>::const_iterator it = _have_shape.find(sid);
|
||||||
|
if (it == _have_shape.end()) {
|
||||||
|
TRI_shape_t const* shape = _shaper->lookupShapeId(_shaper, sid);
|
||||||
|
if (0 == shape) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_have_shape.insert(sid);
|
||||||
|
Shape sh(sid, _shape_data.length(), shape->_size);
|
||||||
|
_shapes.push_back(sh);
|
||||||
|
_shape_data.appendText( reinterpret_cast<char const*>(shape),
|
||||||
|
shape->_size );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we have to add all attribute IDs and all shapes used by this
|
||||||
|
// one recursively, note that the data of this object is in a
|
||||||
|
// consistent state, such that we can call ourselves recursively.
|
||||||
|
if (shape->_type == TRI_SHAPE_HOMOGENEOUS_SIZED_LIST) {
|
||||||
|
// Handle a homogeneous list with equal size entries:
|
||||||
|
// Subobjects have fixed size, so in particular no subobject can
|
||||||
|
// contain any inhomogeneous list as one of its subobjects.
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
else if (shape->_type == TRI_SHAPE_HOMOGENEOUS_LIST) {
|
||||||
|
// Handle a homogeneous list:
|
||||||
|
// Only one sid, but one of the subobjects could be an
|
||||||
|
// inhomogeneous list. We first scan the shape without data, if this
|
||||||
|
// goes well, there was no subshape containing an inhomogeneous
|
||||||
|
// list! Otherwise, we have to scan all entries of the list.
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
else if (shape->_type == TRI_SHAPE_LIST) {
|
||||||
|
// Handle an inhomogeneous list:
|
||||||
|
// We have to scan recursively all entries of the list since they
|
||||||
|
// contain sids in the data area.
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
else if (shape->_type == TRI_SHAPE_ARRAY) {
|
||||||
|
// Handle an array ...
|
||||||
|
// Distinguish between fixed size subobjects and variable size
|
||||||
|
// subobjects. The fixed ones cannot contain inhomogeneous lists.
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t JsonLegend::getSize () {
|
||||||
|
// Add string pool size and shape pool size and add space for header
|
||||||
|
// and tables.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonLegend::dump (void* buf) {
|
||||||
|
// Dump the resulting legend to a given buffer.
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,119 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief legends for shaped JSON objects to make them self-contained
|
||||||
|
///
|
||||||
|
/// @file
|
||||||
|
/// Declaration for legends.
|
||||||
|
///
|
||||||
|
/// DISCLAIMER
|
||||||
|
///
|
||||||
|
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
/// you may not use this file except in compliance with the License.
|
||||||
|
/// You may obtain a copy of the License at
|
||||||
|
///
|
||||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
///
|
||||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
/// See the License for the specific language governing permissions and
|
||||||
|
/// limitations under the License.
|
||||||
|
///
|
||||||
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// @author Max Neunhoeffer
|
||||||
|
/// @author Copyright 2014-2014, triAGENS GmbH, Cologne, Germany
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef TRIAGENS_SHAPED_JSON_LEGENDS_H
|
||||||
|
#define TRIAGENS_SHAPED_JSON_LEGENDS_H 1
|
||||||
|
|
||||||
|
#include "BasicsC/common.h"
|
||||||
|
#include "Basics/Common.h"
|
||||||
|
|
||||||
|
#include "BasicsC/structures.h"
|
||||||
|
#include "Basics/StringBuffer.h"
|
||||||
|
#include "ShapedJson/shaped-json.h"
|
||||||
|
#include "ShapedJson/json-shaper.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace triagens {
|
||||||
|
namespace basics {
|
||||||
|
|
||||||
|
class JsonLegend {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
JsonLegend (TRI_shaper_t* shaper)
|
||||||
|
: _shaper(shaper), _att_data(TRI_UNKNOWN_MEM_ZONE),
|
||||||
|
_shape_data(TRI_UNKNOWN_MEM_ZONE) {
|
||||||
|
}
|
||||||
|
|
||||||
|
~JsonLegend () {
|
||||||
|
};
|
||||||
|
|
||||||
|
void reset (TRI_shaper_t* shaper) {
|
||||||
|
clear();
|
||||||
|
_shaper = shaper;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear ();
|
||||||
|
|
||||||
|
bool addAttributeId (TRI_shape_aid_t aid);
|
||||||
|
|
||||||
|
bool addShape (TRI_shaped_json_t const* sh_json) {
|
||||||
|
return addShape(sh_json->_sid, sh_json->_data.data,
|
||||||
|
sh_json->_data.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool addShape (TRI_shape_sid_t sid, TRI_blob_t const* blob) {
|
||||||
|
return addShape(sid, blob->data, blob->length);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool addShape (TRI_shape_sid_t sid, char const* data, uint32_t len);
|
||||||
|
|
||||||
|
size_t getSize ();
|
||||||
|
|
||||||
|
void dump (void* buf);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
TRI_shaper_t* _shaper;
|
||||||
|
|
||||||
|
struct AttributeId {
|
||||||
|
TRI_shape_aid_t aid;
|
||||||
|
TRI_shape_size_t offset;
|
||||||
|
|
||||||
|
AttributeId (TRI_shape_aid_t a, TRI_shape_size_t o)
|
||||||
|
: aid(a), offset(o) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Shape {
|
||||||
|
TRI_shape_sid_t sid;
|
||||||
|
TRI_shape_size_t offset;
|
||||||
|
TRI_shape_size_t size;
|
||||||
|
|
||||||
|
Shape (TRI_shape_sid_t sid, TRI_shape_size_t o, TRI_shape_size_t siz)
|
||||||
|
: sid(sid), offset(o), size(siz) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
unordered_set<TRI_shape_aid_t> _have_attribute;
|
||||||
|
vector<AttributeId> _attribs;
|
||||||
|
StringBuffer _att_data;
|
||||||
|
unordered_set<TRI_shape_sid_t> _have_shape;
|
||||||
|
vector<Shape> _shapes;
|
||||||
|
StringBuffer _shape_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// mode: outline-minor
|
||||||
|
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"
|
||||||
|
// End:
|
Loading…
Reference in New Issue