Compare commits

..

No commits in common. "3f592f73e8876dace67dca160eca1c42343f2266" and "449f1c1496b347c26176451fc5892afe484219b7" have entirely different histories.

25 changed files with 166 additions and 3227 deletions

Binary file not shown.

View File

@ -12,13 +12,9 @@ jobs:
- name: Check out repository code - name: Check out repository code
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Generating Documentation
run: |
doxygen ehs-docs-config.doxyfile
- name: Installing Dependencies - name: Installing Dependencies
run: | run: |
sudo pacman -S --noconfirm doxygen zip alsa-lib libxcb xcb-util-cursor sudo pacman -S --noconfirm zip alsa-lib libxcb xcb-util-cursor
- name: Building/Compiling Project - name: Building/Compiling Project
run: | run: |
@ -34,7 +30,7 @@ jobs:
mv libEHS.a lib mv libEHS.a lib
- name: Zipping Binaries - name: Zipping Binaries
run: zip -r ehs-linux-amd64.zip include bin lib docs run: zip -r ehs-linux-amd64.zip include bin lib
- uses: https://github.com/actions/setup-go@v4 - uses: https://github.com/actions/setup-go@v4
with: with:
@ -55,11 +51,7 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Installing Dependencies - name: Installing Dependencies
run: sudo apt install -y doxygen zip libasound2-dev libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev run: sudo apt install -y zip libasound2-dev libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev
- name: Generating Documentation
run: |
doxygen ehs-docs-config.doxyfile
- name: Building/Compiling Project - name: Building/Compiling Project
run: | run: |
@ -75,7 +67,7 @@ jobs:
mv libEHS.a lib mv libEHS.a lib
- name: Zipping Binaries - name: Zipping Binaries
run: zip -r ehs-linux-aarch64.zip include bin lib docs run: zip -r ehs-linux-aarch64.zip include bin lib
- uses: https://github.com/actions/setup-go@v4 - uses: https://github.com/actions/setup-go@v4
with: with:

View File

@ -221,7 +221,7 @@ add_executable(StrToHash src/StrToHash.cpp)
target_include_directories(EHS PUBLIC ${PROJECT_SOURCE_DIR}/include) target_include_directories(EHS PUBLIC ${PROJECT_SOURCE_DIR}/include)
set(CMAKE_INSTALL_PREFIX "/usr/local") set(CMAKE_INSTALL_PREFIX "${USER_HOME_DIRECTORY}/Libraries/EHS")
install(TARGETS EHS DESTINATION lib) install(TARGETS EHS DESTINATION lib)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include)

View File

@ -71,6 +71,24 @@ Wayland Window System. Wayland support is currently not fully supported yet, use
#include <ehs/EHS.h> #include <ehs/EHS.h>
#include <ehs/io/Console.h> #include <ehs/io/Console.h>
void LogRaised(const ehs::Log& log)
{
ehs::Array<ehs::Str_8> tags = log.GetTags(); // Retrieves the tags from the log such as line number, function, etc...
ehs::Str_8 result = "{";
for (ehs::UInt_32 i = 0; i < tags.Size(); ++i)
{
result += tags[i];
if (i != tags.Size() - 1)
result += ", ";
}
result += "} (" + ehs::Str_8::FromNum(log.GetCode()) + "): " + log.GetMsg(); // Adds the error code and message from the log.
ehs::Console::Write_8(result);
}
ehs::Int_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer) ehs::Int_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer)
{ {
// Simple identifying meta-data for the logger. // Simple identifying meta-data for the logger.
@ -78,6 +96,10 @@ ehs::Int_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer
*appVerId = "Release"; // The app's version prefix; i.e. Alpha, Beta or Release as an example. *appVerId = "Release"; // The app's version prefix; i.e. Alpha, Beta or Release as an example.
*appVer = {1, 0, 0}; // The app's version major, minor and patch number. *appVer = {1, 0, 0}; // The app's version major, minor and patch number.
ehs::Console::Attach(); // Attach to the console.
ehs::Log::SetCallback(LogRaised); // Sets the log callback function for outputting the information to console.
ehs::Console::Write_8("How old are you?"); // Write to the console in UTF_8 character encoding. ehs::Console::Write_8("How old are you?"); // Write to the console in UTF_8 character encoding.
ehs::Str_8 response = ehs::Console::Read_8(); // Read from the console in UTF_8 character encoding. ehs::Str_8 response = ehs::Console::Read_8(); // Read from the console in UTF_8 character encoding.

File diff suppressed because it is too large Load Diff

View File

@ -227,9 +227,6 @@ namespace ehs
data[b] = std::move(tmp); data[b] = std::move(tmp);
} }
/// Inserts a value at the specified index.
/// @param [in] index The index to insert the value at.
/// @param [in] value The value to add.
void Insert(const N index, const T value) void Insert(const N index, const T value)
{ {
N newSize = 0; N newSize = 0;
@ -254,9 +251,6 @@ namespace ehs
size = newSize; size = newSize;
} }
/// Removes a value at the specified index.
/// @param [in] index The index to remove a value.
/// @returns The value that was removed.
T Remove(const N index) T Remove(const N index)
{ {
T popped = {}; T popped = {};
@ -389,7 +383,6 @@ namespace ehs
return Pop(); return Pop();
} }
/// Releases the resources of the array.
void Clear() void Clear()
{ {
if (!data) if (!data)
@ -425,8 +418,6 @@ namespace ehs
return size; return size;
} }
/// Retrieves the index at the end of the array.
/// @returns The index.
N End() const N End() const
{ {
return size - 1; return size - 1;

View File

@ -28,47 +28,25 @@ namespace ehs
bool operator!=(const BaseObj& base) const; bool operator!=(const BaseObj& base) const;
/// Retrieves the class hierarchy.
/// @returns The hierarchy array.
const Type* GetHierarchy() const; const Type* GetHierarchy() const;
/// Retrieves the class hierarchy size.
/// @returns The hierarchy size.
UInt_64 GetHierarchySize() const; UInt_64 GetHierarchySize() const;
/// Checks if this class derives from another.
/// @param [in] typeHashId The type hash id to look for.
/// @returns True if found.
bool HasType(UInt_64 typeHashId) const; bool HasType(UInt_64 typeHashId) const;
/// Checks if this class derives from another.
/// @param [in] typeId The type id to look for.
/// @returns True if found.
bool HasType(const Char_8* typeId) const; bool HasType(const Char_8* typeId) const;
/// Retrieves the top class' information.
/// @returns The Type object containing the class information.
Type GetType() const; Type GetType() const;
/// Retrieves the top class' string name, size.
/// @returns The name size.
UInt_64 GetTypeIdSize() const; UInt_64 GetTypeIdSize() const;
/// Retrieves the top class' string name.
/// @returns The name.
const Char_8* GetTypeId() const; const Char_8* GetTypeId() const;
/// Retrieves the top class' hashed name.
/// @returns The hashed name.
UInt_64 GetTypeHashId() const; UInt_64 GetTypeHashId() const;
/// Clones the object onto the heap.
/// @returns The cloned object.
virtual BaseObj* Clone() const; virtual BaseObj* Clone() const;
protected: protected:
/// Adds the class name to the class hierarchy.
/// @param [in] id The name of the class to add.
void AddType(const Char_8* id); void AddType(const Char_8* id);
}; };
} }

