KDIS  2-8-x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DIS_Logger_Playback.h
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 For Further Information Please Contact me at
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
29 
30 /********************************************************************
31  class: DIS_Logger_Playback
32  created: 2008/12/06
33  author: Karl Jones
34 
35  purpose: This class will allow you to play back data recorded using
36  DIS_Logger_Record.
37 *********************************************************************/
38 
39 #pragma once
40 
41 #include <fstream>
42 #include <time.h>
43 #include "./../PDU/Header.h"
44 #include <queue>
45 
46 namespace KDIS {
47 namespace UTILS {
48 
50 {
51 protected:
52 
53  struct Log
54  {
56 
58  };
59 
60  std::fstream m_File;
61 
63 
64  std::queue<Log> m_qLog;
65 
66  //************************************
67  // FullName: KDIS::UTILS::DIS_Logger_Playback::loadFromFile
68  //!Description: Load data from file
69  //************************************
70  void loadFromFile() throw( KException );
71 
72 public:
73 
74  // BufferSz - how many lines of the log to load into memory at a time,
75  // set to 0 to load all data.
76  DIS_Logger_Playback( const KString & FileName, KUINT16 BufferSz );
77 
79 
80  //************************************
81  // FullName: KDIS::UTILS::DIS_Logger_Playback::Record
82  //!Description: Returns the next item in the log.
83  //! If the end of the log has been reached returns false.
84  // Parameter: Type & Stamp
85  // Parameter: KDataStream & Stream
86  //************************************
87  template<class Type>
88  KBOOL GetNext( Type & Stamp, KDataStream & stream ) throw( KException );
89 
90  //************************************
91  // FullName: KDIS::UTILS::DIS_Logger_Playback::EndOfLogReached
92  //!Description: Returns true if the end of the logged data has
93  //! reached.
94  //************************************
95  KBOOL EndOfLogReached() const;
96 };
97 
98 //////////////////////////////////////////////////////////////////////////
99 // Template Operators
100 //////////////////////////////////////////////////////////////////////////
101 
102 template<class Type>
103 KBOOL DIS_Logger_Playback::GetNext( Type & Stamp, KDataStream & Stream ) throw( KException )
104 {
105  if( EndOfLogReached() )return false;
106 
107  if( m_qLog.size() == 0 )loadFromFile();
108 
109  KStringStream ssStamp( m_qLog.front().sStamp );
110  ssStamp >> Stamp;
111 
112  Stream.ReadFromString( m_qLog.front().sData );
113 
114  m_qLog.pop();
115 
116  return true;
117 }
118 
119 //////////////////////////////////////////////////////////////////////////
120 
121 } // END namespace UTILS
122 } // END namespace KDIS
123 
Definition: DIS_Logger_Playback.h:49
std::fstream m_File
Definition: DIS_Logger_Playback.h:60
unsigned short int KUINT16
Definition: KDefines.h:101
Definition: KDefines.h:182
Definition: KDataStream.h:48
bool KBOOL
Definition: KDefines.h:119
std::string KString
Definition: KDefines.h:116
KString sStamp
Definition: DIS_Logger_Playback.h:55
std::stringstream KStringStream
Definition: KDefines.h:117
KUINT16 m_ui16PreLoadLines
Definition: DIS_Logger_Playback.h:62
KString sData
Definition: DIS_Logger_Playback.h:57
std::queue< Log > m_qLog
Definition: DIS_Logger_Playback.h:64
#define KDIS_EXPORT
Definition: KDefines.h:82
Definition: DIS_Logger_Playback.h:53