1 /*
2    Copyright (c) 2003, 2021, Oracle and/or its affiliates.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef SECTION_READER_HPP
26 #define SECTION_READER_HPP
27 
28 #include <ndb_types.h>
29 
30 #define JAM_FILE_ID 219
31 
32 
33 class SectionReader {
34 public:
35   SectionReader(struct SegmentedSectionPtr &,
36 		class SectionSegmentPool &);
37   SectionReader(Uint32 firstSectionIVal,
38                 class SectionSegmentPool &);
39 
40   /* reset : Set SectionReader to start of section */
41   void reset();
42   /* step : Step over given number of words */
43   bool step(Uint32 len);
44   /* getWord : Copy one word to dst + move forward */
45   bool getWord(Uint32 * dst);
46   /* peekWord : Copy one word to dst */
47   bool peekWord(Uint32 * dst) const ;
48   /* peekWords : Copy len words to dst */
49   bool peekWords(Uint32 * dst, Uint32 len) const;
50   /* getSize : Get total size of section */
51   Uint32 getSize() const;
52   /* getWords : Copy len words to dst + move forward */
53   bool getWords(Uint32 * dst, Uint32 len);
54 
55   /* getWordsPtr : Get const ptr to next contiguous
56    *               block of words
57    * In success case will return at least 1 word
58    */
59   bool getWordsPtr(const Uint32*& readPtr,
60                    Uint32& actualLen);
61   /* getWordsPtr : Get const ptr to at most maxLen words
62    * In success case will return at least 1 word
63    */
64   bool getWordsPtr(Uint32 maxLen,
65                    const Uint32*& readPtr,
66                    Uint32& actualLen);
67 
68   /* PosInfo
69    * Structure for efficiently saving/restoring a SectionReader
70    * to a position
71    * Must be treated as opaque and never 'mippled' with!
72    */
73   struct PosInfo
74   {
75     Uint32 currPos;
76     Uint32 currIVal;
77   };
78 
79   PosInfo getPos();
80   bool setPos(PosInfo posinfo);
81 
82   /**
83    * Update word at current position to <em>value</em>
84    */
85   bool updateWord(Uint32 value) const ;
86 
87 private:
88   Uint32 m_pos;
89   Uint32 m_len;
90   class SectionSegmentPool & m_pool;
91   Uint32 m_headI;
92   struct SectionSegment * m_head;
93   Uint32 m_currI;
94   struct SectionSegment * m_currentSegment;
95 
96   bool segmentContainsPos(PosInfo posInfo);
97 };
98 
99 inline
getSize() const100 Uint32 SectionReader::getSize() const
101 {
102   return m_len;
103 }
104 
105 
106 #undef JAM_FILE_ID
107 
108 #endif
109