mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-22 16:08:23 +08:00
Freeing from C++11-only features
This commit is contained in:
parent
f3a6aba4c4
commit
4745d61905
@ -96,7 +96,7 @@ USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, cons
|
|||||||
std::vector<UString> report = ffsReport.generate();
|
std::vector<UString> report = ffsReport.generate();
|
||||||
if (report.size()) {
|
if (report.size()) {
|
||||||
std::ofstream ofs;
|
std::ofstream ofs;
|
||||||
ofs.open(reportPath, std::ofstream::out);
|
ofs.open((const char*)reportPath, std::ofstream::out);
|
||||||
for (size_t i = 0; i < report.size(); i++) {
|
for (size_t i = 0; i < report.size(); i++) {
|
||||||
ofs << (const char*)report[i].toLocal8Bit() << std::endl;
|
ofs << (const char*)report[i].toLocal8Bit() << std::endl;
|
||||||
}
|
}
|
||||||
@ -160,8 +160,8 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index)
|
|||||||
UByteArray data = model.header(index);
|
UByteArray data = model.header(index);
|
||||||
if (!data.isEmpty()) {
|
if (!data.isEmpty()) {
|
||||||
std::ofstream file;
|
std::ofstream file;
|
||||||
std::string str = std::string((const char*)name) + std::string("_header.bin");
|
UString str = name + UString("_header.bin");
|
||||||
file.open(str, std::ios::out | std::ios::binary);
|
file.open((const char*)str, std::ios::out | std::ios::binary);
|
||||||
file.write(data.constData(), data.size());
|
file.write(data.constData(), data.size());
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@ -170,8 +170,8 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index)
|
|||||||
data = model.body(index);
|
data = model.body(index);
|
||||||
if (!data.isEmpty()) {
|
if (!data.isEmpty()) {
|
||||||
std::ofstream file;
|
std::ofstream file;
|
||||||
std::string str = std::string((const char*)name) + std::string("_body.bin");
|
UString str = name + UString("_body.bin");
|
||||||
file.open(str, std::ios::out | std::ios::binary);
|
file.open((const char*)str, std::ios::out | std::ios::binary);
|
||||||
file.write(data.constData(), data.size());
|
file.write(data.constData(), data.size());
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@ -184,8 +184,8 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index)
|
|||||||
info += model.info(index) + "\n";
|
info += model.info(index) + "\n";
|
||||||
|
|
||||||
std::ofstream file;
|
std::ofstream file;
|
||||||
std::string str = std::string((const char*)name) + std::string("_info.txt");
|
UString str = name + UString("_info.txt");
|
||||||
file.open(str, std::ios::out);
|
file.open((const char*)str, std::ios::out);
|
||||||
file.write((const char*)info, info.length());
|
file.write((const char*)info, info.length());
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ TreeItem::~TreeItem() {
|
|||||||
|
|
||||||
UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem)
|
UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem)
|
||||||
{
|
{
|
||||||
std::list<TreeItem*>::iterator found = std::find(std::begin(childItems), std::end(childItems), item);
|
std::list<TreeItem*>::iterator found = std::find(childItems.begin(), childItems.end(), item);
|
||||||
if (found == std::end(childItems))
|
if (found == childItems.end())
|
||||||
return U_ITEM_NOT_FOUND;
|
return U_ITEM_NOT_FOUND;
|
||||||
childItems.insert(found, newItem);
|
childItems.insert(found, newItem);
|
||||||
return U_SUCCESS;
|
return U_SUCCESS;
|
||||||
@ -54,8 +54,8 @@ UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem)
|
|||||||
|
|
||||||
UINT8 TreeItem::insertChildAfter(TreeItem *item, TreeItem *newItem)
|
UINT8 TreeItem::insertChildAfter(TreeItem *item, TreeItem *newItem)
|
||||||
{
|
{
|
||||||
std::list<TreeItem*>::iterator found = std::find(std::begin(childItems), std::end(childItems), item);
|
std::list<TreeItem*>::iterator found = std::find(childItems.begin(), childItems.end(), item);
|
||||||
if (found == std::end(childItems))
|
if (found == childItems.end())
|
||||||
return U_ITEM_NOT_FOUND;
|
return U_ITEM_NOT_FOUND;
|
||||||
childItems.insert(++found, newItem);
|
childItems.insert(++found, newItem);
|
||||||
return U_SUCCESS;
|
return U_SUCCESS;
|
||||||
@ -83,7 +83,7 @@ UString TreeItem::data(int column) const
|
|||||||
int TreeItem::row() const
|
int TreeItem::row() const
|
||||||
{
|
{
|
||||||
if (parentItem) {
|
if (parentItem) {
|
||||||
std::list<TreeItem*>::const_iterator iter = parentItem->childItems.cbegin();
|
std::list<TreeItem*>::const_iterator iter = parentItem->childItems.begin();
|
||||||
for (int i = 0; i < (int)parentItem->childItems.size(); ++i, ++iter) {
|
for (int i = 0; i < (int)parentItem->childItems.size(); ++i, ++iter) {
|
||||||
if (const_cast<TreeItem*>(this) == *iter)
|
if (const_cast<TreeItem*>(this) == *iter)
|
||||||
return i;
|
return i;
|
||||||
|
@ -15,11 +15,22 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
#define TREEITEM_H
|
#define TREEITEM_H
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
#include "ubytearray.h"
|
#include "ubytearray.h"
|
||||||
#include "ustring.h"
|
#include "ustring.h"
|
||||||
#include "basetypes.h"
|
#include "basetypes.h"
|
||||||
|
|
||||||
|
template <typename ForwardIt>
|
||||||
|
ForwardIt u_std_next(
|
||||||
|
ForwardIt it,
|
||||||
|
typename std::iterator_traits<ForwardIt>::difference_type n = 1
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::advance(it, n);
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
|
||||||
class TreeItem
|
class TreeItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -36,7 +47,7 @@ public:
|
|||||||
UINT8 insertChildAfter(TreeItem *item, TreeItem *newItem); // Non-trivial implementation in CPP file
|
UINT8 insertChildAfter(TreeItem *item, TreeItem *newItem); // Non-trivial implementation in CPP file
|
||||||
|
|
||||||
// Model support operations
|
// Model support operations
|
||||||
TreeItem *child(int row) { return *std::next(childItems.begin(), row); }
|
TreeItem *child(int row) { return *u_std_next(childItems.begin(), row); }
|
||||||
int childCount() const {return childItems.size(); }
|
int childCount() const {return childItems.size(); }
|
||||||
int columnCount() const { return 5; }
|
int columnCount() const { return 5; }
|
||||||
UString data(int column) const; // Non-trivial implementation in CPP file
|
UString data(int column) const; // Non-trivial implementation in CPP file
|
||||||
|
@ -36,13 +36,13 @@ public:
|
|||||||
|
|
||||||
bool isEmpty() const { return d.length() == 0; }
|
bool isEmpty() const { return d.length() == 0; }
|
||||||
|
|
||||||
char* data() { return &(d.front()); /* Feels dirty, but works for all basic_string implementations I know, is fully OK in C++11 and later*/ }
|
char* data() { return d.length() == 0 ? NULL : &(d.at(0)); /* Feels dirty, but works for all basic_string implementations I know, is fully OK in C++11 and later*/ }
|
||||||
const char* data() const { return d.c_str(); }
|
const char* data() const { return d.c_str(); }
|
||||||
const char* constData() const { return d.c_str(); }
|
const char* constData() const { return d.c_str(); }
|
||||||
void clear() { d.clear(); }
|
void clear() { d.clear(); }
|
||||||
|
|
||||||
int32_t size() const { return d.size(); }
|
int32_t size() const { return d.size(); }
|
||||||
int32_t count(char ch) const { return std::count(d.cbegin(), d.cend(), ch); }
|
int32_t count(char ch) const { return std::count(d.begin(), d.end(), ch); }
|
||||||
char at(uint32_t i) const { return d.at(i); }
|
char at(uint32_t i) const { return d.at(i); }
|
||||||
char operator[](uint32_t i) const { return d[i]; }
|
char operator[](uint32_t i) const { return d[i]; }
|
||||||
char& operator[](uint32_t i) { return d[i]; }
|
char& operator[](uint32_t i) { return d[i]; }
|
||||||
@ -61,7 +61,7 @@ public:
|
|||||||
bool operator!= (const UByteArray & ba) const { return d != ba.d; }
|
bool operator!= (const UByteArray & ba) const { return d != ba.d; }
|
||||||
inline void swap(UByteArray &other) { std::swap(d, other.d); }
|
inline void swap(UByteArray &other) { std::swap(d, other.d); }
|
||||||
UByteArray toHex() {
|
UByteArray toHex() {
|
||||||
std::basic_string<char> hex(size() * 2, '\x00');
|
std::basic_string<char> hex(size() * 2, '\x00');
|
||||||
for (int32_t i = 0; i < size(); i++) {
|
for (int32_t i = 0; i < size(); i++) {
|
||||||
uint8_t low = d[i] & 0x0F;
|
uint8_t low = d[i] & 0x0F;
|
||||||
uint8_t high = (d[i] & 0xF0) >> 4;
|
uint8_t high = (d[i] & 0xF0) >> 4;
|
||||||
|
Loading…
Reference in New Issue
Block a user