2000-09-09 04:02:48 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (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.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla strings.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 2000 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Scott Collins <scc@mozilla.org> (original author)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsSlidingString_h___
|
|
|
|
#define nsSlidingString_h___
|
|
|
|
|
2000-09-09 03:54:23 +04:00
|
|
|
#include "nsAReadableString.h"
|
|
|
|
#include "nsSharedBufferList.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maintains the sequence from the prev-most referenced buffer to the last buffer.
|
|
|
|
* As prev-most buffers become un-referenced, they are unlinked from the list
|
|
|
|
* and destroyed.
|
|
|
|
*
|
|
|
|
* One or more |nsSlidingSubstring|s may reference into the list. Each |nsSlidingSubstring|
|
|
|
|
* holds a reference into the prev-most buffer intersecting the
|
|
|
|
* substring it describes. The destructor of a |nsSlidingSubstring| releases this
|
|
|
|
* reference, allowing the buffer list to destroy the contiguous prefix of
|
|
|
|
* unreferenced buffers.
|
|
|
|
*
|
|
|
|
* A single instance of |nsSlidingString| may reference this list.
|
|
|
|
* Through that interface, new data can be appended onto the next-most end
|
|
|
|
* of the list. |nsSlidingString| also the client to advance its starting point.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class nsSlidingSharedBufferList
|
|
|
|
: public nsSharedBufferList
|
|
|
|
{
|
|
|
|
public:
|
2000-09-09 15:31:04 +04:00
|
|
|
nsSlidingSharedBufferList( Buffer* aBuffer ) : nsSharedBufferList(aBuffer), mRefCount(0) { }
|
2000-09-09 03:54:23 +04:00
|
|
|
|
|
|
|
void AcquireReference() { ++mRefCount; }
|
|
|
|
void ReleaseReference() { if ( !--mRefCount ) delete this; }
|
|
|
|
|
|
|
|
void DiscardUnreferencedPrefix( Buffer* );
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRUint32 mRefCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* a substring over a buffer list, this
|
|
|
|
*/
|
|
|
|
class nsSlidingSubstring
|
|
|
|
: public nsPromiseReadable<PRUnichar>
|
|
|
|
{
|
|
|
|
public:
|
2000-09-11 09:24:49 +04:00
|
|
|
typedef nsSlidingSharedBufferList::Buffer Buffer;
|
|
|
|
typedef nsSlidingSharedBufferList::Position Position;
|
2000-09-09 03:54:23 +04:00
|
|
|
|
2000-09-11 09:24:49 +04:00
|
|
|
nsSlidingSubstring( const nsSlidingSubstring& ); // copy-constructor
|
|
|
|
nsSlidingSubstring( const nsSlidingSubstring& aString, const nsReadingIterator<PRUnichar>& aStart, const nsReadingIterator<PRUnichar>& aEnd );
|
|
|
|
~nsSlidingSubstring();
|
2000-09-09 03:54:23 +04:00
|
|
|
|
|
|
|
virtual PRUint32 Length() const { return mLength; }
|
|
|
|
|
|
|
|
protected:
|
2000-09-11 09:24:49 +04:00
|
|
|
nsSlidingSubstring( nsSlidingSharedBufferList& aBufferList );
|
2000-09-09 10:35:16 +04:00
|
|
|
virtual const PRUnichar* GetReadableFragment( nsReadableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 ) const;
|
2000-09-11 09:24:49 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// can't assign into me, I'm a read-only reference
|
|
|
|
void operator=( const nsSlidingSubstring& ); // NOT TO BE IMPLEMENTED
|
|
|
|
|
2000-09-09 03:54:23 +04:00
|
|
|
protected:
|
2000-09-11 09:24:49 +04:00
|
|
|
Position mStart;
|
|
|
|
Position mEnd;
|
|
|
|
nsSlidingSharedBufferList& mBufferList;
|
|
|
|
PRUint32 mLength;
|
2000-09-09 03:54:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An |nsSlidingSharedBufferList| may be modified by zero or one instances of this class.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class nsSlidingString
|
|
|
|
: public nsSlidingSubstring
|
|
|
|
{
|
|
|
|
public:
|
2000-09-09 15:31:04 +04:00
|
|
|
nsSlidingString( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd );
|
2000-09-11 09:24:49 +04:00
|
|
|
// ...created by consuming ownership of a buffer ... |aStorageStart| must point to something
|
|
|
|
// that it will be OK for the slidking string to call |nsMemory::Free| on
|
2000-09-09 03:54:23 +04:00
|
|
|
|
2000-09-11 09:24:49 +04:00
|
|
|
// you are giving ownership to the string, it takes and keeps your buffer, deleting it (with |nsMemory::Free|) when done
|
2000-09-09 03:54:23 +04:00
|
|
|
void AppendBuffer( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd );
|
2000-09-11 09:24:49 +04:00
|
|
|
|
2000-09-09 03:54:23 +04:00
|
|
|
// void Append( ... ); do you want some |Append|s that copy the supplied data?
|
|
|
|
|
|
|
|
void DiscardPrefix( const nsReadingIterator<PRUnichar>& );
|
|
|
|
// any other way you want to do this?
|
2000-09-11 09:24:49 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsSlidingString( const nsSlidingString& ); // NOT TO BE IMPLEMENTED
|
|
|
|
void operator=( const nsSlidingString& ); // NOT TO BE IMPLEMENTED
|
2000-09-09 03:54:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-09-09 08:40:38 +04:00
|
|
|
#if 0
|
|
|
|
// this (or something similar) is what should appear in the parser, I think
|
|
|
|
#include "nsSlidingString.h"
|
|
|
|
|
2000-09-09 03:54:23 +04:00
|
|
|
typedef nsSlidingString nsParserString;
|
2000-09-09 08:40:38 +04:00
|
|
|
typedef nsSlidingSubstring nsParserToken;
|
|
|
|
#endif
|
2000-09-09 04:02:48 +04:00
|
|
|
|
|
|
|
#endif // !defined(nsSlidingString_h___)
|