00001 // /******************************************************************************\ 00002 // * 00003 // * File: ContextManager.h 00004 // * Creation date: June 22, 2001 11:59 00005 // * Author: ClassBuilder 00006 // * XXXX 00007 // * Purpose: Declaration of class 'SqContextManager' 00008 // * 00009 // * Modifications: @INSERT_MODIFICATIONS(* ) 00010 // * 00011 // * 00012 // \******************************************************************************/ 00013 #ifndef _CONTEXTMANAGER_H 00014 #define _CONTEXTMANAGER_H 00015 00016 //@START_USER1 00021 /* -------------------------------------------------------------- 00022 Copyright (C) 2001 LifeLine Networks BV <soap2corba@lifeline.nl> 00023 00024 This program is free software; you can redistribute it and/or 00025 modify it under the terms of the GNU General Public License 00026 as published by the Free Software Foundation; either 00027 version 2 of the License, or (at your option) any later 00028 version. 00029 00030 This program is distributed in the hope that it will be useful, 00031 but WITHOUT ANY WARRANTY; without even the implied warranty of 00032 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00033 GNU General Public License for more details. 00034 00035 You should have received a copy of the GNU General Public License 00036 along with this program; if not, write to the Free Software 00037 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00038 -------------------------------------------------------------- */ 00039 //@END_USER1 00040 00041 00045 class SqContextManager 00046 { 00047 // RELATION_UNIQUEVALUETREE_OWNED_ACTIVE(SqContextManager, ContextManager, SqContext, Context) 00048 private: 00049 SqContext * _firstContext; 00050 int _countContext; 00051 00052 protected: 00053 00054 public: 00055 void AddContext(SqContext* item); 00056 void RemoveContext(SqContext* item); 00057 void DeleteAllContext(); 00058 void ReplaceContext(SqContext* item, SqContext* newItem); 00059 SqContext* GetFirstContext() const; 00060 SqContext* GetLastContext() const; 00061 SqContext* GetNextContext(SqContext* pos) const; 00062 SqContext* GetPrevContext(SqContext* pos) const; 00063 int GetContextCount() const; 00064 00065 class ContextIterator 00066 { 00067 private: 00068 SqContext* _refContext; 00069 SqContext* _prevContext; 00070 SqContext* _nextContext; 00071 const SqContextManager* _iterContextManager; 00072 00073 ContextIterator* _prev; 00074 ContextIterator* _next; 00075 00076 int (SqContext::*_method)() const; 00077 00078 static ContextIterator* _first; 00079 static ContextIterator* _last; 00080 00081 public: 00082 ContextIterator(const SqContextManager* iterContextManager, 00083 int (SqContext::*method)() const = 0, 00084 SqContext* refContext = 0); 00085 ContextIterator(const SqContextManager& iterContextManager, 00086 int (SqContext::*method)() const = 0, 00087 SqContext* refContext = 0); 00088 ContextIterator(const ContextIterator& iterator, 00089 int (SqContext::*method)() const = 0); 00090 ~ContextIterator(); 00091 00092 ContextIterator& operator= (const ContextIterator& iterator) 00093 { 00094 _iterContextManager = iterator._iterContextManager; 00095 _refContext = iterator._refContext; 00096 _prevContext = iterator._prevContext; 00097 _nextContext = iterator._nextContext; 00098 _method = iterator._method; 00099 return *this; 00100 } 00101 SqContext* operator++ () 00102 { 00103 _nextContext = _iterContextManager->GetNextContext(_nextContext); 00104 if (_method != 0) 00105 { 00106 while (_nextContext && !(_nextContext->*_method)()) 00107 _nextContext = _iterContextManager->GetNextContext(_nextContext); 00108 } 00109 _refContext = _prevContext = _nextContext; 00110 return _refContext; 00111 } 00112 SqContext* operator-- () 00113 { 00114 _prevContext = _iterContextManager->GetPrevContext(_prevContext); 00115 if (_method != 0) 00116 { 00117 while (_prevContext && !(_prevContext->*_method)()) 00118 _prevContext = _iterContextManager->GetPrevContext(_prevContext); 00119 } 00120 _refContext = _nextContext = _prevContext; 00121 return _refContext; 00122 } 00123 operator SqContext*() { return _refContext; } 00124 SqContext* operator-> () { return _refContext; } 00125 SqContext* Get() { return _refContext; } 00126 void Reset() { _refContext = _prevContext = _nextContext = (SqContext*)0; } 00127 00128 int IsLast() { return (_iterContextManager->GetLastContext() == _refContext); } 00129 int IsFirst() { return (_iterContextManager->GetFirstContext() == _refContext); } 00130 00131 static void Check(SqContext* itemContext); 00132 static void Check(SqContext* itemContext, SqContext* newItemContext); 00133 }; 00134 00135 //@START_USER2 00136 //@END_USER2 00137 00138 // Members 00139 private: 00140 00141 protected: 00142 00143 public: 00144 00145 // Methods 00146 private: 00147 void ConstructorInclude(); 00148 void DestructorInclude(); 00149 00150 protected: 00151 00152 public: 00153 SqContextManager(); 00154 virtual ~SqContextManager(); 00155 CString CreateContext(unsigned short timeout, CString UserData); 00156 unsigned long DecodeKey(const char* contextKey); 00157 SqContext* FindContext(unsigned long key); 00158 }; 00159 00160 #endif 00161 00162 00163 #ifdef CB_INLINES 00164 #ifndef _CONTEXTMANAGER_H_INLINES 00165 #define _CONTEXTMANAGER_H_INLINES 00166 00167 //@START_USER3 00168 //@END_USER3 00169 00170 #endif 00171 #endif 00172