1 // SSVersionObject.h: interface for the SSActions class.
3 //////////////////////////////////////////////////////////////////////
5 #if !defined(AFX_SSHISTORYOBJECT_H__58F12C7C_FE74_43B1_9BF6_9E803182D8D7__INCLUDED_)
6 #define AFX_SSHISTORYOBJECT_H__58F12C7C_FE74_43B1_9BF6_9E803182D8D7__INCLUDED_
10 #endif // _MSC_VER > 1000
13 #include "SSCommentObject.h"
19 class SSLabeledAction
; // Labeled = 0,
20 class SSCreatedProjectAction
; // Created_Project = 1,
21 class SSAddedProjectAction
; // Added_Project = 2,
22 class SSAddedFileAction
; // Added_File = 3,
23 class SSDestroyedProjectAction
; // Destroyed_Project = 4,
24 class SSDestroyedFileAction
; // Destroyed_File = 5,
25 class SSDeletedProjectAction
; // Deleted_Project = 6,
26 class SSDeletedFileAction
; // Deleted_File = 7,
27 class SSRecoveredProjectAction
; // Recovered_Project = 8,
28 class SSRecoveredFileAction
; // Recovered_File = 9,
29 class SSRenamedProjectAction
; // Renamed_Project = 10,
30 class SSRenamedFileAction
; // Renamed_File = 11,
31 //class SSAction12 // missing action 12,
32 class SSMovedProjectAction
; // Moved_Project = 13,
33 class SSSharedAction
; // Shared_File = 14,
34 class SSBranchFileAction
; // Branch_File = 15,
35 class SSCreatedFileAction
; // Created_File = 16,
36 class SSCheckedInAction
; // Checked_in = 17,
37 //class SSAction18 // missing action 18
38 class SSRollbackAction
; // RollBack = 19
39 class SSArchivedVersionsAction
; // Archived Versions of File
40 class SSArchiveFileAction
; // ArchiveFile
41 class SSArchiveProjectAction
; // ArchiveProject
42 class SSRestoreFileAction
; // RestoreFile
43 class SSRestoreProjectAction
; // RestoreProject
45 class ISSActionVisitor
48 virtual bool Apply (const SSLabeledAction
& rAction
) = 0;
49 virtual bool Apply (const SSCreatedProjectAction
& rAction
) = 0;
50 virtual bool Apply (const SSCreatedFileAction
& rAction
) = 0;
51 virtual bool Apply (const SSAddedProjectAction
& rAction
) = 0;
52 virtual bool Apply (const SSAddedFileAction
& rAction
) = 0;
53 virtual bool Apply (const SSDeletedProjectAction
& rAction
) = 0;
54 virtual bool Apply (const SSDeletedFileAction
& rAction
) = 0;
55 virtual bool Apply (const SSRecoveredProjectAction
& rAction
) = 0;
56 virtual bool Apply (const SSRecoveredFileAction
& rAction
) = 0;
57 virtual bool Apply (const SSBranchFileAction
& rAction
) = 0;
58 virtual bool Apply (const SSRollbackAction
& rAction
) = 0;
59 virtual bool Apply (const SSArchivedVersionsAction
& rAction
) = 0;
60 virtual bool Apply (const SSArchiveFileAction
& rAction
) = 0;
61 virtual bool Apply (const SSArchiveProjectAction
& rAction
) = 0;
62 virtual bool Apply (const SSRestoreFileAction
& rAction
) = 0;
63 virtual bool Apply (const SSRestoreProjectAction
& rAction
) = 0;
65 virtual bool Apply (const SSDestroyedProjectAction
& rAction
) = 0;
66 virtual bool Apply (const SSDestroyedFileAction
& rAction
) = 0;
67 virtual bool Apply (const SSRenamedProjectAction
& rAction
) = 0;
68 virtual bool Apply (const SSRenamedFileAction
& rAction
) = 0;
69 virtual bool Apply (const SSCheckedInAction
& rAction
) = 0;
70 virtual bool Apply (const SSSharedAction
& rAction
) = 0;
71 virtual bool Apply (const SSMovedProjectAction
& rAction
) = 0;
74 //---------------------------------------------------------------------------
78 SSAction (SSRecordPtr pRecord
);
81 static SSAction
* MakeAction (SSRecordPtr pRecord
);
83 virtual eAction
GetActionID () const { return m_ActionId
; }
85 virtual std::string
FormatActionString () = 0;
86 virtual bool Accept (ISSActionVisitor
& rVisitor
) = 0;
88 virtual void ToXml (XMLNode
* pParent
) const = 0;
89 virtual void Dump (std::ostream
& os
) const;
92 const VERSION_RECORD
* GetHistoryRecordPtr (SSRecordPtr pRecord
) const;
96 //---------------------------------------------------------------------------
97 class SSVersionObject
: public SSObject
100 SSVersionObject (SSRecordPtr pRecord
);
101 virtual ~SSVersionObject ();
103 // handle copy constructor und assigment
104 SSVersionObject (SSVersionObject
const & object
);
105 SSVersionObject
& operator= (SSVersionObject
const & object
);
107 // BOOST_PP_SEQ_FOR_EACH(DEFINE_ACCESSORS, GetData(), VERSION_RECORD_SEQ);
108 ulong
GetPrevious () const { return GetData ()->previous
; }
109 eAction
GetActionID () const { return static_cast <eAction
> (GetAction ()->GetActionID ()); }
110 short GetVersionNumber () const { return GetData ()->versionNumber
; }
111 // note the implicit conversion here from Win32 __time32_t to portable time_t
112 time_t GetDate () const { return GetData ()->date
; }
113 std::string
GetUsername () const { return std::string (GetData ()->username
/*, 32*/); }
114 std::string
GetLabel () const { return std::string (GetData ()->label
/*, 32*/); }
115 ulong
GetOffsetToNextRecordOrComment () const { return GetData ()->offsetToNextRecordOrComment
; }
116 ulong
GetOffsetToLabelComment () const { return GetData ()->offsetToLabelComment
; }
117 short GetLengthComment () const { return GetData ()->lengthComment
; }
118 short GetLengthLabelComment () const { return GetData ()->lengthLabelComment
; }
120 // std::string GetUsername () const { return GetData ()->user; }
121 // int GetVersionNumber () const { return GetData ()->version; }
122 // eAction GetActionId () const { return static_cast <eAction> (GetData ()->action); }
123 std::string
GetActionString () const { return m_pAction
? m_pAction
->FormatActionString () : CAction::ActionToString (GetActionID()); }
124 // __time32_t GetDate () const { return GetData ()->date; }
125 std::string
GetComment () const;
127 // special Label Action functions
128 // std::string GetLabel () const;
129 std::string
GetLabelComment () const;
131 // reporting functions
132 virtual void Accept (ISSObjectVisitor
& rVisitor
, const ISSContext
* pCtx
= NULL
) const { rVisitor
.Apply (*this, pCtx
); }
134 const VERSION_RECORD
* GetData () const { return (const VERSION_RECORD
*) SSObject::GetData (); }
136 SSAction
* GetAction () const { return m_pAction
; }
137 SSVersionObject
GetPreviousObject () const;
138 SSCommentObject
GetCommentObject () const;
140 virtual bool Validate ();
142 virtual void ToXml (XMLNode
* pParent
) const;
143 virtual void Dump (std::ostream
& os
) const;
151 //---------------------------------------------------------------------------
152 template <class ACTION
>
153 class SSActionEx
: public SSAction
156 SSActionEx (SSRecordPtr pRecord
)
161 bool Accept (ISSActionVisitor
& rVisitor
)
163 return rVisitor
.Apply(*This());
166 // return a pointer to the most derived class
169 return static_cast<ACTION
*>(this);
174 //---------------------------------------------------------------------------
175 class SSLabeledAction
: public SSActionEx
<SSLabeledAction
>
178 SSLabeledAction (SSRecordPtr pRecord
);
179 virtual ~SSLabeledAction ();
181 std::string
GetLabel () const { return m_Label
; }
182 std::string
GetLabelComment () const { return m_LabelComment
; }
184 virtual std::string
FormatActionString ();
186 virtual void ToXml (XMLNode
* pParent
) const;
187 virtual void Dump (std::ostream
& os
) const;
191 std::string m_LabelComment
;
194 //---------------------------------------------------------------------------
198 virtual std::string
GetPhysical () const = 0;
199 virtual SSName
GetSSName () const = 0;
202 //---------------------------------------------------------------------------
203 template <class ACTION
, class STRUCT
>
204 class SSItemAction
: public SSActionEx
<ACTION
>, public ISSItemAction
207 SSItemAction (SSRecordPtr pRecord
, std::string actionString
);
209 std::string
GetPhysical () const { return std::string (m_Action
.physical
, std::min (strlen (m_Action
.physical
), (size_t)8)); }
210 SSName
GetSSName () const { return m_Action
.name
; }
212 std::string
GetName () const { SSName
name (GetSSName ()); return name
.GetFullName (); }
214 virtual std::string
FormatActionString ();
216 virtual void ToXml (XMLNode
* pParent
) const;
217 virtual void Dump (std::ostream
& os
) const;
221 std::string m_ActionString
;
224 class SSCreatedProjectAction
: public SSItemAction
<SSCreatedProjectAction
, ITEM_ACTION
>
227 SSCreatedProjectAction (SSRecordPtr pRecord
)
228 : SSItemAction
<SSCreatedProjectAction
, ITEM_ACTION
> (pRecord
, "Created Project $")
233 class SSCreatedFileAction
: public SSItemAction
<SSCreatedFileAction
, ITEM_ACTION
>
236 SSCreatedFileAction (SSRecordPtr pRecord
)
237 : SSItemAction
<SSCreatedFileAction
, ITEM_ACTION
> (pRecord
, "Created File ")
242 class SSAddedProjectAction
: public SSItemAction
<SSAddedProjectAction
, ITEM_ACTION
>
245 SSAddedProjectAction (SSRecordPtr pRecord
)
246 : SSItemAction
<SSAddedProjectAction
, ITEM_ACTION
> (pRecord
, "Added Project $")
251 class SSAddedFileAction
: public SSItemAction
<SSAddedFileAction
, ITEM_ACTION
>
254 SSAddedFileAction (SSRecordPtr pRecord
)
255 : SSItemAction
<SSAddedFileAction
, ITEM_ACTION
> (pRecord
, "Added File ")
260 class SSDeletedProjectAction
: public SSItemAction
<SSDeletedProjectAction
, ITEM_ACTION
>
263 SSDeletedProjectAction (SSRecordPtr pRecord
)
264 : SSItemAction
<SSDeletedProjectAction
, ITEM_ACTION
> (pRecord
, "Deleted Project $")
269 class SSDeletedFileAction
: public SSItemAction
<SSDeletedFileAction
, ITEM_ACTION
>
272 SSDeletedFileAction (SSRecordPtr pRecord
)
273 : SSItemAction
<SSDeletedFileAction
, ITEM_ACTION
> (pRecord
, "Deleted File ")
278 class SSRecoveredProjectAction
: public SSItemAction
<SSRecoveredProjectAction
, ITEM_ACTION
>
281 SSRecoveredProjectAction (SSRecordPtr pRecord
)
282 : SSItemAction
<SSRecoveredProjectAction
, ITEM_ACTION
> (pRecord
, "Recovered Project ")
287 class SSRecoveredFileAction
: public SSItemAction
<SSRecoveredFileAction
, ITEM_ACTION
>
290 SSRecoveredFileAction (SSRecordPtr pRecord
)
291 : SSItemAction
<SSRecoveredFileAction
, ITEM_ACTION
> (pRecord
, "Recovered File ")
296 //---------------------------------------------------------------------------
297 class SSBranchFileAction
: public SSItemAction
<SSBranchFileAction
, BRANCH_FILE_ACTION
>
300 SSBranchFileAction (SSRecordPtr pRecord
)
301 : SSItemAction
<SSBranchFileAction
, BRANCH_FILE_ACTION
> (pRecord
, "Branched file ")
305 std::string
GetParent () const { return std::string (m_Action
.parent
, 8); }
307 virtual void ToXml (XMLNode
* pParent
) const;
308 virtual void Dump (std::ostream
& os
) const;
311 //---------------------------------------------------------------------------
312 class SSRollbackAction
: public SSItemAction
<SSRollbackAction
, ROLLBACK_ACTION
>
315 SSRollbackAction (SSRecordPtr pRecord
)
316 : SSItemAction
<SSRollbackAction
, ROLLBACK_ACTION
> (pRecord
, "Rolled back ")
320 std::string
GetParent () const { return std::string (m_Action
.parent
, 8); }
322 virtual void ToXml (XMLNode
* pParent
) const;
323 virtual void Dump (std::ostream
& os
) const;
326 //---------------------------------------------------------------------------
327 class SSArchivedVersionsAction
: public SSItemAction
<SSArchivedVersionsAction
, ARCHIVE_VERSIONS_ACTION
>
330 SSArchivedVersionsAction (SSRecordPtr pRecord
)
331 : SSItemAction
<SSArchivedVersionsAction
, ARCHIVE_VERSIONS_ACTION
> (pRecord
, "Archived versions of ")
335 std::string
GetFileName () const { return std::string (m_Action
.targetFile
); }
336 short GetArchiveVersion () const { return m_Action
.archiveVersion
; }
338 virtual void ToXml (XMLNode
* pParent
) const;
339 virtual void Dump (std::ostream
& os
) const;
342 //---------------------------------------------------------------------------
343 template <class ACTION
>
344 class SSRestoreAction
: public SSItemAction
<ACTION
, RESTORE_ACTION
>
347 SSRestoreAction (SSRecordPtr pRecord
, std::string prefix
)
348 : SSItemAction
<ACTION
, RESTORE_ACTION
> (pRecord
, ""),
353 virtual std::string
FormatActionString ()
356 action
= "Restore " + m_Prefix
+ SSItemAction
<ACTION
, RESTORE_ACTION
>::GetName ();
360 std::string
GetFileName () const { return std::string (SSItemAction
<ACTION
, RESTORE_ACTION
>::m_Action
.filename
); }
362 virtual void ToXml (XMLNode
* pParent
) const;
363 virtual void Dump (std::ostream
& os
) const;
366 std::string m_Prefix
;
369 class SSRestoreProjectAction
: public SSRestoreAction
<SSRestoreProjectAction
>
372 SSRestoreProjectAction (SSRecordPtr pRecord
)
373 : SSRestoreAction
<SSRestoreProjectAction
> (pRecord
, "$")
377 class SSRestoreFileAction
: public SSRestoreAction
<SSRestoreFileAction
>
380 SSRestoreFileAction (SSRecordPtr pRecord
)
381 : SSRestoreAction
<SSRestoreFileAction
> (pRecord
, "")
384 // class SSRestoreAction : public SSItemAction<SSRestoreAction, RESTORE_ACTION>
387 // SSRestoreAction (SSRecordPtr pRecord)
388 // : SSItemAction<SSRestoreAction, RESTORE_ACTION> (pRecord, "Restore ")
392 // std::string GetFileName () const { return std::string (m_Action.filename); }
394 // virtual void ToXml (XMLNode* pParent) const;
395 // virtual void Dump (std::ostream& os) const;
398 //---------------------------------------------------------------------------
399 template <class ACTION
>
400 class SSArchiveAction
: public SSItemAction
<ACTION
, ARCHIVE_ACTION
>
403 SSArchiveAction (SSRecordPtr pRecord
, std::string prefix
)
404 : SSItemAction
<ACTION
, ARCHIVE_ACTION
> (pRecord
, ""),
409 virtual std::string
FormatActionString ()
412 action
= "Archive " + m_Prefix
+ SSItemAction
<ACTION
, ARCHIVE_ACTION
>::GetName ();
416 std::string
GetFileName () const { return std::string (SSItemAction
<ACTION
, ARCHIVE_ACTION
>::m_Action
.filename
); }
418 virtual void ToXml (XMLNode
* pParent
) const;
419 virtual void Dump (std::ostream
& os
) const;
422 std::string m_Prefix
;
425 class SSArchiveProjectAction
: public SSArchiveAction
<SSArchiveProjectAction
>
428 SSArchiveProjectAction (SSRecordPtr pRecord
)
429 : SSArchiveAction
<SSArchiveProjectAction
> (pRecord
, "$")
433 class SSArchiveFileAction
: public SSArchiveAction
<SSArchiveFileAction
>
436 SSArchiveFileAction (SSRecordPtr pRecord
)
437 : SSArchiveAction
<SSArchiveFileAction
> (pRecord
, "")
441 //---------------------------------------------------------------------------
442 template <class ACTION
>
443 class SSDestroyedAction
: public SSItemAction
<ACTION
, DESTROYED_ACTION
>
446 SSDestroyedAction (SSRecordPtr pRecord
, std::string prefix
);
448 virtual std::string
FormatActionString ();
451 std::string m_Prefix
;
454 class SSDestroyedProjectAction
: public SSDestroyedAction
<SSDestroyedProjectAction
>
457 SSDestroyedProjectAction (SSRecordPtr pRecord
)
458 : SSDestroyedAction
<SSDestroyedProjectAction
> (pRecord
, "$")
462 class SSDestroyedFileAction
: public SSDestroyedAction
<SSDestroyedFileAction
>
465 SSDestroyedFileAction (SSRecordPtr pRecord
)
466 : SSDestroyedAction
<SSDestroyedFileAction
> (pRecord
, "")
471 //---------------------------------------------------------------------------
473 template <class ACTION
>
474 class SSRenamedAction
: public SSItemAction
<ACTION
, RENAMED_ACTION
>
477 SSRenamedAction (SSRecordPtr pRecord
, std::string prefix
);
479 std::string
GetNewName () const { SSName
name (SSItemAction
<ACTION
,RENAMED_ACTION
>::m_Action
.newName
); return name
.GetFullName (); }
480 SSName
GetNewSSName () const { return SSItemAction
<ACTION
,RENAMED_ACTION
>::m_Action
.newName
; }
482 virtual std::string
FormatActionString ();
484 virtual void ToXml (XMLNode
* pParent
) const;
485 virtual void Dump (std::ostream
& os
) const;
488 std::string m_Prefix
;
491 class SSRenamedProjectAction
: public SSRenamedAction
<SSRenamedProjectAction
>
494 SSRenamedProjectAction (SSRecordPtr pRecord
)
495 : SSRenamedAction
<SSRenamedProjectAction
> (pRecord
, "$")
499 class SSRenamedFileAction
: public SSRenamedAction
<SSRenamedFileAction
>
502 SSRenamedFileAction (SSRecordPtr pRecord
)
503 : SSRenamedAction
<SSRenamedFileAction
> (pRecord
, "")
507 //---------------------------------------------------------------------------
509 class SSCheckedInAction
: public SSActionEx
<SSCheckedInAction
>
512 SSCheckedInAction ( SSRecordPtr pRecord
);
513 ~SSCheckedInAction ();
515 std::string
GetFileSepc () const { return m_Action
.checkInSpec
; }
516 long GetOffset () const { return m_Action
.offsetFileDelta
; }
517 SSRecordPtr
GetFileDelta () const;
519 virtual std::string
FormatActionString ();
520 virtual bool Accept (ISSActionVisitor
& rVisitor
) { return rVisitor
.Apply (*this); }
522 virtual void ToXml (XMLNode
* pParent
) const;
523 virtual void Dump (std::ostream
& os
) const;
526 CHECKED_IN_ACTION m_Action
;
527 mutable SSRecordPtr m_pFileDelta
;
528 SSFileImpPtr m_FilePtr
;
532 //---------------------------------------------------------------------------
534 class SSSharedAction
: public SSItemAction
<SSSharedAction
, SHARED_FILE_ACTION
>
537 SSSharedAction ( SSRecordPtr pRecord
);
540 std::string
GetSrcPathSpec () const { return m_Action
.srcPathSpec
; }
541 short GetPinnedToVersion () const { return m_Action
.pinnedToVersion
; }
542 short GetSubActionAndVersion () const { return m_Action
.subActionAndVersion
; }
544 short GetUnpinnedVersion () const { return m_Action
.subActionAndVersion
>= 0 ? m_Action
.subActionAndVersion
: 0; }
546 virtual eAction
GetActionID () const
548 if (m_Action
.subActionAndVersion
< 0)
550 else if (m_Action
.subActionAndVersion
== 0)
552 /* else if (m_Action.subActionAndVersion > 0) */
553 return Unpinned_File
;
556 virtual std::string
FormatActionString ();
558 virtual void ToXml (XMLNode
* pParent
) const;
559 virtual void Dump (std::ostream
& os
) const;
563 //---------------------------------------------------------------------------
565 class SSMovedProjectAction
: public SSItemAction
<SSMovedProjectAction
, MOVED_PROJECT_ACTION
>
568 SSMovedProjectAction ( SSRecordPtr pRecord
);
569 ~SSMovedProjectAction ();
571 std::string
GetPathSpec () const { return m_Action
.pathSpec
; }
573 // virtual eAction GetActionID () const
575 // if (m_Action.subActionAndVersion < 0)
576 // return Shared_File;
577 // else if (m_Action.subActionAndVersion == 0)
578 // return Pinned_File;
579 // /* else if (m_Action.subActionAndVersion > 0) */
580 // return Unpinned_File;
583 virtual std::string
FormatActionString ();
585 virtual void ToXml (XMLNode
* pParent
) const;
586 virtual void Dump (std::ostream
& os
) const;
588 #endif // !defined(AFX_SSHISTORYOBJECT_H__58F12C7C_FE74_43B1_9BF6_9E803182D8D7__INCLUDED_)