View File

@ -21,9 +21,9 @@ namespace ehs
UINT_8 UINT_8
}; };
DataType FromAudioBitDepth(UInt_16 bitDepth); DataType FromAudioBitDepth(const UInt_16 bitDepth);
UInt_8 ToByteDepth(DataType type); UInt_8 ToByteDepth(const DataType type);
UInt_8 ToBitDepth(DataType type); UInt_8 ToBitDepth(const DataType type);
} }

View File

@ -33,7 +33,7 @@ namespace ehs
public: public:
/// Frees any data created on the heap. /// Frees any data created on the heap.
~Str() override ~Str()
{ {
delete[] data; delete[] data;
} }
@ -84,7 +84,6 @@ namespace ehs
AddType("Str"); AddType("Str");
} }
/// A move constructor.
Str(Str&& str) noexcept Str(Str&& str) noexcept
: BaseObj((BaseObj&&)str), size(str.size), data(str.data) : BaseObj((BaseObj&&)str), size(str.size), data(str.data)
{ {
@ -159,7 +158,7 @@ namespace ehs
/// Concatenates with the given C-style string. /// Concatenates with the given C-style string.
/// @param [in] str The given C-style string. /// @param [in] str The given C-style string.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const T* const str) Str<T, N>& operator+=(const T* const str)
{ {
N inputSize = Len(str); N inputSize = Len(str);
@ -181,7 +180,7 @@ namespace ehs
/// Concatenates with the given string object. /// Concatenates with the given string object.
/// @param [in] str The given string object. /// @param [in] str The given string object.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const Str<T, N>& str) Str<T, N>& operator+=(const Str<T, N>& str)
{ {
T* result = new T[size + str.size + 1]; T* result = new T[size + str.size + 1];
@ -201,7 +200,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const SInt_64 num) Str<T, N>& operator+=(const SInt_64 num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -209,7 +208,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const UInt_64 num) Str<T, N>& operator+=(const UInt_64 num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -217,7 +216,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const SInt_32 num) Str<T, N>& operator+=(const SInt_32 num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -225,7 +224,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const UInt_32 num) Str<T, N>& operator+=(const UInt_32 num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -233,7 +232,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const SInt_16 num) Str<T, N>& operator+=(const SInt_16 num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -241,7 +240,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const UInt_16 num) Str<T, N>& operator+=(const UInt_16 num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -249,7 +248,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const SInt_8 num) Str<T, N>& operator+=(const SInt_8 num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -257,7 +256,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const UInt_8 num) Str<T, N>& operator+=(const UInt_8 num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -283,7 +282,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const float num) Str<T, N>& operator+=(const float num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -291,7 +290,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const double num) Str<T, N>& operator+=(const double num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -299,7 +298,7 @@ namespace ehs
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to concatenate. /// @param [in] num The given number to concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N>& operator+=(const long double num) Str<T, N>& operator+=(const long double num)
{ {
return operator+=(FromNum(num)); return operator+=(FromNum(num));
@ -307,7 +306,7 @@ namespace ehs
/// Concatenates with the given C-style string. /// Concatenates with the given C-style string.
/// @param [in] str The given C-style string. /// @param [in] str The given C-style string.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const T* const str) const Str<T, N> operator+(const T* const str) const
{ {
N inSize = Len(str); N inSize = Len(str);
@ -325,7 +324,7 @@ namespace ehs
/// Concatenates with the given string object. /// Concatenates with the given string object.
/// @param [in] str The given string object. /// @param [in] str The given string object.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const Str<T, N>& str) const Str<T, N> operator+(const Str<T, N>& str) const
{ {
Str<T, N> result(size + str.size); Str<T, N> result(size + str.size);
@ -340,64 +339,64 @@ namespace ehs
} }
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const SInt_64 num) const Str<T, N> operator+(const SInt_64 num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
} }
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const UInt_64 num) const Str<T, N> operator+(const UInt_64 num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
} }
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const SInt_32 num) const Str<T, N> operator+(const SInt_32 num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
} }
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const UInt_32 num) const Str<T, N> operator+(const UInt_32 num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
} }
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const SInt_16 num) const Str<T, N> operator+(const SInt_16 num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
} }
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const UInt_16 num) const Str<T, N> operator+(const UInt_16 num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
} }
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const SInt_8 num) const Str<T, N> operator+(const SInt_8 num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
} }
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const UInt_8 num) const Str<T, N> operator+(const UInt_8 num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
@ -422,32 +421,29 @@ namespace ehs
#endif #endif
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const float num) const Str<T, N> operator+(const float num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
} }
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const double num) const Str<T, N> operator+(const double num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
} }
/// Concatenates with the given number. /// Concatenates with the given number.
/// @param [in] num The given number to Concatenate. /// @param [in] str The given number to Concatenate.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> operator+(const long double num) const Str<T, N> operator+(const long double num) const
{ {
return operator+(FromNum(num)); return operator+(FromNum(num));
} }
/// Compares with a another string. First comparing sizes.
/// @param [in] str The string object to compare with.
/// @returns Whether or not they are equal.
bool operator==(T* str) const bool operator==(T* str) const
{ {
if (size != Len(str)) if (size != Len(str))
@ -539,7 +535,7 @@ namespace ehs
return size; return size;
} }
/// Finds the null terminator in the string and makes it the exact size if greater than. /// Finds a null terminator in the string and makes it the exact size if greater than.
void ExactSize() void ExactSize()
{ {
size = Len(data); size = Len(data);
@ -598,9 +594,6 @@ namespace ehs
Util::Copy(data[dstOffset], src, srcSize * sizeof(T)); Util::Copy(data[dstOffset], src, srcSize * sizeof(T));
} }
/// Inserts a string at a specified index.
/// @param [in] index The index to insert the string at.
/// @param [in] value The string to insert.
void Insert(const N index, const Str& value) void Insert(const N index, const Str& value)
{ {
if (!value.size) if (!value.size)
@ -623,9 +616,6 @@ namespace ehs
size = newSize; size = newSize;
} }
/// Inserts a character at a specified index.
/// @param [in] index The index to insert the character at.
/// @param [in] value The character to insert.
void Insert(const N index, const T value) void Insert(const N index, const T value)
{ {
N newSize = 0; N newSize = 0;
@ -651,10 +641,6 @@ namespace ehs
size = newSize; size = newSize;
} }
/// Removes characters withing the given range.
/// @param [in] start The index to start.
/// @param [in] end The index to end.
/// @returns The removed string object.
Str Remove(const N start, const N end) Str Remove(const N start, const N end)
{ {
if (!size || start >= size || end > size || end <= start) if (!size || start >= size || end > size || end <= start)
@ -678,9 +664,6 @@ namespace ehs
return popped; return popped;
} }
/// Removes a character at the given index.
/// @param [in] index The index to remove a character.
/// @returns The character removed.
T Remove(const N index) T Remove(const N index)
{ {
T popped = {}; T popped = {};
@ -708,6 +691,7 @@ namespace ehs
/// Adds a value at the end of the string. /// Adds a value at the end of the string.
/// @param [in] value The character to push to the end of the string. /// @param [in] value The character to push to the end of the string.
/// @note Automatically moves the null terminator after the value is pushed.
void Push(const Str<T, N> &value) void Push(const Str<T, N> &value)
{ {
T* result = new T[size + value.size + 1]; T* result = new T[size + value.size + 1];
@ -725,6 +709,7 @@ namespace ehs
/// Adds a value at the end of the string. /// Adds a value at the end of the string.
/// @param [in] value The C-style string to push to the end of the string. /// @param [in] value The C-style string to push to the end of the string.
/// @param [in] size The size of the given C-style string. /// @param [in] size The size of the given C-style string.
/// @note Automatically moves the null terminator after the value is pushed.
void Push(const T* const value, const N size) void Push(const T* const value, const N size)
{ {
T* result = new T[this->size + size + 1]; T* result = new T[this->size + size + 1];
@ -741,6 +726,7 @@ namespace ehs
/// Adds a value at the end of the string. /// Adds a value at the end of the string.
/// @param [in] value The C-style string to push to the end of the string. /// @param [in] value The C-style string to push to the end of the string.
/// @note Automatically moves the null terminator after the value is pushed.
void Push(const T* const value) void Push(const T* const value)
{ {
N inSize = Len(value); N inSize = Len(value);
@ -759,6 +745,7 @@ namespace ehs
/// Adds a value at the end of the string. /// Adds a value at the end of the string.
/// @param [in] value The character to push to the end of the string. /// @param [in] value The character to push to the end of the string.
/// @note Automatically moves the null terminator after the value is pushed.
void Push(const T value) void Push(const T value)
{ {
T* result = new T[size + 2]; T* result = new T[size + 2];
@ -774,7 +761,7 @@ namespace ehs
++size; ++size;
} }
/// Removes the value at the end of the array. /// Removes a value at the end of the array.
/// @returns The value that was popped. /// @returns The value that was popped.
T Pop() T Pop()
{ {
@ -807,7 +794,7 @@ namespace ehs
return (Byte*)data; return (Byte*)data;
} }
/// Converts all upper-case ASCII characters to lower-case. /// Changes all upper-case ASCII characters to lower-case.
void ToLower() void ToLower()
{ {
for (N i = 0; i < size; ++i) for (N i = 0; i < size; ++i)
@ -815,8 +802,8 @@ namespace ehs
data[i] += 32; data[i] += 32;
} }
/// Converts all upper-case ASCII characters to lower-case. /// Changes all upper-case ASCII characters to lower-case.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> GetLower() const Str<T, N> GetLower() const
{ {
Str<T, N> result(size); Str<T, N> result(size);
@ -830,7 +817,7 @@ namespace ehs
return result; return result;
} }
/// Converts all lower-case ASCII characters to upper-case. /// Changes all lower-case ASCII characters to upper-case.
void ToUpper() void ToUpper()
{ {
for (N i = 0; i < size; ++i) for (N i = 0; i < size; ++i)
@ -838,8 +825,8 @@ namespace ehs
data[i] -= 32; data[i] -= 32;
} }
/// Converts all lower-case ASCII characters to upper-case. /// Changes all lower-case ASCII characters to upper-case.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> GetUpper() const Str<T, N> GetUpper() const
{ {
Str<T, N> result(size); Str<T, N> result(size);
@ -853,7 +840,7 @@ namespace ehs
return result; return result;
} }
/// Reverses the entire string object. /// Reverses the entire referenced string object.
void Reverse() void Reverse()
{ {
if (size <= 1 || !data) if (size <= 1 || !data)
@ -872,7 +859,7 @@ namespace ehs
} }
/// Reverses the entire string object. /// Reverses the entire string object.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> GetReverse() Str<T, N> GetReverse()
{ {
if (size <= 1 || !data) if (size <= 1 || !data)
@ -889,7 +876,7 @@ namespace ehs
/// Clips the string at the given index and with the given size. /// Clips the string at the given index and with the given size.
/// @param [in] index The index to clip at. /// @param [in] index The index to clip at.
/// @param [in] size The size for the clip starting from the index. /// @param [in] size The size for the clip starting from the index.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> Sub(const N index, const N size = 0) const Str<T, N> Sub(const N index, const N size = 0) const
{ {
if (index >= this->size) if (index >= this->size)
@ -924,10 +911,10 @@ namespace ehs
} }
} }
/// Splits a string into a Vector with the given separator. /// Splits a string into an array with the given separator.
/// @param [in] ide The given string as the separator. /// @param [in] ide The given string as the separator.
/// @param [in] max The max amount of times to split the string. /// @param [in] max The max amount of times to split the string.
/// @returns The resulting string object. /// @returns The result.
Vector<Str<T, N>, N> Split(const Str<T, N>& ide, const N max = 0) const Vector<Str<T, N>, N> Split(const Str<T, N>& ide, const N max = 0) const
{ {
Vector<Str<T, N>, N> result(0, 5); Vector<Str<T, N>, N> result(0, 5);
@ -965,9 +952,9 @@ namespace ehs
return result; return result;
} }
/// Removes all instances of the ide. /// Removes all instances of the given string object.
/// @param [in] ide The string to look for. /// @param [in] ide The string to look for.
/// @returns The resulting string object. /// @returns The result.
Str<T, N> RemoveAll(const Str<T, N>& ide) const Str<T, N> RemoveAll(const Str<T, N>& ide) const
{ {
Str<T, N> result(size); Str<T, N> result(size);
@ -994,10 +981,6 @@ namespace ehs
return result; return result;
} }
/// Replaces all instances of ide with the replacer.
/// @param [in] ide The string to look for.
/// @param [in] replacer The string placed.
/// @returns The resulting string object.
Str ReplaceAll(const Str& ide, const Str& replacer) const Str ReplaceAll(const Str& ide, const Str& replacer) const
{ {
Str<T, N> result; Str<T, N> result;
@ -1085,10 +1068,6 @@ namespace ehs
return false; return false;
} }
/// Checks if the current string contains the given ide.
/// @param [in] ide The given ide to check for.
/// @param [in] pattern The search pattern to use.
/// @returns True if the current string does contain the ide.
bool Contains(const Str<T, N>& ide, const SearchPattern pattern = SearchPattern::LEFT_RIGHT) const bool Contains(const Str<T, N>& ide, const SearchPattern pattern = SearchPattern::LEFT_RIGHT) const
{ {
if (pattern == SearchPattern::LEFT_RIGHT) if (pattern == SearchPattern::LEFT_RIGHT)
@ -1138,10 +1117,6 @@ namespace ehs
return true; return true;
} }
/// Converts a number into hexadecimal string representation.
/// @tparam I The data type of the number given.
/// @param [in] num The number to convert.
/// @returns The resulting hexadecimal.
template<typename I = int> template<typename I = int>
static Str NumToHex(const I num) static Str NumToHex(const I num)
{ {
@ -1158,10 +1133,6 @@ namespace ehs
return result; return result;
} }
/// Converts a string hexadecimal into a number.
/// @tparam I The data type of the number outputted.
/// @param [in] in The string to convert.
/// @returns The resulting number.
template<typename I = int> template<typename I = int>
static I HexToNum(const Str& in) static I HexToNum(const Str& in)
{ {
@ -1202,9 +1173,6 @@ namespace ehs
return neg ? -acc : acc; return neg ? -acc : acc;
} }
/// Converts the current string from hexadecimal into a number.
/// @tparam I The data type of the number outputted.
/// @returns The resulting number.
template<typename I = int> template<typename I = int>
I HexToNum() const I HexToNum() const
{ {
@ -1248,7 +1216,7 @@ namespace ehs
/// Converts the string into a number. /// Converts the string into a number.
/// @tparam I The resulting number's data type. /// @tparam I The resulting number's data type.
/// @returns The result. /// @returns The result.
/// @note Use "IsNum" before this if the string object is not guaranteed to be a number. /// @note Use "IsNum" before this if the referenced string object will not always be a number.
template<typename I = N> template<typename I = N>
I ToDecimal() const I ToDecimal() const
{ {
@ -1266,9 +1234,6 @@ namespace ehs
return r; return r;
} }
/// Converts the string into a floating point number.
/// @returns The resulting float.
/// @note Use "IsNum" before this if the string object is not guaranteed to be a number.
float ToFloat() const float ToFloat() const
{ {
N decPoint = size; N decPoint = size;
@ -1292,9 +1257,6 @@ namespace ehs
return result; return result;
} }
/// Converts the string into a double floating point number.
/// @returns The resulting double.
/// @note Use "IsNum" before this if the string object is not guaranteed to be a number.
double ToDouble() const double ToDouble() const
{ {
N decPoint = size; N decPoint = size;
@ -1318,9 +1280,6 @@ namespace ehs
return result; return result;
} }
/// Converts the string into a long double floating point number.
/// @returns The resulting long double.
/// @note Use "IsNum" before this if the string object is not guaranteed to be a number.
long double ToLDouble() const long double ToLDouble() const
{ {
N decPoint = size; N decPoint = size;
@ -1345,8 +1304,7 @@ namespace ehs
} }
/// Converts the given number into a string. /// Converts the given number into a string.
/// @param [in] num The given number to convert. /// @returns The result.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const SInt_64 num) static Str<T, N> FromNum(const SInt_64 num)
{ {
if (num == 0) if (num == 0)
@ -1381,8 +1339,7 @@ namespace ehs
} }
/// Converts the given number into a string. /// Converts the given number into a string.
/// @param [in] num The given number to convert. /// @returns The result.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const UInt_64 num) static Str<T, N> FromNum(const UInt_64 num)
{ {
if (num == 0) if (num == 0)
@ -1410,8 +1367,7 @@ namespace ehs
} }
/// Converts the given number into a string. /// Converts the given number into a string.
/// @param [in] num The given number to convert. /// @returns The result.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const SInt_32 num) static Str<T, N> FromNum(const SInt_32 num)
{ {
if (num == 0) if (num == 0)
@ -1446,8 +1402,7 @@ namespace ehs
} }
/// Converts the given number into a string. /// Converts the given number into a string.
/// @param [in] num The given number to convert. /// @returns The result.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const UInt_32 num) static Str<T, N> FromNum(const UInt_32 num)
{ {
if (num == 0) if (num == 0)
@ -1475,8 +1430,7 @@ namespace ehs
} }
/// Converts the given number into a string. /// Converts the given number into a string.
/// @param [in] num The given number to convert. /// @returns The result.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const SInt_16 num) static Str<T, N> FromNum(const SInt_16 num)
{ {
if (num == 0) if (num == 0)
@ -1511,8 +1465,7 @@ namespace ehs
} }
/// Converts the given number into a string. /// Converts the given number into a string.
/// @param [in] num The given number to convert. /// @returns The result.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const UInt_16 num) static Str<T, N> FromNum(const UInt_16 num)
{ {
if (num == 0) if (num == 0)
@ -1540,8 +1493,7 @@ namespace ehs
} }
/// Converts the given number into a string. /// Converts the given number into a string.
/// @param [in] num The given number to convert. /// @returns The result.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const SInt_8 num) static Str<T, N> FromNum(const SInt_8 num)
{ {
if (num == 0) if (num == 0)
@ -1576,8 +1528,7 @@ namespace ehs
} }
/// Converts the given number into a string. /// Converts the given number into a string.
/// @param [in] num The given number to convert. /// @returns The result.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const UInt_8 num) static Str<T, N> FromNum(const UInt_8 num)
{ {
if (num == 0) if (num == 0)
@ -1669,10 +1620,8 @@ namespace ehs
} }
#endif #endif
/// Converts the given floating point into a string. /// Converts the given float into a string.
/// @param [in] num The given floating point to convert. /// @returns The result.
/// @param [in] maxDecimals The max decimal places to add.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const float num, const UInt_8 maxDecimals = 5) static Str<T, N> FromNum(const float num, const UInt_8 maxDecimals = 5)
{ {
SInt_64 whole = (SInt_64)num; SInt_64 whole = (SInt_64)num;
@ -1711,10 +1660,8 @@ namespace ehs
return result; return result;
} }
/// Converts the given double floating point into a string. /// Converts the given double into a string.
/// @param [in] num The given double floating point to convert. /// @returns The result.
/// @param [in] maxDecimals The max decimal places to add.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const double num, const UInt_8 maxDecimals = 5) static Str<T, N> FromNum(const double num, const UInt_8 maxDecimals = 5)
{ {
SInt_64 whole = (SInt_64)num; SInt_64 whole = (SInt_64)num;
@ -1753,10 +1700,8 @@ namespace ehs
return result; return result;
} }
/// Converts the given long double floating point into a string. /// Converts the given long double into a string.
/// @param [in] num The given long double floating point to convert. /// @returns The result.
/// @param [in] maxDecimals The max decimal places to add.
/// @returns The resulting string representation.
static Str<T, N> FromNum(const long double num, const UInt_8 maxDecimals = 5) static Str<T, N> FromNum(const long double num, const UInt_8 maxDecimals = 5)
{ {
SInt_64 whole = (SInt_64)num; SInt_64 whole = (SInt_64)num;
@ -1797,7 +1742,7 @@ namespace ehs
/// A 32-bit FNV-1a hash algorithm. /// A 32-bit FNV-1a hash algorithm.
/// @param [in] str The string to hash. /// @param [in] str The string to hash.
/// @returns The resulting hash. Zero if string does not contain any characters. /// @returns The resulting hash.
static UInt_32 Hash_32(const Str<T, N>& str) static UInt_32 Hash_32(const Str<T, N>& str)
{ {
if (!str.Size()) if (!str.Size())
@ -1813,8 +1758,6 @@ namespace ehs
return hash; return hash;
} }
/// A 32-bit FNV-1a hash algorithm.
/// @returns The resulting hash. Zero if string does not contain any characters.
UInt_32 Hash_32() const UInt_32 Hash_32() const
{ {
if (!size) if (!size)
@ -1832,7 +1775,7 @@ namespace ehs
/// A 64-bit FNV-1a hash algorithm. /// A 64-bit FNV-1a hash algorithm.
/// @param [in] str The string to hash. /// @param [in] str The string to hash.
/// @returns The resulting hash. Zero if string does not contain any characters. /// @returns The resulting hash.
static UInt_64 Hash_64(const Str<T, N>& str) static UInt_64 Hash_64(const Str<T, N>& str)
{ {
if (!str.Size()) if (!str.Size())
@ -1848,8 +1791,6 @@ namespace ehs
return hash; return hash;
} }
/// A 64-bit FNV-1a hash algorithm.
/// @returns The resulting hash. Zero if string does not contain any characters.
UInt_64 Hash_64() const UInt_64 Hash_64() const
{ {
if (!size) if (!size)
@ -1865,9 +1806,6 @@ namespace ehs
return hash; return hash;
} }
/// Calculates the length of a C-Style string.
/// @param [in] str The C-Style string to calculate.
/// @returns The character count.
static N Len(const T* const str) static N Len(const T* const str)
{ {
N count = 0; N count = 0;
@ -1876,10 +1814,6 @@ namespace ehs
return count; return count;
} }
/// Compares two C-style string with each other.
/// @param [in] a The first C-style string to compare.
/// @param [in] b The second C-style string to compare.
/// @returns True if both C-style strings are equal.
static bool Cmp(const T* const a, const T* const b) static bool Cmp(const T* const a, const T* const b)
{ {
N aSize = Len(a); N aSize = Len(a);

View File

@ -17,8 +17,6 @@ namespace ehs
public: public:
Type(); Type();
/// Constructs the object with the given class name.
/// @param [in] id The class name.
explicit Type(const Char_8* id); explicit Type(const Char_8* id);
Type(Type&& type) noexcept; Type(Type&& type) noexcept;
@ -41,20 +39,12 @@ namespace ehs
bool operator!=(const Char_8* inStr) const; bool operator!=(const Char_8* inStr) const;
/// Retrieves the name size.
/// @returns The size.
UInt_64 GetSize() const; UInt_64 GetSize() const;
/// Retrieves the name.
/// @returns The name.
const Char_8* GetId() const; const Char_8* GetId() const;
/// Retrieves the hashed name.
/// @returns The hashed name.
UInt_64 GetHashId() const; UInt_64 GetHashId() const;
/// Whether or not this object was properly constructed.
/// @returns The result.
bool IsValid() const; bool IsValid() const;
private: private:

View File

@ -8,14 +8,8 @@ namespace ehs
class URI class URI
{ {
public: public:
/// Encodes specialized characters in the URI.
/// @param [in] in The URI to encode.
/// @returns The encoded URI.
static Str_8 Encode(const Str_8& in); static Str_8 Encode(const Str_8& in);
/// Decodes specialized characters back into their readable format.
/// @param [in] in The URI to decode.
/// @returns The decoded URI.
static Str_8 Decode(const Str_8& in); static Str_8 Decode(const Str_8& in);
}; };
} }

View File

@ -259,8 +259,6 @@ namespace ehs
return stride; return stride;
} }
/// Retrieves the index at the end of the array.
/// @returns The index.
N End() const N End() const
{ {
return size ? size - 1 : size; return size ? size - 1 : size;
@ -619,7 +617,7 @@ namespace ehs
} }
} }
/// Releases the resources of the vector. /// Clears all values in the vector object.
void Clear() void Clear()
{ {
if (!size) if (!size)

View File

@ -14,10 +14,10 @@ namespace ehs
protected: protected:
AddrType addrType; AddrType addrType;
Str_8 localAddr; Str_8 localAddr;
UInt_16 localPort; unsigned short localPort;
Str_8 remoteHostName; Str_8 remoteHostName;
Str_8 remoteAddr; Str_8 remoteAddr;
UInt_16 remotePort; unsigned short remotePort;
bool connection; bool connection;
bool bound; bool bound;
bool listening; bool listening;
@ -30,12 +30,9 @@ namespace ehs
virtual ~BaseTCP() = default; virtual ~BaseTCP() = default;
/// Initializes the socket with the defaults.
BaseTCP(); BaseTCP();
/// Properly initializes the socket. BaseTCP(const AddrType addrType);
/// @param [in] type The ip version to initialize the socket with.
BaseTCP(AddrType addrType);
BaseTCP(BaseTCP&& tcp) noexcept; BaseTCP(BaseTCP&& tcp) noexcept;
@ -45,45 +42,22 @@ namespace ehs
BaseTCP& operator=(const BaseTCP& tcp); BaseTCP& operator=(const BaseTCP& tcp);
/// Explicitly initialize the socket.
virtual void Initialize() = 0; virtual void Initialize() = 0;
/// Explicitly release resources before it falls off the stack.
virtual void Release() = 0; virtual void Release() = 0;
/// Binds to socket to a specified address and port. virtual void Bind(const Str_8& address, unsigned short port) = 0;
/// @param [in] address The ip address to bind to.
/// @param [in] port The port to bind to.
/// @note Used for servers.
virtual void Bind(const Str_8& address, UInt_16 port) = 0;
/// Listens for new incoming connections.
/// @note Used for servers.
virtual void Listen() = 0; virtual void Listen() = 0;
/// Accepts the new incoming connection.
/// @note Used for servers.
virtual BaseTCP* Accept() = 0; virtual BaseTCP* Accept() = 0;
/// Connects to a server at the specified address and port. virtual void Connect(const Str_8& address, const unsigned short port) = 0;
/// @param [in] address The ip address to connect to.
/// @param [in] port The port to connect to.
/// @note Used for clients.
virtual void Connect(const Str_8& address, UInt_16 port) = 0;
/// Sends data to the connected endpoint. virtual UInt_64 Send(const Byte* const buffer, const UInt_32 size) = 0;
/// @param [in] buffer The data to send to the endpoint.
/// @param [in] size The size in bytes of data being sent.
virtual UInt_64 Send(const Byte* buffer, UInt_32 size) = 0;
/// Receives data from the connected endpoint. virtual UInt_64 Receive(Byte* const buffer, const UInt_32 size) = 0;
/// @param [out] buffer The incoming data from the endpoint.
/// @param [in] size The max size of the buffer in bytes to store the data.
/// @returns The size of the incoming data in bytes.
virtual UInt_64 Receive(Byte* buffer, UInt_32 size) = 0;
/// Sends a string to the connected endpoint.
/// @param [in] str The string to send to the endpoint.
void SendStr(const Str_8& str); void SendStr(const Str_8& str);
/// Sends a HTTP response to the connected endpoint. /// Sends a HTTP response to the connected endpoint.
@ -102,61 +76,37 @@ namespace ehs
/// @returns The request received. /// @returns The request received.
Request RecvReq(); Request RecvReq();
/// Retrieves the sockets ip version.
/// @returns The ip version.
AddrType GetAddressType() const; AddrType GetAddressType() const;
/// Retrieves the bound ip address.
/// @returns The ip address.
Str_8 GetLocalAddress() const; Str_8 GetLocalAddress() const;
/// Retrieves the bound port.
/// @returns The port.
unsigned short GetLocalPort() const; unsigned short GetLocalPort() const;
/// Retrieves the ip address of the connected endpoint.
/// @returns The ip address.
Str_8 GetRemoteAddress() const; Str_8 GetRemoteAddress() const;
/// Retrieves the port of the connected endpoint. unsigned short GetRemotePort() const;
/// @returns The port.
UInt_16 GetRemotePort() const;
/// Retrieves whether or not this socket is connected to a client endpoint.
/// @returns The result.
bool IsConnection() const; bool IsConnection() const;
/// Retrieves whether of not this socket is bound to an ip address and port.
/// @returns The result.
bool IsBound() const; bool IsBound() const;
/// Retrieves whether or not this socket is listening for incoming connections.
/// @returns The result.
bool IsListening() const; bool IsListening() const;
/// Retrieves whether or not this socket is connected to an endpoint.
/// @returns The result.
bool IsConnected() const; bool IsConnected() const;
/// Sets whether or not the socket blocks the thread when receiving data. virtual void SetBlocking(const bool blocking) = 0;
/// @param [in] blocking Whether or not to block.
virtual void SetBlocking(bool blocking) = 0;
/// Retrieves whether or not when receiving data blocks the thread.
/// @returns The result.
virtual bool IsBlocking() const = 0; virtual bool IsBlocking() const = 0;
/// Retrieves whether or not this socket was initialized.
/// @returns The result.
virtual bool IsValid() const = 0; virtual bool IsValid() const = 0;
private: private:
Str_8 RecvHeader(); Str_8 RecvHeader();
Str_8 RecvBody(UInt_64 contentLength); Str_8 RecvBody(const UInt_64 contentLength);
UInt_64 RecvChunkSize(); UInt_64 RecvChunkSize();
Str_8 RecvChunk(UInt_64 chunkSize); Str_8 RecvChunk(const UInt_64 chunkSize);
}; };
} }

View File

@ -17,11 +17,8 @@ namespace ehs
public: public:
virtual ~BaseUDP() = default; virtual ~BaseUDP() = default;
/// Initializes the socket with the defaults.
BaseUDP(); BaseUDP();
/// Properly initializes the socket.
/// @param [in] type The ip version to initialize the socket with.
BaseUDP(AddrType type); BaseUDP(AddrType type);
BaseUDP(BaseUDP&& udp) noexcept; BaseUDP(BaseUDP&& udp) noexcept;
@ -32,57 +29,26 @@ namespace ehs
BaseUDP& operator=(const BaseUDP& udp); BaseUDP& operator=(const BaseUDP& udp);
/// Explicitly release resources before it falls off the stack.
virtual void Release() = 0; virtual void Release() = 0;
/// Binds to socket to a specified address and port.
/// @param [in] type The ip version to use.
/// @param [in] address The ip address to bind to.
/// @param [in] port The port to bind to.
/// @note Used for servers.
virtual void Bind(AddrType type, const Str_8& address, UInt_16 port) = 0; virtual void Bind(AddrType type, const Str_8& address, UInt_16 port) = 0;
/// Sends data to the endpoint.
/// @param [in] type The ip version of the endpoint.
/// @param [in] address The ip address of the endpoint.
/// @param [in] port The port of the endpoint is bound to.
virtual UInt_64 Send(AddrType type, const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size) = 0; virtual UInt_64 Send(AddrType type, const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size) = 0;
/// Receives data from the endpoint.
/// @param [out] type The ip version of the endpoint.
/// @param [out] address The ip address of the endpoint.
/// @param [out] port The port of the endpoint.
/// @param [out] data The incoming data from the endpoint.
/// @param [in] size The max size of the buffer in bytes to store the data.
/// @returns The size of the incoming data in bytes.
virtual UInt_64 Receive(AddrType* type, Str_8* address, UInt_16* port, Byte* data, UInt_64 size) = 0; virtual UInt_64 Receive(AddrType* type, Str_8* address, UInt_16* port, Byte* data, UInt_64 size) = 0;
/// Retrieves whether or not this socket is bound to an ip address and port.
/// @returns The result.
bool IsBound() const; bool IsBound() const;
/// Sets whether or not the socket blocks the thread when receiving data.
/// @param [in] blocking Whether or not to block.
virtual void SetBlocking(bool blocking) = 0; virtual void SetBlocking(bool blocking) = 0;
/// Retrieves whether or not when receiving data blocks the thread.
/// @returns The result.
virtual bool IsBlocking() const = 0; virtual bool IsBlocking() const = 0;
/// Retrieves the bound ip version.
/// @returns The result.
AddrType GetLocalAddressType() const; AddrType GetLocalAddressType() const;
/// Retrieves the bound ip address.
/// @returns The bound ip address.
Str_8 GetLocalAddress() const; Str_8 GetLocalAddress() const;
/// Retrieves the bound port.
/// @returns The bound port.
UInt_16 GetLocalPort() const; UInt_16 GetLocalPort() const;
/// Retrieves whether or not this socket was initialized.
/// @returns The result.
virtual bool IsValid() const = 0; virtual bool IsValid() const = 0;
}; };
} }

View File

@ -9,9 +9,6 @@ namespace ehs
class DNS class DNS
{ {
public: public:
/// Resolves a hostname to an ip address. static Str_8 Resolve(const AddrType addrType, const Str_8& hostName);
/// @param [in] hostname The given hostname to resolve.
/// @returns The resulting ip address.
static Str_8 Resolve(const Str_8& hostname);
}; };
} }

View File

@ -22,7 +22,7 @@ namespace ehs
/// Default members initialization. /// Default members initialization.
TCP(); TCP();
TCP(AddrType addrType); TCP(const AddrType addrType);
TCP(TCP&& tcp) noexcept; TCP(TCP&& tcp) noexcept;
@ -46,7 +46,7 @@ namespace ehs
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device. /// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param [in] port The port to bind to. /// @param [in] port The port to bind to.
/// @note Requires the port given to be forwarded if this is called. /// @note Requires the port given to be forwarded if this is called.
void Bind(const Str_8& address, UInt_16 port) override; void Bind(const Str_8& address, unsigned short port) override;
/// Listens for incoming connections. Used for servers or PtP. /// Listens for incoming connections. Used for servers or PtP.
void Listen() override; void Listen() override;
@ -58,23 +58,23 @@ namespace ehs
/// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP. /// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP.
/// @param address The address of the listening TCP socket. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device. /// @param address The address of the listening TCP socket. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param port The port of the listening TCP socket. /// @param port The port of the listening TCP socket.
void Connect(const Str_8& address, UInt_16 port) override; void Connect(const Str_8& address, const unsigned short port) override;
/// Sends data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking. /// Sends data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
/// @param [in] buffer The C-style array to send. /// @param [in] buffer The C-style array to send.
/// @param [in] size The size of the given C-style array. /// @param [in] size The size of the given C-style array.
/// @returns The size of the data actually sent in bytes. /// @returns The size of the data actually sent in bytes.
UInt_64 Send(const Byte* buffer, UInt_32 size) override; UInt_64 Send(const Byte* const buffer, const UInt_32 size) override;
/// Receives data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking. /// Receives data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
/// @param [out] buffer The C-style array to receive with. /// @param [out] buffer The C-style array to receive with.
/// @param [in] size The size of the given C-style array. /// @param [in] size The size of the given C-style array.
/// @returns The size of the data actually received in bytes. /// @returns The size of the data actually received in bytes.
UInt_64 Receive(Byte* buffer, UInt_32 size) override; UInt_64 Receive(Byte* const buffer, const UInt_32 size) override;
/// Sets whether or not receiving data blocks the next task. /// Sets whether or not receiving data blocks the next task.
/// @param [in] blocking Whether or not to block. /// @param [in] blocking Whether or not to block.
void SetBlocking(bool blocking) override; void SetBlocking(const bool blocking) override;
/// Retrieves whether or not this socket will block when receiving data. /// Retrieves whether or not this socket will block when receiving data.
/// @returns The result. /// @returns The result.
@ -83,12 +83,12 @@ namespace ehs
bool IsValid() const override; bool IsValid() const override;
private: private:
void Bind_v6(const Str_8& address, UInt_16 port); void Bind_v6(const Str_8& address, unsigned short port);
void Bind_v4(const Str_8& address, UInt_16 port); void Bind_v4(const Str_8& address, unsigned short port);
void Connect_v6(const Str_8& address, UInt_16 port); void Connect_v6(const Str_8& address, unsigned short port);
void Connect_v4(const Str_8& address, UInt_16 port); void Connect_v4(const Str_8& address, unsigned short port);
}; };
} }

