[DEV] update to the etk::Buffer system

This commit is contained in:
Edouard DUPIN 2012-11-19 22:45:55 +01:00
parent af38aaf01a
commit 311c009fff
9 changed files with 50 additions and 1142 deletions

View File

@ -124,7 +124,7 @@ void EdnBuf::GetAll(etk::Vector<int8_t> &text)
// Clean output vector
text.Clear();
// Set data on the vector
m_data.Get(0, m_data.Size(), text);
text = m_data.Get(0, m_data.Size());
}
@ -153,7 +153,7 @@ void EdnBuf::GetRange(int32_t start, int32_t end, etk::Vector<int8_t> &output)
// Remove all data ...
output.Clear();
// import data :
m_data.Get(start, end-start, output);
output = m_data.Get(start, end-start);
//APPL_DEBUG("request start=" << start << " end="<< end << " size="<< end-start << " result size=" << output.Size() );
}
@ -162,8 +162,7 @@ void EdnBuf::GetRange(int32_t start, int32_t end, etk::UString &output)
// Remove all data ...
output = "";
// import data :
etk::Vector<int8_t> localOutput;
m_data.Get(start, end-start, localOutput);
etk::Vector<int8_t> localOutput = m_data.Get(start, end-start);
// transcript in UNICODE ...
if (true == m_isUtf8) {
localOutput.PushBack('\0');
@ -763,16 +762,11 @@ int32_t EdnBuf::CharWidth(char c, int32_t indent)
*/
int32_t EdnBuf::CountDispChars(int32_t lineStartPos, int32_t targetPos)
{
EdnVectorBuf::Iterator myPosIt = m_data.Position(lineStartPos);
int32_t charCount = 0;
char expandedChar[MAX_EXP_CHAR_LEN];
//APPL_DEBUG("lineStartPos="<< lineStartPos << " targetPos=" << targetPos);
while( myPosIt
&& myPosIt.Position() < targetPos )
{
charCount += ExpandCharacter(*myPosIt, charCount, expandedChar);
myPosIt++;
for(int32_t iii = lineStartPos; iii< targetPos && iii<m_data.Size() ; iii++ ) {
charCount += ExpandCharacter(m_data[iii], charCount, expandedChar);
}
//APPL_DEBUG(" result=" << charCount);
return charCount;
@ -780,102 +774,74 @@ int32_t EdnBuf::CountDispChars(int32_t lineStartPos, int32_t targetPos)
/**
* @brief Return the position of the nth diplaye char
*
* @param[in] lineStartPos Position of the start of the line
* @param[in] nChars search in the next nChars elements
*
* @return number of diaplay char
*
*/
int32_t EdnBuf::CountForwardDispChars(int32_t lineStartPos, int32_t nChars)
{
EdnVectorBuf::Iterator myPosIt = m_data.Position(lineStartPos);
int32_t charCount = 0;
char c;
while( charCount < nChars
&& myPosIt)
{
c = *myPosIt;
int32_t iii = 0;
for(iii = lineStartPos; charCount<nChars && iii<m_data.Size() ; iii++ ) {
char c = m_data[iii];
if (c == '\n') {
return myPosIt.Position();
return iii;
}
charCount += CharWidth(c, charCount);
myPosIt++;
}
return myPosIt.Position();
return iii;
}
/**
* @brief Count the number of newlines ('\n') between startPos and endPos
*
* @param[in,out] startPos Fist position in the buffer
* @param[in,out] endPos Last position in the buffer (not counted)
*
* @return ---
*
*/
int32_t EdnBuf::CountLines(int32_t startPos, int32_t endPos)
{
EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos);
int32_t lineCount = 0;
while (myPosIt) {
if (myPosIt.Position() == endPos) {
for(int32_t iii = startPos; iii<m_data.Size() ; iii++ ) {
if (iii == endPos) {
return lineCount;
}
if ('\n' == *myPosIt) {
if ('\n' == m_data[iii]) {
lineCount++;
}
myPosIt++;
}
return lineCount;
}
/**
* @brief count the number of '\n' in the vector of elements
*
* @param[in] text Data to count the lines
*
* @return number of line found
*
*/
int32_t EdnBuf::CountLines(etk::Vector<int8_t> &data)
{
etk::Vector<int8_t>::Iterator myPosIt = data.Begin();
int32_t lineCount = 0;
while(myPosIt) {
if ('\n' == *myPosIt) {
for(int32_t iii=0 ; iii<m_data.Size() ; iii++ ) {
if ('\n' == data[iii]) {
lineCount++;
}
myPosIt++;
}
return lineCount;
}
int32_t EdnBuf::CountLines(void)
{
EdnVectorBuf::Iterator myPosIt = m_data.Begin();
int32_t lineCount = 0;
while(myPosIt) {
if ('\n' == *myPosIt) {
for(int32_t iii=0 ; iii<m_data.Size() ; iii++ ) {
if ('\n' == m_data[iii]) {
lineCount++;
}
myPosIt++;
}
return lineCount;
}
/**
* @brief Calculate the number of line
*
* @param ---
*
* @return the number of line in the buffer [1..n]
*
*/
void EdnBuf::CountNumberOfLines(void)
{
@ -900,22 +866,20 @@ int32_t EdnBuf::CountForwardNLines(int32_t startPos, int32_t nLines)
} else if (startPos > m_data.Size() ) {
return m_data.Size();
}
EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos);
int32_t lineCount = 0;
//APPL_INFO("startPos=" << startPos << " nLines=" << nLines);
while(myPosIt)
{
if ('\n' == *myPosIt) {
int32_t iii = 0;
for(iii = startPos; iii<m_data.Size() ; iii++ ) {
if ('\n' == m_data[iii]) {
lineCount++;
if (lineCount == nLines) {
//APPL_INFO(" ==> (1) at position=" << myPosIt.Position()+1 );
return myPosIt.Position()+1;
return iii+1;
}
}
myPosIt++;
}
//APPL_INFO(" ==> (2) at position=" << myPosIt.Position() );
return myPosIt.Position();
return iii;
}
@ -937,18 +901,15 @@ int32_t EdnBuf::CountBackwardNLines(int32_t startPos, int32_t nLines)
}
//APPL_INFO("startPos=" << startPos << " nLines=" << nLines);
EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos-1);
int32_t lineCount = -1;
while(myPosIt) {
if ('\n' == *myPosIt) {
for(int32_t iii = startPos-1; iii>=0 ; iii-- ) {
if ('\n' == m_data[iii]) {
lineCount++;
if (lineCount >= nLines) {
//APPL_INFO(" ==> (1) at position=" << myPosIt.Position()+1 );
return myPosIt.Position()+1;
return iii+1;
}
}
myPosIt--;
}
//APPL_INFO(" ==> (2) at position=0");
return 0;
@ -1276,15 +1237,12 @@ void EdnBuf::eventModification(int32_t pos, int32_t nInserted, etk::Vector<int8_
*/
bool EdnBuf::SearchForward(int32_t startPos, char searchChar, int32_t *foundPos)
{
// Create iterator
EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos);
// move in the string
while (myPosIt) {
if (*myPosIt == searchChar) {
*foundPos = myPosIt.Position();
for(int32_t iii=startPos ; iii<m_data.Size() ; iii++ ) {
if (m_data[iii] == searchChar) {
*foundPos = iii;
return true;
}
myPosIt++;
}
*foundPos = m_data.Size();
return false;
@ -1303,15 +1261,12 @@ bool EdnBuf::SearchForward(int32_t startPos, char searchChar, int32_t *foundPos)
*/
bool EdnBuf::SearchBackward(int32_t startPos, char searchChar, int32_t *foundPos)
{
// Create iterator
EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos-1);
// move in the string
while (myPosIt) {
if (*myPosIt == searchChar) {
*foundPos = myPosIt.Position();
for(int32_t iii=startPos-1 ; iii>=0 ; iii-- ) {
if (m_data[iii] == searchChar) {
*foundPos = iii;
return true;
}
myPosIt--;
}
*foundPos = 0;
return false;

View File

@ -31,7 +31,7 @@
class EdnBuf;
#include <EdnVectorBuf.h>
#include <etk/Buffer.h>
#include <EdnBufHistory.h>
#include <HighlightManager.h>
#include <etk/unicode.h>
@ -166,7 +166,7 @@ class EdnBuf {
colorInformation_ts * GetElementColorAtPosition(int32_t pos, int32_t &starPos);
private:
EdnVectorBuf m_data; //!< buffer of the data in the mode int8_t
etk::Buffer m_data; //!< buffer of the data in the mode int8_t
void CountNumberOfLines(void);
int32_t m_nbLine; //!< Number of line in the biffer

View File

@ -1,704 +0,0 @@
/**
*******************************************************************************
* @file EdnEdnVectorBuf.cpp
* @brief Editeur De N'ours : Basic EdnVectorBuf Basic binary vector for all type of storage
* @author Edouard DUPIN
* @date 07/04/2011
* @par Project
* Edn
*
* @par Copyright
* Copyright 2010 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
* You can not earn money with this Software (if the source extract from Edn
* represent less than 50% of original Sources)
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#include <appl/Debug.h>
#include <appl/global.h>
#include <EdnVectorBuf.h>
#undef __class__
#define __class__ "EdnEdnVectorBuf"
/**
* @brief Create an empty vector
*
* @param[in] count Minimum request size of the Buffer
*
* @return ---
*
*/
EdnVectorBuf::EdnVectorBuf(int32_t count)
{
m_data = NULL;
m_allocated = 0;
m_gapStart = 0;
m_gapEnd = GAP_SIZE_MIN;
ChangeAllocation(count+GAP_SIZE_MIN);
}
/**
* @brief Re-copy constructor (copy all needed data)
*
* @param[in] Evb Vector that might be copy
*
* @return ---
*
*/
EdnVectorBuf::EdnVectorBuf(const EdnVectorBuf & Evb)
{
m_allocated = Evb.m_allocated;
m_data = NULL;
m_gapStart = Evb.m_gapStart;
m_gapEnd = Evb.m_gapEnd;
// allocate all same data
m_data = (int8_t *)malloc( m_allocated * sizeof(int8_t) );
APPL_ASSERT(NULL!=m_data, "Error in data allocation");
// Copy all data ...
memcpy(m_data, Evb.m_data, m_allocated * sizeof(int8_t) );
}
/**
* @brief Destructor of the current Class
*
* @param ---
*
* @return ---
*
*/
EdnVectorBuf::~EdnVectorBuf()
{
if (NULL!=m_data) {
free(m_data);
m_data = NULL;
m_allocated = 0;
m_gapStart = 0;
m_gapEnd = 0;
}
}
static int32_t getFileSize(FILE *myFile)
{
if (NULL == myFile) {
return 0;
}
int32_t size = 0;
fseek(myFile, 0, SEEK_END);
size = ftell(myFile);
fseek(myFile, 0, SEEK_SET);
return size;
}
/**
* @brief Save in the current file open
*
* @param[in,out] myFile pointer on the file where data might be writed
*
* @return true if OK / false if an error occured
*
*/
bool EdnVectorBuf::DumpIn(etk::FSNode &file)
{
bool ret = true;
// write Data
(void)file.FileWrite(m_data, sizeof(int8_t), m_gapStart);
(void)file.FileWrite(&m_data[m_gapEnd], sizeof(int8_t), m_allocated - m_gapEnd);
return ret;
}
/**
* @brief Load in the current file open
*
* @param[in,out] myFile pointer on the file where data might be read
*
* @return true if OK / false if an error occured
*
*/
bool EdnVectorBuf::DumpFrom(etk::FSNode &file)
{
bool ret = true;
uint32_t length = file.FileSize();
// error case ...
if (length > 2000000000) {
return false;
}
// allocate the current buffer :
ChangeAllocation(length + GAP_SIZE_MIN);
// insert Data
int32_t nbReadData = file.FileRead(&m_data[GAP_SIZE_MIN], sizeof(int8_t), length);
APPL_INFO("load data : filesize=" << length << ", readData=" << nbReadData);
// check ERROR
if (nbReadData != length) {
APPL_ERROR("load data pb : filesize=" << length << ", readData=" << nbReadData);
ret = false;
}
// set the gapsize at the end ...
m_gapStart = 0;
m_gapEnd = GAP_SIZE_MIN;
return ret;
}
/**
* @brief Re-copy operator
*
* @param[in] Evb Vector that might be copy
*
* @return reference on the curent re-copy vector
*
*/
EdnVectorBuf& EdnVectorBuf::operator=(const EdnVectorBuf & Evb)
{
if( this != &Evb ) // avoid copy to itself
{
if (NULL!=m_data) {
free(m_data);
m_data = NULL;
}
// Set the new value
m_allocated = Evb.m_allocated;
m_gapStart = Evb.m_gapStart;
m_gapEnd = Evb.m_gapEnd;
// allocate all same data
m_data = (int8_t *)malloc( m_allocated * sizeof(int8_t) );
APPL_ASSERT(NULL!=m_data, "Error in data allocation");
// Copy all data ...
memcpy(m_data, Evb.m_data, m_allocated * sizeof(int8_t) );
}
// Return the curent pointer
return *this;
}
int8_t EdnVectorBuf::operator[] (int32_t pos)
{
APPL_ASSERT(0 <= pos || pos < Size(), "try to read an element non existing");
if (pos < m_gapStart) {
return m_data[pos];
}
return m_data[pos + m_gapEnd-m_gapStart];
}
/**
* @brief Get a current element in the vector
*
* @param[in] pos Desired position read
*
* @return Reference on the Element
*
*/
int8_t& EdnVectorBuf::Get(int32_t pos)
{
APPL_ASSERT(0 <= pos || pos < Size(), "try to read an element non existing");
if (pos < m_gapStart) {
return m_data[pos];
}
return m_data[pos + m_gapEnd-m_gapStart];
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnVectorBuf::Get(int32_t pos, int32_t nbElement, etk::Vector<int8_t> &tmpBuffer)
{
tmpBuffer.Clear();
if (pos < m_gapStart) {
if (pos + nbElement < m_gapStart) {
tmpBuffer.PushBack(&m_data[pos], nbElement);
} else {
tmpBuffer.PushBack(&m_data[pos], m_gapStart - pos);
tmpBuffer.PushBack(&m_data[m_gapEnd], nbElement - (m_gapStart - pos) );
}
} else {
tmpBuffer.PushBack(&m_data[pos+(m_gapEnd-m_gapStart)], nbElement);
}
}
/**
* @brief Add at the Last position of the Vector
*
* @param[in] item Element to add at the end of vector
*
* @return ---
*
*/
void EdnVectorBuf::PushBack(const int8_t& item)
{
Insert( Size(), item);
}
/**
* @brief Remove the last element of the vector
*
* @param ---
*
* @return ---
*
*/
void EdnVectorBuf::PopBack(void)
{
if (Size()>0) {
Remove( Size() );
}
}
/**
* @brief Remove data in the buffer
*
* @param[in]
*
* @return ---
*
*/
void EdnVectorBuf::Remove(int32_t pos, int32_t nbRemoveElement)
{
if( pos > Size()
|| pos < 0 ) {
APPL_ERROR("Request higher than buffer size : pos="<<pos<< " bufferSize="<<Size());
return;
}
if( pos+nbRemoveElement > Size() ) {
APPL_ERROR("Request remove more element than expected in the buffer pos+nbRemoveElement="<<pos+nbRemoveElement<< " bufferSize="<<Size());
return;
}
if (false == GapMove(pos) ) {
return;
}
// Remove elements :
if (m_allocated==m_gapEnd) {
m_gapStart -= nbRemoveElement;
} else {
m_gapEnd += nbRemoveElement;
}
// Resize buffer if needed...
GapCheckMaxSize();
}
/**
* @brief Change the current allocation to the corect one (depend on the current size)
*
* @param[in] newSize Minimum number of element needed
*
* @return ---
*
*/
void EdnVectorBuf::Clear(void)
{
// Remove all element in the buffer
Remove(0, Size() );
}
/**
* @brief Change the current allocation to the corect one (depend on the current size)
*
* @param[in] newSize Minimum number of element needed
*
* @return ---
*
*/
void EdnVectorBuf::ChangeAllocation(int32_t newSize)
{
// set the minimal size to 1
if(newSize <= 0) {
newSize = 1;
}
// set the size with the corect chose type :
if (newSize == m_allocated) {
return;
}
APPL_DEBUG("Change Allocation : " << m_allocated << " ==> " << newSize);
// check if something is allocated :
if (NULL == m_data) {
// no data allocated ==> request an allocation (might be the first)
m_data = (int8_t *)malloc( newSize * sizeof(int8_t) );
} else {
// move datas
m_data = (int8_t *)realloc( m_data, newSize* sizeof(int8_t) );
}
// Check result with assert :
APPL_ASSERT(NULL!=m_data, "Error in data allocation");
// set the new allocation size
m_allocated = newSize;
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnVectorBuf::Insert(int32_t pos, const int8_t& item)
{
if( pos > Size()
|| pos < 0 ) {
APPL_ERROR("Request higher than buffer size : pos="<<pos<< " bufferSize="<<Size());
return;
}
if( 0 == GapSize() ) {
if (false == GapResize(pos, GAP_SIZE_MIN + 1) ) {
return;
}
} else if( pos == m_gapStart
&& pos == m_gapEnd-1 )
{
// mothing to do ...
} else {
if (false == GapMove(pos)) {
return;
}
}
if(pos == m_gapStart) {
m_data[m_gapStart] = item;
m_gapStart++;
} else {
m_data[m_gapEnd-1] = item;
m_gapEnd--;
}
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnVectorBuf::Insert(int32_t pos, etk::Vector<int8_t>& items)
{
if( pos > Size()
|| pos < 0 ) {
APPL_ERROR("Request higher than buffer size : pos="<<pos<< " bufferSize="<<Size());
return;
}
if( items.Size() > GapSize() ) {
if (false == GapResize(pos, GAP_SIZE_MIN + items.Size()) ) {
return;
}
} else {
if (false == GapMove(pos) ) {
return;
}
}
int32_t i;
for(i=0; i<items.Size(); i++) {
m_data[m_gapStart+i] = items[i];
}
m_gapStart += items.Size();
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnVectorBuf::Replace(int32_t pos, const int8_t& item)
{
if( pos > Size()
|| pos < 0 ) {
APPL_ERROR("Request higher than buffer size : pos="<<pos<< " bufferSize="<<Size());
return;
}
// just replace the element, not update Gap position
if (pos < m_gapStart) {
m_data[pos] = item;
} else {
m_data[pos+GapSize()] = item;
}
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnVectorBuf::Replace(int32_t pos, int32_t nbRemoveElement, etk::Vector<int8_t>& items)
{
if( pos > Size()
|| pos < 0 ) {
APPL_ERROR("Request higher than buffer size : pos="<<pos<< " bufferSize="<<Size());
return;
}
if( pos+nbRemoveElement > Size() ) {
APPL_ERROR("Request remove more element than expected in the buffer pos+nbRemoveElement="<<pos+nbRemoveElement<< " bufferSize="<<Size());
return;
}
if (false == GapMove(pos)) {
return;
}
// Remove elements :
m_gapEnd += nbRemoveElement;
//Display();
// insert elements
Insert(pos, items);
// Resize buffer if needed...
GapCheckMaxSize();
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
bool EdnVectorBuf::GapMove(int32_t pos)
{
if( pos > Size()
|| pos < 0 ) {
APPL_ERROR("Request higher than buffer size : pos="<<pos<< " bufferSize="<<Size());
return false;
}
int32_t gapLen = m_gapEnd - m_gapStart;
if (pos > m_gapStart) {
memmove(&m_data[m_gapStart], &m_data[m_gapEnd], pos - m_gapStart);
} else {
memmove(&m_data[pos + gapLen], &m_data[pos], m_gapStart - pos);
}
m_gapEnd += pos - m_gapStart;
m_gapStart += pos - m_gapStart;
return true;
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
bool EdnVectorBuf::GapResize(int32_t pos, int32_t newGapLen)
{
if( pos > Size()
|| pos < 0 ) {
APPL_ERROR("Request higher than buffer size : pos="<<pos<< " bufferSize="<<Size());
return false;
}
int32_t previousSize = Size();
if (newGapLen == GapSize() ) {
// nothing to do ...
return true;
} else {
if (newGapLen > GapSize() ) {
// reallocation
ChangeAllocation( previousSize + newGapLen);
}
// move Data
if (pos <= m_gapStart) {
// just move the end of the gap
memmove(&m_data[m_gapStart + newGapLen], &m_data[m_gapEnd], previousSize - m_gapStart);
// update gap end position
m_gapEnd = m_gapStart + newGapLen;
if (pos < m_gapStart) {
if (false == GapMove(pos)) {
return false;
}
}
// no else
} else {
if (false == GapMove(pos) ) {
return false;
}
memmove(&m_data[m_gapStart + newGapLen], &m_data[m_gapEnd], previousSize - m_gapStart);
}
if (newGapLen < GapSize() ) {
// rellocation
ChangeAllocation(previousSize + newGapLen);
}
}
// update gap position
m_gapStart = pos;
m_gapEnd = pos + newGapLen;
return true;
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnVectorBuf::GapCheckMaxSize(void)
{
if(GapSize() > GAP_SIZE_MAX) {
int32_t currentSize = Size();
// Change the gap Size
if (false == GapResize(m_gapStart, GAP_SIZE_MAX) ) {
return;
}
// remove deprecated elements at the end of the buffer ...
ChangeAllocation(currentSize + GAP_SIZE_MAX);
}
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void EdnVectorBuf::Display(void)
{
APPL_INFO(" Display Buffer : Size="<<Size()<<" m_allocated="<<m_allocated<<" m_gapStart="<<m_gapStart<<" m_gapEnd="<<m_gapEnd);
for(int32_t i=0; i<m_allocated; i++) {
if (i>= m_gapStart && i< m_gapEnd) {
APPL_INFO( "Element " << i << " : GAP");
} else {
APPL_INFO( "Element " << i << " : " << m_data[i]);
}
}
}
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
void TestEdnVectorBuf(void)
{
EdnVectorBuf myBufferTmp;
int32_t i;
//invert data
for (i=0; i<50; i++) {
myBufferTmp.Insert(0, 'a' + i%26);
}
myBufferTmp.Display();
myBufferTmp.Clear();
myBufferTmp.Display();
myBufferTmp.Remove(2, 300);
/*
char plop='a';
myBufferTmp.Insert(0, plop);
myBufferTmp.Display();
plop='b';
myBufferTmp.Insert(0, plop);
myBufferTmp.Display();
plop='c';
myBufferTmp.Insert(0, plop);
myBufferTmp.Display();
plop='d';
myBufferTmp.Insert(0, plop);
myBufferTmp.Display();
plop='e';
myBufferTmp.Insert(0, plop);
myBufferTmp.Display();
plop='f';
myBufferTmp.Insert(0, plop);
myBufferTmp.Display();
plop='g';
myBufferTmp.Insert(0, plop);
myBufferTmp.Display();
plop='h';
myBufferTmp.Insert(0, plop);
myBufferTmp.Display();
plop='m';
etk::Vector<int8_t> items;
items.PushBack('i');
items.PushBack('j');
items.PushBack('k');
items.PushBack('l');
items.PushBack('m');
items.PushBack('n');
items.PushBack('o');
items.PushBack('p');
myBufferTmp.Insert(3, items);
myBufferTmp.Display();
plop='7';
myBufferTmp.Insert(7, plop);
myBufferTmp.Display();
myBufferTmp.Replace(8, 'z');
myBufferTmp.Display();
items.Clear();
items.PushBack('1');
items.PushBack('2');
items.PushBack('3');
myBufferTmp.Replace(10, 4, items);
myBufferTmp.Display();
myBufferTmp.PushBack('a');
myBufferTmp.PushBack('a');
myBufferTmp.PushBack('a');
myBufferTmp.PushBack('a');
myBufferTmp.Display();
myBufferTmp.PopBack();
myBufferTmp.PopBack();
myBufferTmp.PopBack();
myBufferTmp.PopBack();
myBufferTmp.Display();
myBufferTmp.Remove(2, 3);
myBufferTmp.Display();
*/
}

View File

@ -1,342 +0,0 @@
/**
*******************************************************************************
* @file EdnEdnVectorBuf.h
* @brief Editeur De N'ours : Basic EdnVectorBuf for direct data insertion (template)
* @author Edouard DUPIN
* @date 07/04/2011
* @par Project
* Edn
*
* @par Copyright
* Copyright 2010 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
* You can not earn money with this Software (if the source extract from Edn
* represent less than 50% of original Sources)
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#ifndef __EDN_VECTOR_BUF_H__
#define __EDN_VECTOR_BUF_H__
#include <etk/Vector.h>
#include <etk/os/FSNode.h>
#undef __class__
#define __class__ "EdnVectorBuf"
// minimum gapSize when allocated
#define GAP_SIZE_MIN (80)
// maximum gap that is automaticly resize
#define GAP_SIZE_MAX (GAP_SIZE_MIN*4)
/*
______________________________________________________________________________________
| |
| |
| <GapStart |
| *******************************************************************|
|****************************************** |
| Gap Stop > |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|____________________________________________________________________________________|
*/
/**
* @brief EdnVectorBuf classes ...
*/
class EdnVectorBuf
{
public:
class Iterator
{
// Private data :
private:
int32_t m_current; // curent Id on the vector
EdnVectorBuf * m_EdnVectorBuf; // Pointer on the curent element of the vectorBin
public:
/**
* @brief Basic itarator constructor with no link with an EdnVector
*/
Iterator(void):
m_current(-1),
m_EdnVectorBuf(NULL)
{
// nothing to do ...
}
/**
* @brief Recopy constructor on a specific EdnVector.
* @param[in] otherIterator The Iterator that might be copy
*/
Iterator(const Iterator & otherIterator):
m_current(otherIterator.m_current),
m_EdnVectorBuf(otherIterator.m_EdnVectorBuf)
{
// nothing to do ...
}
/**
* @brief Asignation operator.
* @param[in] otherIterator The Iterator that might be copy
* @return reference on the curent Iterator
*/
Iterator& operator=(const Iterator & otherIterator)
{
m_current = otherIterator.m_current;
m_EdnVectorBuf = otherIterator.m_EdnVectorBuf;
return *this;
}
/**
* @brief Basic destructor
*/
~Iterator(void)
{
m_current = -1;
m_EdnVectorBuf = NULL;
}
/**
* @brief gaet element position in the system
*/
int32_t Position(void)
{
if(0 > m_current) {
return 0;
} else if (m_EdnVectorBuf->Size() <= m_current) {
return m_EdnVectorBuf->Size();
} else {
return m_current;
}
}
/**
* @brief basic boolean cast
* @return true if the element is present in the EdnVector size
*/
operator bool ()
{
if( 0 <= m_current
&& m_current < m_EdnVectorBuf->Size() )
{
return true;
} else {
return false;
}
}
/**
* @brief Incremental operator
* @return Reference on the current iterator incremented
*/
Iterator& operator++ ()
{
if( NULL != m_EdnVectorBuf
&& m_current < m_EdnVectorBuf->Size() )
{
m_current++;
}
return *this;
}
/**
* @brief Decremental operator
* @return Reference on the current iterator decremented
*/
Iterator& operator-- ()
{
if (m_current >= 0) {
m_current--;
}
return *this;
}
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
Iterator operator++ (int32_t)
{
Iterator it(*this);
++(*this);
return it;
}
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
Iterator operator-- (int32_t)
{
Iterator it(*this);
--(*this);
return it;
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
int8_t & operator-> () const
{
APPL_CHECK_INOUT(m_current >= 0 && m_current < m_EdnVectorBuf->Size());
return m_EdnVectorBuf->Get(m_current);
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
int8_t & operator* () const
{
APPL_CHECK_INOUT(m_current >= 0 && m_current < m_EdnVectorBuf->Size());
return m_EdnVectorBuf->Get(m_current);
}
private:
/**
* @brief
*
* @param[in,out] ---
*
* @return ---
*
*/
Iterator(EdnVectorBuf * Evb, int32_t pos):
m_current(pos),
m_EdnVectorBuf(Evb)
{
// nothing to do ...
}
friend class EdnVectorBuf;
};
private:
int8_t * m_data; //!< pointer on the curetn table of Data
int32_t m_allocated; //!< Current allocated size
// empty part of the buffer data
int32_t m_gapStart; //!< points to the first character of the gap
int32_t m_gapEnd; //!< points to the first char after the gap
public:
EdnVectorBuf(int32_t count = 0);
EdnVectorBuf(const EdnVectorBuf & Evb);
~EdnVectorBuf();
bool DumpIn( etk::FSNode &file);
bool DumpFrom( etk::FSNode &file);
EdnVectorBuf & operator=( const EdnVectorBuf & Evb);
int8_t operator[] (int32_t pos);
int8_t & Get( int32_t pos);
void Get( int32_t pos, int32_t nbElement, etk::Vector<int8_t> &tmpBuffer);
// insert functions
void PushBack( const int8_t& item);
void Insert( int32_t pos, const int8_t& item);
void Insert( int32_t pos, etk::Vector<int8_t>& items);
// Remove and insert functions
void Replace( int32_t pos, const int8_t& item);
void Replace( int32_t pos, int32_t nbRemoveElement, etk::Vector<int8_t>& items);
// Revove fonctions
void Remove( int32_t pos, int32_t nbRemoveElement = 1);
void PopBack( void);
void Clear( void);
void Fit(void);
void Display(void);
/**
* @brief Get a current element in the vector (iterator system)
* @param[in] RealElementPosition Real position in the buffer (only use in the ITERATOR)
* @return Reference on the Element
*/
int8_t & GetDirect(int32_t RealElementPosition){ return m_data[RealElementPosition]; };
/**
* @brief Get the number of element in the vector
* @return The number requested
*/
int32_t Size(void) { return m_allocated - GapSize(); };
Iterator Position(int32_t pos)
{
return Iterator(this, pos);
}
/**
* @brief Get an Iterator on the start position of the Vector
* @return The Iterator
*/
Iterator Begin()
{
return Position(0);
}
/**
* @brief Get an Iterator on the end position of the Vector
* @return The Iterator
*/
Iterator End()
{
return Position( Size()-1 );
}
private:
// TODO : Set a boolean at the return value to prevent internal error ...
void ChangeAllocation( int32_t newSize);
bool GapMove( int32_t pos);
bool GapResize( int32_t pos, int32_t newGapLen);
// get current gap Size
int32_t GapSize( void) { return m_gapEnd - m_gapStart; };
void GapCheckMaxSize( void);
};
#undef __class__
#define __class__ NULL
void TestEdnVectorBuf(void);
#endif

View File

@ -238,7 +238,7 @@ void Highlight::Parse(int32_t start,
int32_t stop,
etk::Vector<colorInformation_ts> &metaData,
int32_t addingPos,
EdnVectorBuf &buffer)
etk::Buffer &buffer)
{
if (0 > addingPos) {
addingPos = 0;
@ -301,7 +301,7 @@ void Highlight::Parse(int32_t start,
void Highlight::Parse2(int32_t start,
int32_t stop,
etk::Vector<colorInformation_ts> &metaData,
EdnVectorBuf &buffer)
etk::Buffer &buffer)
{
//APPL_DEBUG("Parse element 0 => " << m_listHighlightPass2.size() << " ==> position search: (" << start << "," << stop << ")" );
int32_t elementStart = start;

View File

@ -45,7 +45,7 @@ extern "C" {
#include <etk/os/FSNode.h>
#include <HighlightPattern.h>
#include <Colorize.h>
#include <EdnVectorBuf.h>
#include <etk/Buffer.h>
#include <tinyXML/tinyxml.h>
class Highlight {
@ -61,14 +61,14 @@ class Highlight {
int32_t stop,
etk::Vector<colorInformation_ts> &metaData,
int32_t addingPos,
EdnVectorBuf &buffer);
etk::Buffer &buffer);
void Parse2(int32_t start,
int32_t stop,
etk::Vector<colorInformation_ts> &metaData,
EdnVectorBuf &buffer);
etk::Buffer &buffer);
private:
void ParseRules(TiXmlNode *child, etk::Vector<HighlightPattern*> &mListPatern, int32_t level);
etk::UString m_styleName; //!< curent style name (like "c++" or "c" or "script Bash")
void ParseRules(TiXmlNode *child, etk::Vector<HighlightPattern*> &mListPatern, int32_t level);
etk::UString m_styleName; //!< curent style name (like "c++" or "c" or "script Bash")
etk::Vector<etk::UString*> m_listExtentions; //!< List of possible extention for this high-light, like : ".c", ".cpp", ".h"
etk::Vector<HighlightPattern*> m_listHighlightPass1; //!< List of ALL hightlight modules (pass 1 ==> when we load and wride data on the buffer)
etk::Vector<HighlightPattern*> m_listHighlightPass2; //!< List of ALL hightlight modules (pass 2 ==> When we display the buffer( only the display area (100 lines)) )

View File

@ -38,8 +38,8 @@ HighlightPattern::HighlightPattern(void)
m_haveStopPatern = false;
m_multiline = false;
m_color = ColorizeManager::Get("normal");
m_regExpStart = new etk::RegExp<EdnVectorBuf>();
m_regExpStop = new etk::RegExp<EdnVectorBuf>();
m_regExpStart = new etk::RegExp<etk::Buffer>();
m_regExpStop = new etk::RegExp<etk::Buffer>();
m_escapeChar = 0;
}
@ -207,7 +207,7 @@ void HighlightPattern::ParseRules(TiXmlNode *child, int32_t level)
* @return HLP_FIND_OK_NO_END Xe find a partial pattern (missing end)
* @return HLP_FIND_ERROR Not find the pattern
*/
resultFind_te HighlightPattern::Find(int32_t start, int32_t stop, colorInformation_ts &resultat, EdnVectorBuf &buffer)
resultFind_te HighlightPattern::Find(int32_t start, int32_t stop, colorInformation_ts &resultat, etk::Buffer &buffer)
{
//APPL_DEBUG(" try to find the element");
resultat.beginStart = -1;

View File

@ -35,7 +35,7 @@ class HighlightPattern;
#include <Colorize.h>
#include <etk/Vector.h>
#include <tinyXML/tinyxml.h>
#include <EdnVectorBuf.h>
#include <etk/Buffer.h>
typedef enum {
HLP_FIND_ERROR,
@ -65,7 +65,7 @@ class HighlightPattern {
bool IsEnable(void);
void Display(void);
resultFind_te Find(int32_t start, int32_t stop, colorInformation_ts &resultat, EdnVectorBuf &buffer);
resultFind_te Find(int32_t start, int32_t stop, colorInformation_ts &resultat, etk::Buffer &buffer);
Colorize * GetColor(void) { return m_color; };
void ParseRules(TiXmlNode *child, int32_t level);
@ -76,13 +76,13 @@ class HighlightPattern {
etk::UString m_paternName; //!< Current style name (like "c++" or "c" or "script Bash")
etk::UString m_colorName; //!< Current color name
Colorize * m_color; //!< Link to the color manager
etk::RegExp<EdnVectorBuf> * m_regExpStart; //!< Start of Regular expression
etk::RegExp<EdnVectorBuf> * m_regExpStop; //!< Stop of Regular Expression
etk::RegExp<etk::Buffer> * m_regExpStart; //!< Start of Regular expression
etk::RegExp<etk::Buffer> * m_regExpStop; //!< Stop of Regular Expression
bool m_haveStopPatern; //!< Stop patern presence
bool m_multiline; //!< The patern is multiline
uniChar_t m_escapeChar; //!< Escape char to prevent exeit of patern ....
etk::Vector<HighlightPattern *> m_subPatern; //!< Under patern of this one
// etk::Vector<HighlightPattern *> m_subColor; //!< Under Color in the start RegExp ...
etk::Vector<HighlightPattern *> m_subPatern; //!< Under patern of this one
// etk::Vector<HighlightPattern *> m_subColor; //!< Under Color in the start RegExp ...
};
#endif

View File

@ -23,8 +23,7 @@ FILE_LIST+= appl/Gui/BufferView.cpp \
appl/Gui/TagFileList.cpp
# All needed for the buffer management :
FILE_LIST+= appl/Buffer/EdnVectorBuf.cpp \
appl/Buffer/EdnBuf/EdnBuf.cpp \
FILE_LIST+= appl/Buffer/EdnBuf/EdnBuf.cpp \
appl/Buffer/EdnBuf/EdnBuf_HighLight.cpp \
appl/Buffer/EdnBuf/EdnBuf_History.cpp \
appl/Buffer/EdnBuf/EdnBuf_Selection.cpp \