Skip to content

Commit

Permalink
Small pending code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
aslze committed Nov 12, 2022
1 parent ea214f6 commit 9cd21ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
9 changes: 7 additions & 2 deletions include/asl/StreamBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class ASL_API StreamBufferReader
/**
Skips a number of bytes
*/
void skip(int n) { _ptr += n; }
StreamBufferReader& skip(int n)
{
_ptr += n;
return *this;
}

template <class T>
StreamBufferReader& read2(T& x)
Expand Down Expand Up @@ -176,6 +180,7 @@ class ASL_API StreamBufferReader
Endian _endian;
};

typedef StreamBufferReader BufferReader;

/**
This class is a buffer that can be written to as a binary stream. The buffer is initially
Expand All @@ -198,7 +203,7 @@ socket << *buffer;
class StreamBuffer : public Array<byte>
{
public:
StreamBuffer(Endian e = ENDIAN_LITTLE) : _endian(e) {}
ASL_EXPLICIT StreamBuffer(Endian e = ENDIAN_LITTLE) : _endian(e) {}

Array<byte>& operator*() { return (Array<byte>&)*this; }
const Array<byte>& operator*() const { return (const Array<byte>&)*this; }
Expand Down
2 changes: 1 addition & 1 deletion include/asl/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ String euros = "3€";
euros.length() // returns 4 (bytes)
euros.count() // returns 2 (characters)
euros.chars() // returns the array [51, 8364] (the codes of '3' and '€')
foreach(int c, euros)
for(int c : euros)
printf("%i ", c); // prints "51 8364"
~~~
Expand Down
18 changes: 9 additions & 9 deletions include/asl/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ class Thread
#ifdef _WIN32
#define ASL_THREADFUNC_API __stdcall
#define ASL_THREADFUNC_RET unsigned int
typedef unsigned(__stdcall *Function)(void*);
typedef HANDLE Handle;
typedef unsigned(__stdcall *Function_)(void*);
typedef HANDLE Handle_;
#else
#define ASL_THREADFUNC_API
#define ASL_THREADFUNC_RET void*
typedef void* (*Function)(void*);
typedef pthread_t Handle;
typedef void* (*Function_)(void*);
typedef pthread_t Handle_;
#endif
Handle _thread;
Handle_ _thread;
volatile bool _threadFinished;
private:
template<class F>
Expand All @@ -116,7 +116,7 @@ class Thread
int i0, i1, s;
};

void run(Function f, void* arg)
void run(Function_ f, void* arg)
{
#ifdef _WIN32
if (_thread != 0)
Expand All @@ -134,7 +134,7 @@ class Thread
ASL_BAD_ALLOC();
}
}
void run(Function f, ThreadAttrib& a , void* arg=0)
void run(Function_ f, ThreadAttrib& a , void* arg=0)
{
int n;
if((n = pthread_create(&_thread, *a, f, arg)))
Expand Down Expand Up @@ -259,7 +259,7 @@ class Thread
static Thread start(const Func& f, Thread* t)
{
Context<Func> s = { f, t, false, 0, 0, 0 };
t->run((Function)Thread::beginf<Func>, (void*)&s);
t->run((Function_)Thread::beginf<Func>, (void*)&s);
while (!s.ready) {}
return *t;
}
Expand Down Expand Up @@ -292,7 +292,7 @@ class Thread
{
threads << new Thread;
Context<F> s = { f, threads.last(), false, i0 + i, i1, n };
threads.last()->run((Function)Thread::beginfN<F>, (void*)&s);
threads.last()->run((Function_)Thread::beginfN<F>, (void*)&s);
while (!s.ready) {}
}
foreach(Thread* t, threads)
Expand Down
1 change: 1 addition & 0 deletions include/asl/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ inline void asl_construct_copy(T* p, const T& x) {*p = x;} \
inline void bswap(T& a, T& b) {swap(a, b);}

ASL_POD_CONSTRUCT(byte)
ASL_POD_CONSTRUCT(signed char)
ASL_POD_CONSTRUCT(char)
ASL_POD_CONSTRUCT(int)
ASL_POD_CONSTRUCT(unsigned int)
Expand Down

0 comments on commit 9cd21ba

Please sign in to comment.