Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

buffered_string_buffer.cpp

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2005 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00029 #include "precomp.h"
00030 #include "buffered_string_buffer.h"
00031 #include "buffered_string.h"
00032 
00034 // CL_BufferedStringBuffer Construction:
00035 
00036 CL_BufferedStringBuffer::CL_BufferedStringBuffer()
00037 {
00038 }
00039 
00040 CL_BufferedStringBuffer::~CL_BufferedStringBuffer()
00041 {
00042 }
00043 
00045 // CL_BufferedStringBuffer Attributes:
00046 
00048 // CL_BufferedStringBuffer Operations:
00049 
00050 const char *CL_BufferedStringBuffer::get_data(int index)
00051 {
00052         return 0;
00053 }
00054         
00055 int CL_BufferedStringBuffer::get_length(int index)
00056 {
00057         return 0;
00058 }
00059 
00060 int CL_BufferedStringBuffer::get_string_count()
00061 {
00062         return (int) strings.size();
00063 }
00064         
00065 CL_BufferedString CL_BufferedStringBuffer::add_string(const char *str, int length)
00066 {
00067         // Include space for the null terminator when allocating for a string.
00068         int full_length = length + 1;
00069 
00070         // Extend buffer in blocks, if we are exhausting it:
00071         if (buffer.get_size()+full_length > buffer.get_capacity())
00072         {
00073                 int block_size = 32*1024;
00074                 int blocks = (buffer.get_capacity() + full_length + block_size-1) / block_size;
00075                 buffer.set_capacity(blocks * block_size);
00076         }
00077 
00078         // Create string in buffer:     
00079         StringData str_data;
00080         str_data.pos = buffer.get_size();
00081         str_data.length = length;
00082         buffer.set_size(str_data.pos+str_data.length);
00083         memcpy(buffer.get_data()+str_data.pos, str, length);
00084         buffer[str_data.pos+length] = 0;
00085         strings.push_back(str_data);
00086 
00087         // Return the created string:
00088         return CL_BufferedString(this, (int) strings.size()-1);
00089 }
00090         
00091 CL_BufferedString CL_BufferedStringBuffer::get_string(int index)
00092 {
00093         return CL_BufferedString(this, index);
00094 }
00095 
00097 // CL_BufferedStringBuffer Implementation:

Generated on Sat Feb 19 22:51:15 2005 for npcore by  doxygen 1.4.1