Skip to content

Commit bb0591e

Browse files
committed
pofParser: removed getMemSection. Simplify getData/getLength logic. Improved displayHeader format
1 parent 48da801 commit bb0591e

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

src/pofParser.cpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,35 @@ POFParser::POFParser(const std::string &filename, bool verbose):
2828
POFParser::~POFParser()
2929
{}
3030

31-
int POFParser::getMemSection(const std::string &name)
32-
{
33-
int i = 0;
34-
for (auto it = mem_section.begin(); it != mem_section.end(); it++, i++) {
35-
if ((*it).first == name)
36-
return i;
37-
}
38-
return -1;
39-
}
40-
4131
uint8_t *POFParser::getData(const std::string &section_name)
4232
{
4333
if (section_name == "")
4434
return (uint8_t*)_bit_data.data();
45-
int idx = getMemSection(section_name);
46-
if (idx != -1)
47-
return mem_section[section_name].data;
48-
else
35+
auto section = mem_section.find(section_name);
36+
if (section == mem_section.end())
4937
return NULL;
38+
return (*section).second.data;
5039
}
5140

5241
int POFParser::getLength(const std::string &section_name)
5342
{
5443
if (section_name == "")
5544
return _bit_length;
56-
int idx = getMemSection(section_name);
57-
if (idx != -1)
58-
return mem_section[section_name].len;
59-
else
45+
auto section = mem_section.find(section_name);
46+
if (section == mem_section.end())
6047
return -1;
48+
return (*section).second.len;
6149
}
6250

6351
void POFParser::displayHeader()
6452
{
6553
ConfigBitstreamParser::displayHeader();
54+
char mess[1024];
55+
snprintf(mess, 1024, "Flag section offset len end");
56+
printInfo(mess);
6657
for (auto it = mem_section.begin(); it != mem_section.end(); it++) {
6758
memory_section_t v = (*it).second;
68-
char mess[1024];
69-
snprintf(mess, 1024, "%02x %4s: ", v.flag, v.section.c_str());
59+
snprintf(mess, 1024, "%02x %4s: ", v.flag, v.section.c_str());
7060
printInfo(mess, false);
7161
// start address + len (in bits) + end addr
7262
snprintf(mess, 1024, " %08x %08x %08x", v.offset, v.len, v.offset + ((v.len/8)-1));
@@ -111,9 +101,9 @@ int POFParser::parse()
111101
/* update pointers to memory area */
112102
ptr = (uint8_t *)_bit_data.data();
113103
mem_section["CFM0"].data = &ptr[mem_section["CFM0"].offset + 0x0C];
114-
if (getMemSection("CFM1") != -1)
104+
if (mem_section.find("CFM1") != mem_section.end())
115105
mem_section["CFM1"].data = &ptr[mem_section["CFM1"].offset + 0x0C];
116-
if (getMemSection("CFM2") != -1)
106+
if (mem_section.find("CFM2") != mem_section.end())
117107
mem_section["CFM2"].data = &ptr[mem_section["CFM2"].offset + 0x0C];
118108
mem_section["UFM"].data = &ptr[mem_section["UFM"].offset + 0x0C];
119109
mem_section["ICB"].data = &ptr[mem_section["ICB"].offset + 0x0C];

src/pofParser.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ class POFParser: public ConfigBitstreamParser {
5757

5858

5959
private:
60-
/* \brief return index for a section called name
61-
* \return -1 when section not present, index otherwise
62-
*/
63-
int getMemSection(const std::string &name);
64-
6560
/* packet 0x1A content */
6661
typedef struct {
6762
uint8_t flag; // 1 Byte before section name

0 commit comments

Comments
 (0)