Back to index

lightning-sunbird  0.9+nobinonly
nsMsgKeySet.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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) 1998
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 _nsMsgKeySet_H_
00039 #define _nsMsgKeySet_H_
00040 
00041 #include "msgCore.h"
00042 
00043 class nsMsgKeyArray;
00044 
00045 // nsMsgKeySet represents a set of articles.  Typically, it is the set of
00046 // read articles from a .newsrc file, but it can be used for other purposes
00047 // too.
00048 
00049 #if 0
00050 // If a MSG_NewsHost* is supplied to the creation routine, then that
00051 // MSG_NewsHost will be notified whenever a change is made to set.
00052 class MSG_NewsHost;
00053 #endif
00054 
00055 class NS_MSG_BASE nsMsgKeySet {
00056 public:
00057   // Creates an empty set.
00058   static nsMsgKeySet* Create(/* MSG_NewsHost* host = NULL*/);
00059 
00060   // Creates a set from the list of numbers, as might be found in a
00061   // newsrc file.
00062   static nsMsgKeySet* Create(const char* str/* , MSG_NewsHost* host = NULL*/);
00063   ~nsMsgKeySet();
00064   
00065   // FirstNonMember() returns the lowest non-member of the set that is
00066   // greater than 0.
00067   PRInt32 FirstNonMember();
00068 
00069   // Output() converts to a string representation suitable for writing to a
00070   // .newsrc file.  
00071   nsresult Output(char **outputStr);             
00072 
00073   // IsMember() returns whether the given article is a member of this set.
00074   PRBool IsMember(PRInt32 art);
00075   
00076   // Add() adds the given article to the set.  (Returns 1 if a change was
00077   // made, 0 if it was already there, and negative on error.)
00078   int Add(PRInt32 art);
00079   
00080   // Remove() removes the given article from the set. 
00081   int Remove(PRInt32 art);
00082   
00083   // AddRange() adds the (inclusive) given range of articles to the set.
00084   int AddRange(PRInt32 first, PRInt32 last);
00085   
00086   // CountMissingInRange() takes an inclusive range of articles and returns
00087   // the number of articles in that range which are not in the set.
00088   PRInt32 CountMissingInRange(PRInt32 start, PRInt32 end);
00089   
00090   // FirstMissingRange() takes an inclusive range and finds the first range
00091   // of articles that are not in the set.  If none, return zeros. 
00092   int FirstMissingRange(PRInt32 min, PRInt32 max, PRInt32* first, PRInt32* last);
00093   
00094 
00095   // LastMissingRange() takes an inclusive range and finds the last range
00096   // of articles that are not in the set.  If none, return zeros. 
00097   int LastMissingRange(PRInt32 min, PRInt32 max, PRInt32* first, PRInt32* last);
00098   
00099   PRInt32 GetLastMember();
00100   PRInt32 GetFirstMember();
00101   void  SetLastMember(PRInt32 highWaterMark);
00102   // For debugging only...
00103   PRInt32 getLength() {return m_length;}
00104 
00111   nsresult ToMsgKeyArray(nsMsgKeyArray **aArray);
00112   
00113 #ifdef DEBUG
00114   static void RunTests();
00115 #endif
00116 
00117 protected:
00118   nsMsgKeySet(/* MSG_NewsHost* host */);
00119   nsMsgKeySet(const char* /* , MSG_NewsHost* host */);
00120   PRBool Grow();
00121   PRBool Optimize();
00122   
00123 #ifdef DEBUG
00124   static void test_decoder(const char*);
00125   static void test_adder();
00126   static void test_ranges();
00127   static void test_member(PRBool with_cache);
00128 #endif
00129   
00130   PRInt32 *m_data;                               /* the numbers composing the `chunks' */
00131   PRInt32 m_data_size;                           /* size of that malloc'ed block */
00132   PRInt32 m_length;                       /* active area */
00133   
00134   PRInt32 m_cached_value;                 /* a potential set member, or -1 if unset*/
00135   PRInt32 m_cached_value_index;           /* the index into `data' at which a search
00136                                                                   to determine whether `cached_value' was
00137                                                                   a member of the set ended. */
00138 #ifdef NEWSRC_DOES_HOST_STUFF
00139   MSG_NewsHost* m_host;
00140 #endif
00141 };
00142 
00143 
00144 #endif /* _nsMsgKeySet_H_ */