View File

@ -46,7 +46,7 @@ namespace ehs
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device. /// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param [in] port The port to bind to. /// @param [in] port The port to bind to.
/// @note Requires the port given to be forwarded if this is called. /// @note Requires the port given to be forwarded if this is called.
void Bind(const Str_8& address, UInt_16 port) override; void Bind(const Str_8& address, unsigned short port) override;
/// Listens for incoming connections. Used for servers or PtP. /// Listens for incoming connections. Used for servers or PtP.
void Listen() override; void Listen() override;
@ -58,23 +58,23 @@ namespace ehs
/// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP. /// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP.
/// @param address The address of the listening TCP socket. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device. /// @param address The address of the listening TCP socket. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param port The port of the listening TCP socket. /// @param port The port of the listening TCP socket.
void Connect(const Str_8& address, UInt_16 port) override; void Connect(const Str_8& address, const unsigned short port) override;
/// Sends data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking. /// Sends data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
/// @param [in] buffer The C-style array to send. /// @param [in] buffer The C-style array to send.
/// @param [in] size The size of the given C-style array. /// @param [in] size The size of the given C-style array.
/// @returns The size of the data actually sent in bytes. /// @returns The size of the data actually sent in bytes.
UInt_64 Send(const Byte* buffer, UInt_32 size) override; UInt_64 Send(const Byte* const buffer, const UInt_32 size) override;
/// Receives data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking. /// Receives data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
/// @param [out] buffer The C-style array to receive with. /// @param [out] buffer The C-style array to receive with.
/// @param [in] size The size of the given C-style array. /// @param [in] size The size of the given C-style array.
/// @returns The size of the data actually received in bytes. /// @returns The size of the data actually received in bytes.
UInt_64 Receive(Byte* buffer, UInt_32 size) override; UInt_64 Receive(Byte* const buffer, const UInt_32 size) override;
/// Sets whether or not receiving data blocks the next task. /// Sets whether or not receiving data blocks the next task.
/// @param [in] blocking Whether or not to block. /// @param [in] blocking Whether or not to block.
void SetBlocking(bool blocking) override; void SetBlocking(const bool blocking) override;
/// Retrieves whether or not this socket will block when receiving data. /// Retrieves whether or not this socket will block when receiving data.
/// @returns The result. /// @returns The result.
@ -83,12 +83,12 @@ namespace ehs
bool IsValid() const override; bool IsValid() const override;
private: private:
void Bind_v6(const Str_8& address, UInt_16 port); void Bind_v6(const Str_8& address, unsigned short port);
void Bind_v4(const Str_8& address, UInt_16 port); void Bind_v4(const Str_8& address, unsigned short port);
void Connect_v6(const Str_8& address, UInt_16 port); void Connect_v6(const Str_8& address, unsigned short port);
void Connect_v4(const Str_8& address, UInt_16 port); void Connect_v4(const Str_8& address, unsigned short port);
}; };
} }

