/** * @file XTPCalendarMemoryDataProvider.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #if !defined(_XTPCALENDARMEMORYDATAPROVIDER_H__) # define _XTPCALENDARMEMORYDATAPROVIDER_H__ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" ///////////////////////////////////////////////////////////////////////////// class CXTPCalendarEvent; class CXTPCalendarRecurrencePattern; /** * @brief * Define events storage hash table size. Should be a prime number! * like: 503, 1021, 1511, 2003, 3001, 4001, 5003, 6007, 8009, 12007, * 16001, 32003, 48017, 64007 * * @see CXTPCalendarData::EventsMapByID_T overview * @see CMap overview */ # define XTP_EVENTS_STORAGE_HASH_TABLE_SIZE 4001 /** * @brief * This class implements an abstract representation of the data used * in the XTPCalendarData class. * * @details * This class is the implementation of the XTPCalendarData abstract * class which represents a data portion of the Calendar control. * * This class provides a memory storage implementation of the * CXTPCalendarData class. It stores all elements using standard * CXTPCalendarEvents array collection and provides fast search * on it using search tree algorithms. * * To use CXTPCalendarMemoryDataProvider, you first construct an instance * of a CXTPCalendarDatabaseDataProvider object. Then use the Open() member * function to establish a connection to the data source and initialize the * object. This class provides a number of functions to manipulate events and * events related data. After finishing work with the data source, you should * call the Close() member function to close the connection, de-initialize the * object and free unused resources. * * @see CXTPCalendarData overview * @see CXTPCalendarEvents * @see CXTPCalendarEvent */ class _XTP_EXT_CLASS CXTPCalendarMemoryDataProvider : public CXTPCalendarData { /** @cond */ DECLARE_DYNAMIC(CXTPCalendarMemoryDataProvider) /** @endcond */ public: /** * @brief * Default constructor. * * @details * Constructs a Data object. To establish a connection to a * specified data source and initialize the object you must * call the Open() member function immediately after construction. * * @see Open() */ CXTPCalendarMemoryDataProvider(); /** * @brief * Default Destructor. * * @details * Handles all deallocation. */ virtual ~CXTPCalendarMemoryDataProvider(); /** * @brief * Call this member function to initialize a newly constructed * Data object. Your data object must be created before you * can call Open(). * * @return Boolean value represents succsess/failure result */ virtual BOOL Open(); /** * @brief * Call this member function to create a file for storing memory * data provider data. * * @details * It will be opened by default. * * @return TRUE is successful. FALSE otherwise. */ virtual BOOL Create(); /** * @brief * This method saves data to the file. * * @details * The most recent data from the data provider will be saved in * the same file as before. * * @return TRUE is successful. FALSE otherwise. */ virtual BOOL Save(); /** * @brief * Call this member function to close the connection to a data source. */ virtual void Close(); /** * @brief * Call this member function to get a collection of events for the specified date range. * * @param dtStartDay A COleDateTime object without the time portion. * @param dtEndDay A COleDateTime object without the time portion. * * @return A CXTPCalendarEvents pointer containing a collection of day events. * * @see CXTPCalendarEvents */ virtual CXTPCalendarEventsPtr RetrieveEvents(COleDateTime dtStartDay, COleDateTime dtEndDay); /** * @brief * This method reads data from or writes data to an archive. * * @param ar A CArchive object to serialize to or from. * * @details * For the save case, the most recent data from the data provider * will be saved to the archive. * For the load case, existing data is not removed from the data * provider and new data will be loaded from the specified * archive and added to the existing data set. * Call RemoveAllEvents() manually if you need a cleanup before load. * For load and save operations, the _Load() and _Save() protected methods * are used respectfully. Method can throw CArchiveException. * * @see _Load() * @see _Save() */ virtual void Serialize(CArchive& ar); /** * @brief * This method reads data from or writes data to storage. * * @param pPX A CXTPPropExchange object to serialize to or from. * * @details * For the save case, the most recent data from the data provider * will be saved to the archive. * For the load case, existing data is not removed from the data * provider and new data will be loaded from the specified * archive and added to the existing data set. * Call RemoveAllEvents() manually if you need a cleanup before load. * For load and save operations, the _Load() and _Save() protected methods * are used respectfully. Method can throw CArchiveException. * * @see _Load() * @see _Save() */ virtual void DoPropExchange(CXTPPropExchange* pPX); protected: /** * @brief * This method reads data from an archive. * * @param pPX A CXTPPropExchange object to serialize to or from. * * @details * The existing data is not removed from the data provider and * new data will be loaded from the specified archive and * added to the existing data set. * Call RemoveAllEvents() manually if you need a cleanup before load. * Method can throw CArchiveException. * * @return TRUE is successful. FALSE otherwise. * * @see _Save() * @see Serialize() */ virtual BOOL _Load(CXTPPropExchange* pPX); /** * @brief * This method writes data to an archive. * * @param pPX A CXTPPropExchange object to serialize to or from. * * @details * The most recent data from the data provider will be saved to * archive. * Method can throw CArchiveException. * * @return TRUE is successful. FALSE otherwise. * * @see _Load() * @see Serialize() */ virtual BOOL _Save(CXTPPropExchange* pPX); /** * @brief * Retrieves day events for a specified day from the memory storage. * * @param dtDay A specified day. * * @details * This method retrieves all appointments for a specified day from * the memory storage. It includes recurrence appointments occurrences, * regular appointments for this day, and multi-day appointments which * also have a part of this day. * * @return A collection of events for a specified day. */ virtual CXTPCalendarEventsPtr DoRetrieveDayEvents(COleDateTime dtDay); /** * @brief * Removes all events from the memory storage. * * @details * This method removes all appointments from the memory storage. */ virtual void DoRemoveAllEvents(); /** * @brief * Read event from the memory storage. * * @param dwEventID Event ID of the read target. * * @details * This method retrieves all data for a specified event. * * @return A pointer to the new CXTPCalendarEvent object in which fields * are filled with a data from the corresponding memory storage. */ virtual CXTPCalendarEventPtr DoRead_Event(DWORD dwEventID); /** * @brief * Read recurrence pattern from the memory storage. * * @param dwPatternID Pattern ID of the read target. * * @details * This method retrieves all data for a specified recurrence pattern. * * @return A pointer to the new CXTPCalendarRecurrencePatternPtr object in which * fields are filled with a data from the corresponding memory storage. */ virtual CXTPCalendarRecurrencePatternPtr DoRead_RPattern(DWORD dwPatternID); /** * @brief * Creates a new event in the memory storage. * * @param pEvent Pointer to the CXTPCalendarEvent object which describes * all data fields of a newly created record. * @param rdwNewEventID [out] EventID of a newly created record * * @details * This method creates a memory data record corresponding with the * specified event. * * @return TRUE if event created successfully, * FALSE in case of any error during the process. */ virtual BOOL DoCreate_Event(CXTPCalendarEvent* pEvent, DWORD& rdwNewEventID); /** * @brief * Updates event properties in the memory storage. * * @param pEvent Pointer to the CXTPCalendarEvent object which describes * all data fields of an event. * * @details * This method updates a memory data record corresponding with the * specified event. * * @return TRUE if an event updated successfully, * FALSE in case of any errors during the process. */ virtual BOOL DoUpdate_Event(CXTPCalendarEvent* pEvent); /** * @brief * Deletes an event from the memory storage. * * @param pEvent Pointer to the CXTPCalendarEvent object which describes * all data fields of an event. * * @details * This method deletes a memory data record corresponding with the * specified event. * * @return TRUE if an event deleted successfully, * FALSE in case of any errors during the process. */ virtual BOOL DoDelete_Event(CXTPCalendarEvent* pEvent); /** * @brief * Creates a new recurrence pattern in the memory storage. * * @param pPattern Pointer to the CXTPCalendarRecurrencePattern object which * describes all data fields of a newly created memory record. * @param rdwNewPatternID [out] ID of a newly created memory record * * @details * This method creates a memory data record corresponding with the * specified recurrence pattern. * * @return TRUE if recurrence pattern created successfully, * FALSE in case of any error during the process. */ virtual BOOL DoCreate_RPattern(CXTPCalendarRecurrencePattern* pPattern, DWORD& rdwNewPatternID); /** * @brief * Updates a recurrence pattern in the memory storage. * * @param pPattern Pointer to the CXTPCalendarRecurrencePattern object. * * @details * This method updates a memory data record corresponding with the * specified recurrence pattern. * * @return TRUE if recurrence pattern updated successfully, * FALSE in case of any error during the process. */ virtual BOOL DoUpdate_RPattern(CXTPCalendarRecurrencePattern* pPattern); /** * @brief * Deletes a recurrence pattern from the memory storage. * * @param pPattern Pointer to the CXTPCalendarRecurrencePattern object * which should be deleted. * * @details * This method deletes a memory data record corresponding with the * specified recurrence pattern. * * @return TRUE if recurrence pattern deleted successfully, * FALSE in case of any error during the process. */ virtual BOOL DoDelete_RPattern(CXTPCalendarRecurrencePattern* pPattern); /** * @brief * This method implements getting all events from the memory storage * without generating recurrence occurrences. * * @details * Simple events are included as is. * For the recurrence events only master events are included, * recurrence occurrences are not generated. * * @return A CXTPCalendarEvents pointer containing a collection of * all events. * * @see GetAllEvents_raw() */ virtual CXTPCalendarEventsPtr DoGetAllEvents_raw(); /** * @brief * Retrieves a collection of events expiring in the period from * dtFrom during next spPeriod. * * @param dtFrom Start date and time of a specified period. * @param spPeriod A duration of a specified period. * * @details * This method returns a collection of upcoming events. * It is used by a reminders manager. * * @return * A CXTPCalendarEvents pointer containing a collection of * upcoming events. * @see * CXTPCalendarRemindersManager overview */ virtual CXTPCalendarEventsPtr DoGetUpcomingEvents(COleDateTime dtFrom, COleDateTimeSpan spPeriod); /** * @brief * This method is called by the calendar control framework when the Time Zone is Changed. * * @details * The data provider implementation may use this method to adjust its data for * a new timezone. * * @return TRUE if internal data has changed and the calendar must be re-populated, * FALSE if this event is ignored (no data changed). * Base implementation does nothing and returns FALSE. * * @see CXTPTopLevelWndMsgNotifier * @see XTP_WM_TIME_ZONE_CHANGED */ virtual BOOL OnTimeZoneChanged() { return TRUE; }; private: typedef CMap CMapIDtoEvent; struct DSTNode /**< Digital Search Tree Node*/ { DSTNode(); ~DSTNode(); DSTNode* pLeft; DSTNode* pRight; void Mark(CXTPCalendarEvent* pEvent); void Unmark(CXTPCalendarEvent* pEvent); BOOL IsMarked(CXTPCalendarEvent* pEvent); void AppendAll(CMapIDtoEvent* pMapEvents); private: typedef CMap EventsMap; EventsMap* m_pMapEvents; }; struct DST /**< Digital Search Tree*/ { DST(); ~DST(); void Insert(CXTPCalendarEvent* pEvent); void Remove(CXTPCalendarEvent* pEvent); void Clear(); void SearchForEvents(DWORD dwStart, DWORD dwEnd, CXTPCalendarEvents* pEvents); private: DSTNode* pHead; /**< properties*/ CMapIDtoEvent tmp_mapEvents; /**< temp data storage*/ private: enum DSTScanType { dstScanMark, dstScanUnmark, dstScanFind }; void ScanRange(DSTNode* const pNode, const int nDepth, const DWORD dwMinValue, const DWORD dwMaxValue, const DWORD dwStart, const DWORD dwEnd, CXTPCalendarEvent* const pEvent, CMapIDtoEvent* pMapEvents, const DSTScanType eScanType); /**< methods*/ void MarkRange(CXTPCalendarEvent* pEvent, const DSTScanType eScanType); }; private: BOOL IsProviderXML(BOOL bCheckXMLsupport, BOOL* pbXMLsupportError = NULL); CString GetXMLEncoding(); DWORD _UniqueID_Event(DWORD dwID); DWORD _UniqueID_Patern(DWORD dwID); private: EventsMapByID_T m_EventsStorage; EventsMapByID_T m_mapPatterns; DST m_tree; //------------------------------------------------------------ // CMap m_mapIsDayInCache; }; # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // !defined(_XTPCALENDARMEMORYDATAPROVIDER_H__)