summaryrefslogtreecommitdiff
path: root/src/ToolBox/superpmi/superpmi-shared/methodcontextiterator.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ToolBox/superpmi/superpmi-shared/methodcontextiterator.h')
-rw-r--r--src/ToolBox/superpmi/superpmi-shared/methodcontextiterator.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/ToolBox/superpmi/superpmi-shared/methodcontextiterator.h b/src/ToolBox/superpmi/superpmi-shared/methodcontextiterator.h
new file mode 100644
index 0000000000..d6002ba852
--- /dev/null
+++ b/src/ToolBox/superpmi/superpmi-shared/methodcontextiterator.h
@@ -0,0 +1,104 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+#include "simpletimer.h"
+
+// Class to implement method context hive reading and iterating.
+
+class MethodContextIterator
+{
+public:
+
+ MethodContextIterator(bool progressReport = false)
+ : m_hFile(INVALID_HANDLE_VALUE)
+ , m_fileSize(0)
+ , m_methodContextNumber(0)
+ , m_mc(nullptr)
+ , m_indexCount(-1)
+ , m_index(0)
+ , m_indexes(nullptr)
+ , m_progressReport(progressReport)
+ , m_timer(nullptr)
+ {
+ if (m_progressReport)
+ {
+ m_timer = new SimpleTimer();
+ }
+ }
+
+ MethodContextIterator(const int indexCount, const int* indexes, bool progressReport = false)
+ : m_hFile(INVALID_HANDLE_VALUE)
+ , m_fileSize(0)
+ , m_methodContextNumber(0)
+ , m_mc(nullptr)
+ , m_indexCount(indexCount)
+ , m_index(0)
+ , m_indexes(indexes)
+ , m_progressReport(progressReport)
+ , m_timer(nullptr)
+ {
+ if (m_progressReport)
+ {
+ m_timer = new SimpleTimer();
+ }
+ }
+
+ ~MethodContextIterator()
+ {
+ Destroy();
+ }
+
+ bool Initialize(const char* fileName);
+
+ bool Destroy();
+
+ bool MoveNext();
+
+ // The iterator class owns the memory returned by Current(); the caller should not delete it.
+ MethodContext* Current()
+ {
+ return m_mc;
+ }
+
+ // In this case, we are giving ownership of the MethodContext* to the caller. So, null out m_mc
+ // before we return, so we don't attempt to delete it in this class.
+ MethodContext* CurrentTakeOwnership()
+ {
+ MethodContext* ret = m_mc;
+ m_mc = nullptr;
+ return ret;
+ }
+
+ // Return the file position offset of the current method context.
+ __int64 CurrentPos()
+ {
+ return m_pos.QuadPart;
+ }
+
+ int MethodContextNumber()
+ {
+ return m_methodContextNumber;
+ }
+
+private:
+
+ HANDLE m_hFile;
+ int64_t m_fileSize;
+ int m_methodContextNumber;
+ MethodContext* m_mc;
+ LARGE_INTEGER m_pos;
+
+ // If m_indexCount==-1, use all method contexts. Otherwise, m_indexCount is the number of elements in the
+ // m_indexes array, which contains a sorted set of method context indexes to return. In this case, m_index
+ // is the index of the current element in m_indexes.
+ const int m_indexCount;
+ int m_index;
+ const int* m_indexes;
+
+ // Should we log a progress report as we are loading the method contexts?
+ // The timer is only used when m_progressReport==true.
+ bool m_progressReport;
+ SimpleTimer* m_timer;
+}; \ No newline at end of file