Click to See Complete Forum and Search --> : Could anyone anser this?


Kohinoor24
June 21st, 2002, 01:54 AM
please Dont stepback,by seeing the length of my mail.I would reaaly appreciate if anyone could help me in this regard.

I have a Buffer class called SimpleBuffer.It was a code I took from some one else .I went through the code,But I couldnt find how the writing into the buffer is achieved.I asked a few people,but none could give me a clear answer.Is there anyone who could tell me this.

Iam sending some files as attached & Iam explaining the workflow below.


I just would like to tell u how it looks:
(These files iam mentioning here are in the attachment).

I have a buffer class(Buffer.h)- BufferSize -10000.
It also has a (Bufferallocator.h) class where memory is allocated.
A Simplebuffer class (SimpleBuffer.h)

I went through the code & the flow goes like as it is numbered:

[1]In C_RdiMapDocument.cpp there is a call - m_rdiDocument->createNgElement( this );
[2]It goes to C_RdiMapDocument::createNgElement( RdiTProcess* process ) in C_RdiMapDocument.cpp.

[3] Then in the BufferAllocator
< NgDocData< SimpleBuffer >
, SimpleBuffer
> bufAlloc( simpleBuffer );
It goes to the buffallocator and produes the object & the protected (B& m_buffer) in the bufferallocator becomes the simplebuffer.

[4]In the next call // Create the NG document object.

m_ngDocumentData = new ( bufAlloc.allocate( 1 ) )This part (a) go to [A] down..
NgDocData< SimpleBuffer >( simpleBuffer ); This part (b) go to [B] down..

[A]

goes to this in Bufferallocator,& the m_buffer is now the simplebuffer ,it calls the allocate bytes of the simplebuffer.
pointer allocate(size_type _N, const void* p = NULL)
throw (DocGenEx)
{
return reinterpret_cast<pointer>(m_buffer.allocateBytes(_N * sizeof(T)));-What is "T" here.
}
m_pfree can be considered to be a read ptr to the buffer, as it incremets whenever bytes are allocated.
max_size(); in the simpleBuffer checks the remaining space in the buffer.

[B]

Goes to the [NgDocData< SimpleBuffer >( simpleBuffer )] Constructor
Where "B" is the simpleBuffer,
m_ngSubDocDataList is a list declared in NgDocData.h file.

list<NgSubDocData<B>*, BufferAllocator<NgSubDocData<B>*, B> > m_ngSubDocDataList;

In The constructor:

template <class B>
NgDocData<B>::NgDocData(B& b):m_ngSubDocDataList(BufferAllocator<NgSubDocData<B>*, B>(b))
{}

This call to constructor goes to the bufferallocator & simplebuffer classes & allocate bytes.
There are other classes & lists which are members of the classes whch Iam not mentioning here.There also same thing happens like this .only the object created changes.

For Eg:-
// Gets the buffer

SimpleBuffer& simpleBuffer = process->getSimpleBuffer();

// Create a buffer allocator.
BufferAllocator
<Corr:Element< SimpleBuffer >
, SimpleBuffer
> bufAlloc( simpleBuffer );

// Where the corr: Elements are created
Corr:element= new ( bufAlloc.allocate( 1 ) )
Corr:Element< SimpleBuffer >( simpleBuffer );

Finally all objects created is pushed into the the list in NgDocData.

//m_ngSubDocDataList.push_back(pNgSubDocData);

So writing into the buffer is done as an object,But I dont now how it is done.The writer pointer gets incremented.

This call in void RdiTProcess::run()
// Output the NG data to screen.
// COUT << *m_pNgDocData;

This call goes to the foll: function iterates the list & ouputs it to the screen.

T_OStream& operator<<(T_OStream& out, const NgDocData<B>& ngDocData)
{


for(NgDocData<B>::const_iterator it = ngDocData.m_ngSubDocDataList.begin();
it != ngDocData.m_ngSubDocDataList.end(); it++)
out << **it;


}

THIS much i wrote to let u understand the situation.Only the parts I told u are relevant(the other parts of the code is not important in this scenario)

Hope,ur not tired after reading all thse stuff...

So In brief:
The SimpleBuffer is filled with an NgDocData object.I have a ptr to this object,by which Iam outputting the things to the screen.


[1]My question is how the object gets written into the buffer.

Expecting an answer

Thanks in advance..