#ifndef _VBUFSTORAGE_H #define _VBUFSTORAGE_H #include #include #include #include #include "virtualBuffer.h" #define DLLEXPORT extern "C" __declspec(dllexport) //Buffers and nodes share some commen members //The following dataType constants help to distinguish the difference between buffers and nodes at runtime #define VBUFINTERNAL_NODETYPE_BUFFER 1 #define VBUFINTERNAL_NODETYPE_TAG 2 #define VBUFINTERNAL_NODETYPE_TEXT 3 //A class that can hold values to uniquely identify a node typedef struct _VBufStorage_nodeIdentifier_struct { bool operator<(const _VBufStorage_nodeIdentifier_struct&) const; int docHandle; int ID; } VBufStorage_nodeIdentifier_t; //buffer and node types, struct definitions are further down typedef struct _VBufStorage_bufferNode_struct VBufStorage_bufferNode_t; typedef struct _VBufStorage_node_struct VBufStorage_node_t; typedef struct _VBufStorage_tagNode_struct VBufStorage_tagNode_t; typedef struct _VBufStorage_textNode_struct VBufStorage_textNode_t; //A struct for the node type struct _VBufStorage_node_struct { int dataType; VBufStorage_nodeIdentifier_t identifier; VBufStorage_bufferNode_t* buffer; VBufStorage_node_t* firstChild; VBufStorage_node_t* lastChild; VBufStorage_node_t* previous; VBufStorage_node_t* next; VBufStorage_node_t* parent; int startOffset; int endOffset; }; //A struct for the buffer type struct _VBufStorage_bufferNode_struct : _VBufStorage_node_struct { std::map<_VBufStorage_nodeIdentifier_struct,VBufStorage_node_t*>* nodesByIdentifier; std::wstring* bufferText; int selectionStart; int selectionEnd; }; //A struct for the tag node type struct _VBufStorage_tagNode_struct : _VBufStorage_node_struct { VBuf_attribute_t* attribs; int numAttribs; int isBlock; }; //A struct for the text node type struct _VBufStorage_textNode_struct : _VBufStorage_node_struct { }; //All the following functions return error codes less than 0 if there is an error //Creates a new buffer and returns a pointer to it. //If successfull it returns a pointer to the buffer DLLEXPORT VBufStorage_bufferNode_t* VBufStorage_createBuffer(); //Gets the node in given buffer that has a given docHandle and ID DLLEXPORT VBufStorage_node_t* VBufStorage_getBufferNodeWithIdentifier(VBufStorage_bufferNode_t* buf, int docHandle, int ID); //Merges a buffer's contents in to another buffer DLLEXPORT int VBufStorage_mergeBuffer(VBufStorage_node_t* parent, VBufStorage_node_t* previous, VBufStorage_bufferNode_t* node); //Destroies the buffer pointed to by buf. It also firstly clears the buffer, removing any nodes it has //If successfull it returns 0 DLLEXPORT int VBufStorage_destroyBuffer(VBufStorage_bufferNode_t* buf); //Clears the buffer pointed to by buf (removing all nodes associated with it) //Returns 0 on success DLLEXPORT int VBufStorage_clearBuffer(VBufStorage_bufferNode_t* buf); //Splits a text node in to two adjacent text nodes DLLEXPORT int VBufStorage_splitTextNodeAtOffset(VBufStorage_textNode_t* node, int offset); //Creates a new tag node, setting its docHandle to given docHandle, ID to given ID and attribs to given attribs //It links it to given parent and previous nodes DLLEXPORT VBufStorage_tagNode_t* VBufStorage_addTagNodeToBuffer(VBufStorage_node_t* parent, VBufStorage_node_t* previous, int docHandle, int ID, VBuf_attribute_t* attribs, int numAttribs, int isBlock); //Creates a new text node, setting its docHandle to given docHandle and ID to given ID, and inserts the given text. //It links it to given parent and previous nodes DLLEXPORT VBufStorage_textNode_t* VBufStorage_addTextNodeToBuffer(VBufStorage_node_t* parent, VBufStorage_node_t* previous, int docHandle, int ID, wchar_t* text); //Removes the node , //It also removes any nodes that are descendants of the node being removed. //Returns 0 on success DLLEXPORT int VBufStorage_removeNodeFromBuffer(VBufStorage_node_t* node); //Removes the descendants of the node //Returns 0 on success DLLEXPORT int VBufStorage_removeDescendantsFromBufferNode(VBufStorage_node_t* node); //Finds the node who owns the range of text in the buffer that includes the given offset. //Places the docHandle and ID in given by ref arguments //Returns 0 on success DLLEXPORT int VBufStorage_getFieldIdentifierFromBufferOffset(VBufStorage_bufferNode_t* buf, int offset, int* foundDocHandle, int* foundID); //Gets the offsets of the node identified by the given docHandle and ID. //The offsets are placed in memory pointed to by the given startOffset and endOffset pointers. //Returns 0 on success DLLEXPORT int VBufStorage_getBufferOffsetsFromFieldIdentifier(VBufStorage_bufferNode_t* buf, int docHandle, int ID, int* startOffset, int* endOffset); //Finds the next or previous node of the buffer pointed to by buf, that matches the given attribs. //any attrib can be listed more than once to match on more than one possibility //It starts from the given startOffset, and searches in the direction given by direction. //It places the found node's docHandle and ID in given by ref arguments //It returns 0 on success DLLEXPORT int VBufStorage_findBufferFieldIdentifierByProperties(VBufStorage_bufferNode_t* buf, int direction, int startOffset, VBuf_multyValueAttribute_t* attribs, int numAttribs, int* foundDocHandle, int* foundID); //Returns the length of the text in the buffer pointed to by buf. DLLEXPORT int VBufStorage_getBufferTextLength(VBufStorage_bufferNode_t* buf); //Returns the number of nodes in the buffer pointed to by buf. DLLEXPORT int VBufStorage_getBufferFieldCount(VBufStorage_bufferNode_t* buf); //Searches the buffer pointed to by buf, for the given text, in the direction given by direction. //Currently ignores flags, is always case sensitive. //Returns the offset of the text if its found DLLEXPORT int VBufStorage_findBufferText(VBufStorage_bufferNode_t* buf, wchar_t* text, int startOffset, int direction, int flags); //Copies the text between the given start and end offsets, in to the memory pointed to by text DLLEXPORT int VBufStorage_getBufferTextByOffsets(VBufStorage_bufferNode_t* buf, int startOffset, int endOffset, wchar_t* text); //Gets a string of XML open tags that represents the field ancestry from the root node to the given offset. //Call it once with textBuf as NULL and it will cache the xml and return the length so you can allocate appropriate memory and call it again. DLLEXPORT int VBufStorage_getXMLContextAtBufferOffset(VBufStorage_bufferNode_t* buf, int offset, wchar_t* textBuf); //Builds a string of xml, which describes the text and fields between the given startOffset and endOffset, of the buffer pointed to by buf. //This XML is relative to the start offset. //To find out the length of the xml (for purposes of allocating enough memory), call this function //With text as NULL, and it will generate the xml, cache it, and return the length in wchars. //Then call it again with an appropriately sized block of memory, pointed to by text, to copy the xml in to the memory block. //Once copied, it again returns the length of the xml. DLLEXPORT int VBufStorage_getXMLBufferTextByOffsets(VBufStorage_bufferNode_t* buf, int startOffset, int endOffset, wchar_t* text); //Gets the start and end offsets for the line at given offset, and places them in startOffset and endOffset. //Takes maxLineLength in to account when calculating offsets //If useScreenLayout is True then lines will not be broken at all tags, but only ones that are block tags. Of course lines will also be broken at \n. //Returns 0 on success DLLEXPORT int VBufStorage_getBufferLineOffsets(VBufStorage_bufferNode_t* buf, int offset, int maxLineLength, int useScreenLayout, int* startOffset, int* endOffset); //Gets the current selection offsets, putting them in given startOffset and endOffset parameters. //Returns 0 on success DLLEXPORT int VBufStorage_getBufferSelectionOffsets(VBufStorage_bufferNode_t* buf, int* startOffset, int* endOffset); //Sets the selection to the given startOffset and endOffset parameters. //Returns 0 on success DLLEXPORT int VBufStorage_setBufferSelectionOffsets(VBufStorage_bufferNode_t* buf, int startOffset, int endOffset); #endif