View File

@ -1,7 +1,6 @@
#include "ehs/EHS.h" #include "ehs/EHS.h"
#include "ehs/Log.h" #include "ehs/Log.h"
#include "ehs/Version.h" #include "ehs/Version.h"
#include "ehs/io/Console.h"
#include "ehs/GarbageCollector.h" #include "ehs/GarbageCollector.h"
#include "ehs/io/audio/Audio.h" #include "ehs/io/audio/Audio.h"
#include "ehs/io/img/Img.h" #include "ehs/io/img/Img.h"
@ -621,30 +620,8 @@ namespace ehs
} }
} }
void LogRaised(const ehs::Log& log)
{
ehs::Array<ehs::Str_8> tags = log.GetTags();
ehs::Str_8 result = "{";
for (ehs::UInt_32 i = 0; i < tags.Size(); ++i)
{
result += tags[i];
if (i != tags.Size() - 1)
result += ", ";
}
result += "} (" + ehs::Str_8::FromNum(log.GetCode()) + "): " + log.GetMsg();
ehs::Console::Write_8(result);
}
int main() int main()
{ {
ehs::Console::Attach();
ehs::Log::SetCallback(LogRaised);
ehs::Audio::AddCodec({ ehs::Audio::AddCodec({
"Waveform Audio", "Waveform Audio",
"wav", "wav",

View File

@ -8,6 +8,8 @@ ehs::Int_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer
*appVerId = "Release"; *appVerId = "Release";
*appVer = {1, 0, 0}; *appVer = {1, 0, 0};
ehs::Console::Attach();
ehs::Vector<ehs::Str_8> args = ehs::Console::GetArgs_8(); ehs::Vector<ehs::Str_8> args = ehs::Console::GetArgs_8();
if (args.Size() > 1) if (args.Size() > 1)

View File

@ -12,7 +12,7 @@
namespace ehs namespace ehs
{ {
Str_8 DNS::Resolve(const Str_8& hostname) Str_8 DNS::Resolve(const AddrType addrType, const Str_8& hostName)
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
WSADATA data = {}; WSADATA data = {};
@ -25,9 +25,15 @@ namespace ehs
} }
#endif #endif
addrinfo hints = {};
if (addrType == AddrType::IPV6)
hints.ai_family = AF_INET6;
else if (addrType == AddrType::IPV4)
hints.ai_family = AF_INET;
addrinfo* result = nullptr; addrinfo* result = nullptr;
Int_32 code = getaddrinfo(hostname, nullptr, nullptr, &result); Int_32 code = getaddrinfo(hostName, nullptr, &hints, &result);
if (code) if (code)
{ {
EHS_LOG_INT("Error", 1, "Failed to resolve host with error #" + Str_8::FromNum(code) + "."); EHS_LOG_INT("Error", 1, "Failed to resolve host with error #" + Str_8::FromNum(code) + ".");
@ -43,26 +49,22 @@ namespace ehs
#endif #endif
if (result->ai_family == AF_INET6) if (addrType == AddrType::IPV6)
{ {
Str_8 ipResult(INET6_ADDRSTRLEN); Char_8 ipResult[INET6_ADDRSTRLEN];
inet_ntop(result->ai_family, &((sockaddr_in6*)result->ai_addr)->sin6_addr, ipResult, INET6_ADDRSTRLEN); inet_ntop(result->ai_family, &((sockaddr_in6*)result->ai_addr)->sin6_addr, ipResult, INET6_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result); freeaddrinfo(result);
return ipResult; return ipResult;
} }
else if (result->ai_family == AF_INET) else if (addrType == AddrType::IPV4)
{ {
Str_8 ipResult(INET_ADDRSTRLEN); Char_8 ipResult[INET_ADDRSTRLEN];
inet_ntop(result->ai_family, &((sockaddr_in*)result->ai_addr)->sin_addr, ipResult, INET_ADDRSTRLEN); inet_ntop(result->ai_family, &((sockaddr_in*)result->ai_addr)->sin_addr, ipResult, INET_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result); freeaddrinfo(result);
return ipResult; return ipResult;

View File

@ -114,7 +114,7 @@ namespace ehs
hdl = EHS_INVALID_SOCKET; hdl = EHS_INVALID_SOCKET;
} }
void TCP::Bind(const Str_8& address, UInt_16 port) void TCP::Bind(const Str_8& address, unsigned short port)
{ {
if (!IsValid() || bound || connection) if (!IsValid() || bound || connection)
return; return;
@ -207,13 +207,13 @@ namespace ehs
return client; return client;
} }
void TCP::Connect(const Str_8& address, const UInt_16 port) void TCP::Connect(const Str_8& address, const unsigned short port)
{ {
if (connection || !IsValid() || listening) if (connection || !IsValid() || listening)
return; return;
remoteHostName = address; remoteHostName = address;
remoteAddr = DNS::Resolve(address); remoteAddr = DNS::Resolve(addrType, address);
remotePort = port; remotePort = port;
if (addrType == AddrType::IPV6) if (addrType == AddrType::IPV6)
@ -331,7 +331,7 @@ namespace ehs
return hdl != EHS_INVALID_SOCKET; return hdl != EHS_INVALID_SOCKET;
} }
void TCP::Bind_v6(const Str_8& address, UInt_16 port) void TCP::Bind_v6(const Str_8& address, unsigned short port)
{ {
sockaddr_in6 result = {}; sockaddr_in6 result = {};
result.sin6_family = AF_INET6; result.sin6_family = AF_INET6;
@ -367,7 +367,7 @@ namespace ehs
} }
} }
void TCP::Bind_v4(const Str_8& address, UInt_16 port) void TCP::Bind_v4(const Str_8& address, unsigned short port)
{ {
sockaddr_in result = {}; sockaddr_in result = {};
result.sin_family = AF_INET; result.sin_family = AF_INET;
@ -402,7 +402,7 @@ namespace ehs
} }
} }
void TCP::Connect_v6(const Str_8& address, UInt_16 port) void TCP::Connect_v6(const Str_8& address, unsigned short port)
{ {
sockaddr_in6 result = {}; sockaddr_in6 result = {};
result.sin6_family = AF_INET6; result.sin6_family = AF_INET6;
@ -439,7 +439,7 @@ namespace ehs
} }
} }
void TCP::Connect_v4(const Str_8& address, UInt_16 port) void TCP::Connect_v4(const Str_8& address, unsigned short port)
{ {
sockaddr_in result = {}; sockaddr_in result = {};
result.sin_family = AF_INET; result.sin_family = AF_INET;

View File

@ -137,7 +137,7 @@ namespace ehs
connected = false; connected = false;
} }
void TCP::Bind(const Str_8& address, UInt_16 port) void TCP::Bind(const Str_8& address, unsigned short port)
{ {
if (!IsValid() || bound || connection) if (!IsValid() || bound || connection)
return; return;
@ -236,7 +236,7 @@ namespace ehs
return client; return client;
} }
void TCP::Connect(const Str_8& address, const UInt_16 port) void TCP::Connect(const Str_8& address, const unsigned short port)
{ {
if (connection || !IsValid() || listening) if (connection || !IsValid() || listening)
return; return;
@ -352,7 +352,7 @@ namespace ehs
return hdl != EHS_INVALID_SOCKET; return hdl != EHS_INVALID_SOCKET;
} }
void TCP::Bind_v6(const Str_8& address, UInt_16 port) void TCP::Bind_v6(const Str_8& address, unsigned short port)
{ {
sockaddr_in6 result = {}; sockaddr_in6 result = {};
result.sin6_family = AF_INET6; result.sin6_family = AF_INET6;
@ -388,7 +388,7 @@ namespace ehs
} }
} }
void TCP::Bind_v4(const Str_8& address, UInt_16 port) void TCP::Bind_v4(const Str_8& address, unsigned short port)
{ {
sockaddr_in result = {}; sockaddr_in result = {};
result.sin_family = AF_INET; result.sin_family = AF_INET;
@ -424,7 +424,7 @@ namespace ehs
} }
} }
void TCP::Connect_v6(const Str_8& address, UInt_16 port) void TCP::Connect_v6(const Str_8& address, unsigned short port)
{ {
sockaddr_in6 result = {}; sockaddr_in6 result = {};
result.sin6_family = AF_INET6; result.sin6_family = AF_INET6;
@ -461,7 +461,7 @@ namespace ehs
} }
} }
void TCP::Connect_v4(const Str_8& address, UInt_16 port) void TCP::Connect_v4(const Str_8& address, unsigned short port)
{ {
sockaddr_in result = {}; sockaddr_in result = {};
result.sin_family = AF_INET; result.sin_family = AF_INET;

View File

@ -42,7 +42,7 @@ namespace ehs
TCP server(AddrType::IPV4); TCP server(AddrType::IPV4);
server.Initialize(); server.Initialize();
server.Bind(DNS::Resolve("localhost"), 65534); server.Bind(DNS::Resolve(server.GetAddressType(), "localhost"), 65534);
server.Listen(); server.Listen();
System::OpenURI(uri); System::OpenURI(uri);

View File

@ -39,7 +39,7 @@ namespace ehs
scopesFinal; scopesFinal;
TCP server(AddrType::IPV4); TCP server(AddrType::IPV4);
server.Bind(DNS::Resolve("localhost"), 65535); server.Bind(DNS::Resolve(client.GetAddressType(), "localhost"), 65535);
server.Listen(); server.Listen();
System::OpenURI(uri); System::OpenURI(uri);

View File

@ -54,7 +54,7 @@ namespace ehs
return; return;
client = TCP(ehs::AddrType::IPV4); client = TCP(ehs::AddrType::IPV4);
client.Connect(DNS::Resolve("irc.chat.twitch.tv"), 6667); client.Connect(DNS::Resolve(AddrType::IPV4, "irc.chat.twitch.tv"), 6667);
client.SetBlocking(false); client.SetBlocking(false);
Str_8 r("PASS oauth:" + token + "\r\n"); Str_8 r("PASS oauth:" + token + "\r\n");