mirror of
https://github.com/LongSoft/UEFITool.git
synced 2025-05-25 12:34:54 -04:00
LessQt, part 1
- added wrappers over Qt classes for seamless replacement if Qt is not available - added bstrlib as submodule - only UEFIExtract works with this changes for now, others will followa bit later
This commit is contained in:
parent
71ce2a07b2
commit
bf8632c063
32 changed files with 2891 additions and 2774 deletions
67
common/ubytearray.h
Normal file
67
common/ubytearray.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
/* ubytearray.h
|
||||
|
||||
Copyright (c) 2016, Nikolaj Schlej. All rights reserved.
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
*/
|
||||
|
||||
#ifndef UBYTEARRAY_H
|
||||
#define UBYTEARRAY_H
|
||||
|
||||
#ifdef QT_CORE_LIB
|
||||
// Use Qt class, if Qt is available
|
||||
#include <QByteArray>
|
||||
#define UByteArray QByteArray
|
||||
#else
|
||||
// Use own implementation
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class UByteArray
|
||||
{
|
||||
public:
|
||||
UByteArray() : d() {}
|
||||
UByteArray(const UByteArray & ba) : d(ba.d) {}
|
||||
UByteArray(const std::basic_string<char> & bs) : d(bs) {}
|
||||
UByteArray(const std::vector<char> & bc) : d(bc.data(), bc.size()) {}
|
||||
UByteArray(const char* bytes, int32_t size) : d(bytes, size) {}
|
||||
~UByteArray() {}
|
||||
|
||||
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*/ }
|
||||
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); }
|
||||
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]; }
|
||||
|
||||
bool startsWith(const UByteArray & ba) const { return 0 == d.find(ba.d, 0); }
|
||||
int indexOf(const UByteArray & ba, int from = 0) const { return d.find(ba.d, from); }
|
||||
int lastIndexOf(const UByteArray & ba, int from = 0) const { return d.rfind(ba.d, from); }
|
||||
|
||||
UByteArray left(int32_t len) const { return d.substr(0, len); }
|
||||
UByteArray right(int32_t len) const { return d.substr(d.size() - 1 - len, len); };
|
||||
UByteArray mid(int32_t pos, int32_t len = -1) const { return d.substr(pos, len); };
|
||||
|
||||
UByteArray &operator=(const UByteArray & ba) { d = ba.d; return *this; }
|
||||
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); }
|
||||
|
||||
private:
|
||||
std::basic_string<char> d;
|
||||
};
|
||||
|
||||
#endif // QT_CORE_LIB
|
||||
#endif // UBYTEARRAY_H
|
Loading…
Add table
Add a link
Reference in a new issue