Skip to content

Commit

Permalink
less string
Browse files Browse the repository at this point in the history
  • Loading branch information
grencez committed Dec 14, 2023
1 parent 294e7a2 commit 0cf5204
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 86 deletions.
83 changes: 9 additions & 74 deletions src/cx/alphatab.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,31 @@
**/
#ifndef AlphaTab_HH_
#define AlphaTab_HH_
#include <cstring>
#include <string>

#include <fildesh/fildesh.h>

namespace Cx {

class AlphaTab
class AlphaTab : public std::string
{
private:
DECLARE_DEFAULT_FildeshAT(char, t_);

public:
const char* data() const {return *t_;}
size_t size() const {return count_of_FildeshAT(t_);}
bool empty() const {return (this->size() == 0);}
operator std::string_view() const {
if (this->empty()) {return std::string_view("", 0);}
return std::string_view(this->data(), this->size());
}

AlphaTab& operator=(std::string_view b) {
resize_FildeshAT(t_, b.size());
if (!b.empty()) {
memcpy(*t_, b.data(), b.size());
}
this->assign(b);
return *this;
}
AlphaTab& operator=(const AlphaTab& b) {
return (*this = (std::string_view)b);
}
AlphaTab& operator=(const std::string& b) {
return (*this = (std::string_view)b);
}
AlphaTab& operator=(const char* b) {
return (*this = std::string_view(b));
}
AlphaTab& operator=(const AlphaTab& b) {return *this = (std::string_view)b;}
AlphaTab& operator=(const std::string& b) {return *this = (std::string_view)b;}
AlphaTab& operator=(const char* b) {return *this = std::string_view(b);}

AlphaTab() {}
AlphaTab(const AlphaTab& b) {*this = (std::string_view)b;}
AlphaTab(const std::string& b) {*this = (std::string_view)b;}
AlphaTab(const char* b) {*this = std::string_view(b);}
~AlphaTab() {close_FildeshAT(t_);}

void clear() {
clear_FildeshAT(t_);
}

AlphaTab& operator+=(std::string_view s) {
if (!s.empty()) {
memcpy(grow_FildeshAT(t_, s.size()), s.data(), s.size());
}
return *this;
}
AlphaTab& operator+=(char c) {
return (*this += std::string_view(&c, 1));
}
AlphaTab operator+(std::string_view s) const {
return (AlphaTab(*this) += s);
}

bool operator==(std::string_view b) const {
return ((std::string_view)*this == b);
}
bool operator!=(std::string_view b) const {
return ((std::string_view)*this != b);
}
bool operator<(std::string_view b) const {
return ((std::string_view)*this < b);
}

const char* c_str() {
*this += '\0';
mpop_FildeshAT(t_, 1);
return *t_;
}
AlphaTab(const AlphaTab& b) : std::string(b.data(), b.size()) {}
AlphaTab(const std::string& b) : std::string(b) {}
AlphaTab(const char* b) : std::string(b) {}
virtual ~AlphaTab() {}
};

inline
std::ostream& operator<<(ostream& out, const AlphaTab& a) {
return (out << (std::string_view)a);
}

}
namespace protocon {
#if 1
typedef ::Cx::AlphaTab String;
#else
typedef std::string String;
#endif
}

#endif
Expand Down
12 changes: 0 additions & 12 deletions src/cx/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ struct ConstTable
bitint alloc_lgsz; \
}

#define DeclTableT_MemLoc
DeclTableT( MemLoc, void* );
#define DeclTableT_byte
DeclTableT( byte, byte );
#define DeclTableT_char
Expand Down Expand Up @@ -449,16 +447,6 @@ clear_Table (Table* a)
{ mpop_Table (a, a->sz); }
#define ClearTable( a ) MPopTable( a, (a).sz )

qual_inline
void
flush_Table (Table* a)
{
a->sz = 0;
}
#define FlushTable( a ) do \
{ \
(a).sz = 0; \
} while (0)
#endif /* #ifndef __OPENCL_VERSION__ */

qual_inline
Expand Down

0 comments on commit 0cf5204

Please sign in to comment.