Skip to content

Commit

Permalink
Fixed StreamBuffer read 64bit little endian, use ByteArray name, Matr…
Browse files Browse the repository at this point in the history
…ix4 moved functions to class body
  • Loading branch information
aslze committed Mar 18, 2024
1 parent eca86d8 commit 5ef706e
Show file tree
Hide file tree
Showing 19 changed files with 130 additions and 141 deletions.
6 changes: 3 additions & 3 deletions doc/doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ With CMake 3.14+, instead of using `find_package()`, you can download and build
~~~
include(FetchContent)
FetchContent_Declare(asl URL https://github.com/aslze/asl/archive/1.11.7.zip)
FetchContent_Declare(asl URL https://github.com/aslze/asl/archive/1.11.10.zip)
FetchContent_MakeAvailable(asl)
~~~
Expand Down Expand Up @@ -310,7 +310,7 @@ Map, Dic, Stack, HashMap). These classes are reference-counted, so they
are copied by reference. If a separate copy is required, use the `clone()` method:
~~~
Array<int> a = array(1, 2, 3);
Array<int> a = { 1, 2, 3 };
Array<int> b = a; // b is the same as a
Array<int> c = a.clone(); // c is a separate copy of a
~~~
Expand Down Expand Up @@ -613,7 +613,7 @@ that runs all defined tests. Use the `ASL_TEST_ENABLE()` macro if you will provi
~~~
#include <asl/testing.h>
ASL_TEST_ENABLE_MAIN();
ASL_TEST_ENABLE_MAIN()
ASL_TEST(Car)
{
Expand Down
10 changes: 5 additions & 5 deletions include/asl/Http.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ class ASL_API HttpMessage
/**
Sets the body of the message as a binary blob.
*/
void put(const Array<byte>& data);
void put(const ByteArray& data);
/**
Sets the body of the message as a text string.
*/
void put(const String& body);

void put(const char* body) { put(Array<byte>((const byte*)body, (int)strlen(body))); }
void put(const char* body) { put(ByteArray((const byte*)body, (int)strlen(body))); }
/**
Sets the body of the message as a JSON document.
*/
Expand All @@ -180,7 +180,7 @@ class ASL_API HttpMessage
/**
Returns the binary body of the message.
*/
const Array<byte>& body() const { return _body; }
const ByteArray& body() const { return _body; }
/**
Returns the message body as text
*/
Expand Down Expand Up @@ -224,7 +224,7 @@ class ASL_API HttpMessage
String _command;
String _proto;
Dic<> _headers;
Array<byte> _body;
ByteArray _body;
mutable Socket* _socket;
Function<void, const HttpStatus&> _progress;
Shared<HttpSink> _sink;
Expand All @@ -243,7 +243,7 @@ enum HttpMethod { HTTP_UNKNOWN, HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_
An HTTP request that servers can read from.
An HttpRequest has a method (such as GET or POST), optional headers, and optional body. The body can be a
String, an Array<byte> or a Var. In the case of a Var it will be encoded as JSON and the request content type
String, a ByteArray or a Var. In the case of a Var it will be encoded as JSON and the request content type
header automatically set.
\sa HttpServer
Expand Down
121 changes: 51 additions & 70 deletions include/asl/Matrix4.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,70 @@ class Matrix4_
/**
Returns this matrix plus `B`
*/
Matrix4_ operator+(const Matrix4_& B) const;
Matrix4_ operator+(const Matrix4_& B) const
{
Matrix4_ C;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
C(i, j) = a[i][j] + B(i, j);
return C;
}
/**
Returns this matrix minus `B`
*/
Matrix4_ operator-(const Matrix4_& B) const;
Matrix4_ operator-(const Matrix4_& B) const
{
Matrix4_ C;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
C(i, j) = a[i][j] - B(i, j);
return C;
}
/**
Returns this matrix multiplied by `B`
*/
Matrix4_ operator*(const Matrix4_& B) const;
Matrix4_ operator*(const Matrix4_& B) const
{
Matrix4_ C;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
C(i, j) = a[i][0] * B(0, j) + a[i][1] * B(1, j) + a[i][2] * B(2, j) + a[i][3] * B(3, j);
return C;
}
/**
Multipies this matrix by `B`
*/
Matrix4_& operator*=(const Matrix4_& B)
{
Matrix4_ C;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
C(i, j) = a[i][0] * B(0, j) + a[i][1] * B(1, j) + a[i][2] * B(2, j) + a[i][3] * B(3, j);
*this = C;
return *this;
}
/**
Returns this matrix multipled by scalar `t`
*/
Matrix4_ operator*(T t) const;
Matrix4_ operator*(T t) const
{
Matrix4_ C;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
C(i, j) = t * a[i][j];
return C;
}
friend Matrix4_ operator*(T t, const Matrix4_& m) {return m * t;}
/**
Multiplies this matrix by scalar `t`
*/
Matrix4_& operator*=(T t);
Matrix4_& operator*=(T t)
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
a[i][j] *= t;
return *this;
}
/**
Returns vector `p` left-multiplied by this matrix.
*/
Expand Down Expand Up @@ -294,11 +340,6 @@ class Matrix4_
given as a string, such as "XYZ" or "XYZ*", equivalent to the fromEuler function
*/
Vec3_<T> eulerAngles(const char* a) const;

/**
Multipies this matrix by `B`
*/
Matrix4_& operator*=(const Matrix4_& B);
/**
Returns the inverse of this matrix
*/
Expand Down Expand Up @@ -383,66 +424,6 @@ asl::Matrix4_<T> orthonormalize(const asl::Matrix4_<T>& m)

namespace asl {

template<class T>
Matrix4_<T> Matrix4_<T>::operator+(const Matrix4_<T>& B) const
{
Matrix4_<T> C;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
C(i, j) = a[i][j] + B(i, j);
return C;
}

template<class T>
Matrix4_<T> Matrix4_<T>::operator-(const Matrix4_<T>& B) const
{
Matrix4_<T> C;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
C(i, j) = a[i][j] - B(i, j);
return C;
}

template<class T>
inline Matrix4_<T> Matrix4_<T>::operator*(const Matrix4_<T>& B) const
{
Matrix4_<T> C;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
C(i, j) = a[i][0] * B(0, j) + a[i][1] * B(1, j) + a[i][2] * B(2, j) + a[i][3] * B(3, j);
return C;
}

template<class T>
Matrix4_<T> Matrix4_<T>::operator*(T t) const
{
Matrix4_<T> C;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
C(i, j) = t * a[i][j];
return C;
}

template<class T>
Matrix4_<T>& Matrix4_<T>::operator*=(T t)
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
a[i][j] *= t;
return *this;
}

template<class T>
inline Matrix4_<T>& Matrix4_<T>::operator*=(const Matrix4_<T>& B)
{
Matrix4_<T> C;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
C(i, j) = a[i][0] * B(0, j) + a[i][1] * B(1, j) + a[i][2] * B(2, j) + a[i][3] * B(3, j);
*this = C;
return *this;
}

template<class T>
Matrix4_<T> Matrix4_<T>::identity()
{
Expand Down
4 changes: 4 additions & 0 deletions include/asl/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class ASL_API Path
*/
bool isAbsolute() const;
/**
Returns true if this has a parent directory and is not just a name
*/
bool hasDirectory() const { return name() == _path; }
/**
Removes double dots in a path by stepping up one directory each time.
*/
Path& removeDDots();
Expand Down
2 changes: 1 addition & 1 deletion include/asl/SHA1.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SHA1
SHA1();
static Hash hash(const byte* data, int len);
static Hash hash(const char* data) { return hash((const byte*)data, (int)strlen(data)); }
static Hash hash(const Array<byte>& data);
static Hash hash(const ByteArray& data);
static Hash hash(const String& data);
private:
void transform(const byte buffer[64]);
Expand Down
2 changes: 1 addition & 1 deletion include/asl/SerialPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ASL_API SerialPort
*/
int read(void* p, int n);

Array<byte> read(int n);
ByteArray read(int n);

/**
Writes the given string to the port
Expand Down
6 changes: 3 additions & 3 deletions include/asl/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ASL_API InetAddress
*/
static Array<InetAddress> lookup(const String& name);
protected:
Array<byte> _data;
ByteArray _data;
Type _type;
};

Expand Down Expand Up @@ -128,7 +128,7 @@ ASL_SMART_CLASS(Socket, SmartObject)
virtual int available();
virtual int read(void* data, int size);
virtual int write(const void* data, int n);
Array<byte> read(int n = -1);
ByteArray read(int n = -1);
void skip(int n);
virtual bool waitInput(double timeout = 60);
int error() const { return _error; }
Expand Down Expand Up @@ -236,7 +236,7 @@ class ASL_API Socket : public SmartObject
/**
Reads n bytes and returns them as an array of bytes, or reads all available bytes if no argument is given.
*/
Array<byte> read(int n = -1) { return _()->read(n); }
ByteArray read(int n = -1) { return _()->read(n); }

/**
Skips (reads and discards) the next n bytes from the socket.
Expand Down
Loading

0 comments on commit 5ef706e

Please sign in to comment.