00001 /*! \file 00002 \author victorien ferry & www.m4nkind.com 00003 \brief This file applies the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 , read file COPYING. 00004 */ 00005 #ifndef COM_M4NKIND_PackList_TimeBlockTrack_H 00006 #define COM_M4NKIND_PackList_TimeBlockTrack_H 00007 00008 #include "PackList.h" 00009 #include "PackFloat_FixedPoint.h" 00010 /*! 00011 \class PackList_TimeBlockTrack 00012 \ingroup BaseSerializableClass 00013 \brief List that defines a set of TimeTrackElement extended objects. 00014 the difference with PackList_TimeTrack is that elements 00015 serialize block length and not dates... 00016 */ 00017 00018 class PackList_TimeBlockTrack : public PackList 00019 { 00020 /*================================================================== 00021 PUBLIC 00022 ==================================================================*/ 00023 public: 00024 class TimeBlockTrackElement; 00025 //! TimeTrackElementCreatorCallBackFunction stands for a pointer to a static method that make a new TimeTrackElement. 00026 typedef TimeBlockTrackElement *(*TimeBlockTrackElementCreatorCallBackFunction)(void); 00027 00028 /*! 00029 \brief Constructor. Like PAckList you specify an element constructor, 00030 and the meaning of time by elements. Dates and length are then given in seconds. 00031 \param _func a function that return a new object to manage as an element of the list. 00032 \param _SerializeLengthBlock if false, the date in seconds is serialized by elements,if true, the length of elements is serialized. 00033 */ 00034 PackList_TimeBlockTrack( TimeBlockTrackElementCreatorCallBackFunction _func/*,bool _SerializeLengthBlock=false*/); 00035 00036 #ifdef _ENGINE_EDITABLE_ 00037 /*! 00038 \brief Each BaseType's inherited classes must explicit an ID for their 00039 class, or let use one of the super class at least through this virtual method. 00040 This is needed by GUIs to detect the types of each sub-members, and shape 00041 an interface for each Object according to their member list. 00042 \return a const character string, that must be unique and unchanged for all serializable base type. 00043 */ 00044 virtual const char *GetClassID() const { return "PackList::PackList_TimeBlockTrack"; }; 00045 #endif 00046 #ifdef _ENGINE_EDITABLE_ 00047 /*! 00048 \brief Edition tool: Exchange 2 neighbour elements in the list, if there is a next element. 00049 if index is 0, 0 will be 1 and 1 will be 0. 00050 \param _indexOfElementToSwapWithNext any row, from zero to GetNumberOfCell()-2 00051 */ 00052 virtual void SwapElements( unsigned int _indexOfElementToSwapWithNext); 00053 #endif 00054 #ifdef _ENGINE_EDITABLE_ 00055 /*! \brief In edition mode, there is a default timelength you can set at init: 00056 \param _DefaultTimeCellLength in seconds. 00057 */ 00058 void SetDefaultTimeCellLength( double _DefaultTimeCellLength=8.0 ); 00059 #endif 00060 /*! 00061 \brief Nested class that describe a dated element in the list. 00062 It has to be extended with new serializable members (ex: splines, scripts, music tracks..). 00063 It manages the fact that the time are kept sorted in edition mode. 00064 */ 00065 class TimeBlockTrackElement : public PackStruct 00066 { 00067 public: 00068 //! constructor: 00069 TimeBlockTrackElement(); 00070 //! \brief return the time date in second. 00071 inline float GetTimeInSecond(){ return mSer_TimeBlock.Get() ; }; 00072 00073 #ifdef _ENGINE_EDITABLE_ 00074 //! \brief Set the time in seconds in edition mode. It assures the dates are sorted. 00075 virtual void SetTimeInSecond( double _timeSec ); 00076 #endif 00077 #ifdef _ENGINE_EDITABLE_ 00078 /*! 00079 \brief Nested class that patch the virtual PackFloat_FixedPoint::Set() 00080 in edition mode, in order to force a test to assure that the elements 00081 of the list are kept sorted by time date when edited. (yes, it is tricky, but private.) 00082 */ 00083 class PackFloat_FixedPoint_TimeBlock : public PackFloat_FixedPoint 00084 {public: 00085 PackFloat_FixedPoint_TimeBlock(float _fp) : PackFloat_FixedPoint(_fp){}; 00086 virtual void Set(float _value); 00087 protected: 00088 }; 00089 #else 00090 //in non-editable mode, the time date field in each element is a PackFloat_FixedPoint. 00091 typedef PackFloat_FixedPoint PackFloat_FixedPoint_TimeBlock; 00092 #endif 00093 // ------------ PROTECTED ----------- 00094 protected: 00095 //! the time in second, as serialized. 00096 PackFloat_FixedPoint_TimeBlock mSer_TimeBlock; 00097 }; 00098 /*! 00099 \brief Find the Cell which match a given date in the list. 00100 It means the date is between this element and the next elment's date. 00101 Then get its TimeTrackElement with ->GetManagedObject(). 00102 \param _dateInSecond double date in second. 00103 \return the element, or the first elt if date before. 00104 */ 00105 virtual Cell *GetCellByDate( double _dateInSecond ); 00106 #ifdef _ENGINE_EDITABLE_ 00107 /*! 00108 \brief Override PackList to assure the list is date-sorted. 00109 Add a new element, at the given index, in edition context. 00110 in non-editable, it shouldnt be used, and serialization recreate the elements. 00111 when asked a first element, as the track must have a length, 00112 we create 2 elements: a zero timed one, and a end with default time length. 00113 00114 \param _indexWhereToInsert the index where to insert. if -1, at the end. 00115 \param _pObjectToAdd object to manage, or NULL to set it after on the cell. 00116 \return the element created. 00117 */ 00118 virtual Cell * AddElement( int _indexWhereToInsert=-1,BaseType *_pObjectToAdd=0L); 00119 #endif 00120 00121 /*================================================================== 00122 PROTECTED 00123 ==================================================================*/ 00124 protected: 00125 00126 #ifdef _ENGINE_EDITABLE_ 00127 //! In edition mode, there is a default start timelength. 00128 double m_DefaultTimeCellLength; 00129 #endif 00130 }; 00131 00132 /*! 00133 \def REGISTER_MEMBER_TIMEBLOCKTRACK 00134 00135 \brief This macro is used to register a serializable member in a class constructor. 00136 For editable mode, it uses _MemberName to explicit the use of the member, in order 00137 to display it in a GUI for example. 00138 \param _object the member object 00139 \param _MemberName the info string, 0L if not editable. 00140 \param _DefaultTimeCellLengthSec a default time length, or 0L if no particular time length. 00141 00142 */ 00143 #ifdef _ENGINE_EDITABLE_ 00144 #define REGISTER_MEMBER_TIMEBLOCKTRACK(_object,_MemberName,_DefaultTimeCellLengthSec) \ 00145 RegisterSerializableMember(_object);\ 00146 _object.SetMemberName( _MemberName );\ 00147 _object.SetDefaultTimeCellLength(_DefaultTimeCellLengthSec); 00148 #else 00149 #define REGISTER_MEMBER_TIMEBLOCKTRACK(_object,_MemberName,_DefaultTimeLengthSec) \ 00150 RegisterSerializableMember(_object); 00151 #endif 00152 // end of file 00153 #endif
/\/\ 4 N k ! N D _______ _ __ ___ _____ ___ _ _ ____ ___________ __//___ /________ |/ / ___________\_______/ \ / _ _ \/ _ / _ / _/_/____/ _ __ / / / / / / / \ \/ / / \ \ / \\___/___/___/ ¯ _____/_____/ ______\___/_____/\________\\ \________/_ ___ __ l____\ /elD! http://www.m4nkind.com \____/