Back to index

lightning-sunbird  0.9+nobinonly
morkBlob.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _MORKBLOB_
00039 #define _MORKBLOB_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00046 
00047 /*| Buf: the minimum needed to describe location and content length.
00048 **| This is typically only enough to read from this buffer, since
00049 **| one cannot write effectively without knowing the size of a buf.
00050 |*/
00051 class morkBuf { // subset of nsIMdbYarn slots
00052 public:
00053   void*         mBuf_Body;  // space for holding any binary content
00054   mork_fill     mBuf_Fill;  // logical content in Buf in bytes
00055 
00056 public:
00057   morkBuf() { }
00058   morkBuf(const void* ioBuf, mork_fill inFill)
00059   : mBuf_Body((void*) ioBuf), mBuf_Fill(inFill) { }
00060 
00061   void ClearBufFill() { mBuf_Fill = 0; }
00062 
00063   static void NilBufBodyError(morkEnv* ev);
00064 
00065 private: // copying is not allowed
00066   morkBuf(const morkBuf& other);
00067   morkBuf& operator=(const morkBuf& other);
00068 };
00069 
00070 /*| Blob: a buffer with an associated size, to increase known buf info
00071 **| to include max capacity in addition to buf location and content.
00072 **| This form factor allows us to allocate a vector of such blobs,
00073 **| which can share the same managing heap stored elsewhere, and that
00074 **| is why we don't include a pointer to a heap in this blob class.
00075 |*/
00076 class morkBlob : public morkBuf { // greater subset of nsIMdbYarn slots
00077 
00078   // void*         mBuf_Body;  // space for holding any binary content
00079   // mdb_fill      mBuf_Fill;  // logical content in Buf in bytes
00080 public:
00081   mork_size      mBlob_Size;  // physical size of Buf in bytes
00082 
00083 public:
00084   morkBlob() { }
00085   morkBlob(const void* ioBuf, mork_fill inFill, mork_size inSize)
00086   : morkBuf(ioBuf, inFill), mBlob_Size(inSize) { }
00087  
00088   static void BlobFillOverSizeError(morkEnv* ev);
00089  
00090 public:
00091   mork_bool GrowBlob(morkEnv* ev, nsIMdbHeap* ioHeap,
00092     mork_size inNewSize);
00093 
00094 private: // copying is not allowed
00095   morkBlob(const morkBlob& other);
00096   morkBlob& operator=(const morkBlob& other);
00097   
00098 };
00099 
00100 /*| Text: a blob with an associated charset annotation, where the
00101 **| charset actually includes the general notion of typing, and not
00102 **| just a specification of character set alone; we want to permit
00103 **| arbitrary charset annotations for ad hoc binary types as well.
00104 **| (We avoid including a nsIMdbHeap pointer in morkText for the same
00105 **| reason morkBlob does: we want minimal size vectors of morkText.)
00106 |*/
00107 class morkText : public morkBlob { // greater subset of nsIMdbYarn slots
00108 
00109   // void*         mBuf_Body;  // space for holding any binary content
00110   // mdb_fill      mBuf_Fill;  // logical content in Buf in bytes
00111   // mdb_size      mBlob_Size;  // physical size of Buf in bytes
00112 
00113 public:
00114   mork_cscode    mText_Form;  // charset format encoding
00115 
00116   morkText() { }
00117 
00118 private: // copying is not allowed
00119   morkText(const morkText& other);
00120   morkText& operator=(const morkText& other);
00121 };
00122 
00123 /*| Coil: a text with an associated nsIMdbHeap instance that provides
00124 **| all memory management for the space pointed to by mBuf_Body. (This
00125 **| was the hardest type to give a name in this small class hierarchy,
00126 **| because it's hard to characterize self-management of one's space.)
00127 **| A coil is a self-contained blob that knows how to grow itself as
00128 **| necessary to hold more content when necessary.  Coil descends from
00129 **| morkText to include the mText_Form slot, even though this won't be
00130 **| needed always, because we are not as concerned about the overall
00131 **| size of this particular Coil object (if we were concerned about
00132 **| the size of an array of Coil instances, we would not bother with
00133 **| a separate heap pointer for each of them).
00134 **|
00135 **|| A coil makes a good medium in which to stream content as a sink,
00136 **| so we will have a subclass of morkSink called morkCoil that
00137 **| will stream bytes into this self-contained coil object. The name
00138 **| of this morkCoil class derives more from this intended usage than
00139 **| from anything else.  The Mork code to parse db content will use
00140 **| coils with associated sinks to accumulate parsed strings.
00141 **|
00142 **|| Heap: this is the heap used for memory allocation.  This instance
00143 **| is NOT refcounted, since this coil always assumes the heap is held
00144 **| through a reference elsewhere (for example, through the same object
00145 **| that contains or holds the coil itself.  This lack of refcounting
00146 **| is consistent with the fact that morkCoil itself is not refcounted,
00147 **| and is not intended for use as a standalone object.
00148 |*/
00149 class morkCoil : public morkText { // self-managing text blob object
00150 
00151   // void*         mBuf_Body;  // space for holding any binary content
00152   // mdb_fill      mBuf_Fill;  // logical content in Buf in bytes
00153   // mdb_size      mBlob_Size;  // physical size of Buf in bytes
00154   // mdb_cscode    mText_Form;  // charset format encoding
00155 public:
00156   nsIMdbHeap*      mCoil_Heap;  // storage manager for mBuf_Body pointer
00157 
00158 public:
00159   morkCoil(morkEnv* ev, nsIMdbHeap* ioHeap);
00160   
00161   void CloseCoil(morkEnv* ev);
00162 
00163   mork_bool GrowCoil(morkEnv* ev, mork_size inNewSize)
00164   { return this->GrowBlob(ev, mCoil_Heap, inNewSize); }
00165 
00166 private: // copying is not allowed
00167   morkCoil(const morkCoil& other);
00168   morkCoil& operator=(const morkCoil& other);
00169 };
00170 
00171 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00172 
00173 #endif /* _MORKBLOB_ */