mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-21 23:48:22 +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();
|
||||
if (report.size()) {
|
||||
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++) {
|
||||
ofs << (const char*)report[i].toLocal8Bit() << std::endl;
|
||||
}
|
||||
@ -160,8 +160,8 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index)
|
||||
UByteArray data = model.header(index);
|
||||
if (!data.isEmpty()) {
|
||||
std::ofstream file;
|
||||
std::string str = std::string((const char*)name) + std::string("_header.bin");
|
||||
file.open(str, std::ios::out | std::ios::binary);
|
||||
UString str = name + UString("_header.bin");
|
||||
file.open((const char*)str, std::ios::out | std::ios::binary);
|
||||
file.write(data.constData(), data.size());
|
||||
file.close();
|
||||
}
|
||||
@ -170,8 +170,8 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index)
|
||||
data = model.body(index);
|
||||
if (!data.isEmpty()) {
|
||||
std::ofstream file;
|
||||
std::string str = std::string((const char*)name) + std::string("_body.bin");
|
||||
file.open(str, std::ios::out | std::ios::binary);
|
||||
UString str = name + UString("_body.bin");
|
||||
file.open((const char*)str, std::ios::out | std::ios::binary);
|
||||
file.write(data.constData(), data.size());
|
||||
file.close();
|
||||
}
|
||||
@ -184,8 +184,8 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index)
|
||||
info += model.info(index) + "\n";
|
||||
|
||||
std::ofstream file;
|
||||
std::string str = std::string((const char*)name) + std::string("_info.txt");
|
||||
file.open(str, std::ios::out);
|
||||
UString str = name + UString("_info.txt");
|
||||
file.open((const char*)str, std::ios::out);
|
||||
file.write((const char*)info, info.length());
|
||||
file.close();
|
||||
|
||||
|
@ -45,8 +45,8 @@ TreeItem::~TreeItem() {
|
||||
|
||||
UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem)
|
||||
{
|
||||
std::list<TreeItem*>::iterator found = std::find(std::begin(childItems), std::end(childItems), item);
|
||||
if (found == std::end(childItems))
|
||||
std::list<TreeItem*>::iterator found = std::find(childItems.begin(), childItems.end(), item);
|
||||
if (found == childItems.end())
|
||||
return U_ITEM_NOT_FOUND;
|
||||
childItems.insert(found, newItem);
|
||||
return U_SUCCESS;
|
||||
@ -54,8 +54,8 @@ UINT8 TreeItem::insertChildBefore(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);
|
||||
if (found == std::end(childItems))
|
||||
std::list<TreeItem*>::iterator found = std::find(childItems.begin(), childItems.end(), item);
|
||||
if (found == childItems.end())
|
||||
return U_ITEM_NOT_FOUND;
|
||||
childItems.insert(++found, newItem);
|
||||
return U_SUCCESS;
|
||||
@ -83,7 +83,7 @@ UString TreeItem::data(int column) const
|
||||
int TreeItem::row() const
|
||||
{
|
||||
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) {
|
||||
if (const_cast<TreeItem*>(this) == *iter)
|
||||
return i;
|
||||
|
@ -15,11 +15,22 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#define TREEITEM_H
|
||||
|
||||
#include <list>
|
||||
#include <iterator>
|
||||
|
||||
#include "ubytearray.h"
|
||||
#include "ustring.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
|
||||
{
|
||||
public:
|
||||
@ -36,7 +47,7 @@ public:
|
||||
UINT8 insertChildAfter(TreeItem *item, TreeItem *newItem); // Non-trivial implementation in CPP file
|
||||
|
||||
// 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 columnCount() const { return 5; }
|
||||
UString data(int column) const; // Non-trivial implementation in CPP file
|
||||
|
@ -36,13 +36,13 @@ public:
|
||||
|
||||
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* constData() const { return d.c_str(); }
|
||||
void clear() { d.clear(); }
|
||||
|
||||
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 operator[](uint32_t i) const { 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; }
|
||||
inline void swap(UByteArray &other) { std::swap(d, other.d); }
|
||||
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++) {
|
||||
uint8_t low = d[i] & 0x0F;
|
||||
uint8_t high = (d[i] & 0xF0) >> 4;
|
||||
|
Loading…
Reference in New Issue
Block a user