diff --git a/Jupiter.sln b/Jupiter.sln index c4ef9ae..d7352d8 100644 --- a/Jupiter.sln +++ b/Jupiter.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Jupiter", "Jupiter\Jupiter.vcxproj", "{367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}" EndProject @@ -13,18 +13,26 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Debug|Win32.ActiveCfg = Release|Win32 {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Debug|Win32.Build.0 = Release|Win32 {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Debug|Win32.Deploy.0 = Release|Win32 + {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Debug|x64.ActiveCfg = Debug|x64 + {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Debug|x64.Build.0 = Debug|x64 {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Release|Win32.ActiveCfg = Release|Win32 {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Release|Win32.Build.0 = Release|Win32 + {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Release|x64.ActiveCfg = Release|x64 + {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Release|x64.Build.0 = Release|x64 {0F041791-1047-4C6A-A4C1-814E6957D5EB}.Debug|Win32.ActiveCfg = Debug|Win32 {0F041791-1047-4C6A-A4C1-814E6957D5EB}.Debug|Win32.Build.0 = Debug|Win32 + {0F041791-1047-4C6A-A4C1-814E6957D5EB}.Debug|x64.ActiveCfg = Debug|Win32 {0F041791-1047-4C6A-A4C1-814E6957D5EB}.Release|Win32.ActiveCfg = Release|Win32 {0F041791-1047-4C6A-A4C1-814E6957D5EB}.Release|Win32.Build.0 = Release|Win32 + {0F041791-1047-4C6A-A4C1-814E6957D5EB}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Jupiter/ArrayList.h b/Jupiter/ArrayList.h index 7a97439..128bd61 100644 --- a/Jupiter/ArrayList.h +++ b/Jupiter/ArrayList.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2014 Justin James. + * Copyright (C) 2013-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -128,9 +128,9 @@ template Jupiter::ArrayList::ArrayList() : ArrayList(Jupiter::Arr { } -template Jupiter::ArrayList::ArrayList(size_t length) +template Jupiter::ArrayList::ArrayList(size_t length_) { - Jupiter::ArrayList::dataSize = length; + Jupiter::ArrayList::dataSize = length_; Jupiter::ArrayList::data = new T*[Jupiter::ArrayList::dataSize]; Jupiter::List::length = 0; } @@ -186,4 +186,22 @@ template void Jupiter::ArrayList::emptyAndDelete() Jupiter::List::length = 0; } +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::ArrayList *data) + { + _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); + }; + + template static Jupiter::ArrayList interpret(uint8_t *&head) + { + size_t size_ = *reinterpret_cast(head); + head += sizeof(size_t); + Jupiter::ArrayList r = Jupiter::ArrayList(size_); + while (size_-- != 0) + r.add(Jupiter::DataBuffer::interpret_data(head)); + return r; + } +}; + #endif // _ARRAYLIST_H_HEADER \ No newline at end of file diff --git a/Jupiter/Base64.h b/Jupiter/Base64.h index 73fc766..f421198 100644 --- a/Jupiter/Base64.h +++ b/Jupiter/Base64.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014 Justin James. + * Copyright (C) 2014-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -170,6 +170,6 @@ JUPITER_API unsigned int Jupiter_base64decode_s(const char *data, size_t dataLen #if defined __cplusplus } -#endif +#endif // __cplusplus #endif // _BASE64_H_HEADER \ No newline at end of file diff --git a/Jupiter/CString_Imp.h b/Jupiter/CString_Imp.h index fe74de6..f3d51a1 100644 --- a/Jupiter/CString_Imp.h +++ b/Jupiter/CString_Imp.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2014 Justin James. + * Copyright (C) 2013-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -375,6 +375,25 @@ template size_t Jupiter::CString_Type::concat(const T c) template const Jupiter::CString_Type Jupiter::CString_Type::empty = Jupiter::CString_Type(); +// Jupiter::DataBuffer specialization + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::CString_Type *data) + { + _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); + }; + + template static Jupiter::CString_Type interpret(uint8_t *&head) + { + size_t size_ = *reinterpret_cast(head); + head += sizeof(size_t); + Jupiter::CString_Type r = Jupiter::CString_Type(reinterpret_cast(head), size_); + head += size_; + return r; + } +}; + /** * IMPLEMENTATION: * CString_Loose @@ -561,4 +580,23 @@ template Jupiter::CString_Loose Jupiter::CString_Loose::gotoWo template const Jupiter::CString_Loose Jupiter::CString_Loose::empty = Jupiter::CString_Loose(); +// Jupiter::DataBuffer specialization + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::CString_Loose *data) + { + _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); + }; + + template static Jupiter::CString_Loose interpret(uint8_t *&head) + { + size_t size_ = *reinterpret_cast(head); + head += sizeof(size_t); + Jupiter::CString_Loose r = Jupiter::CString_Loose(reinterpret_cast(head), size_); + head += size_; + return r; + } +}; + #endif // _CSTRING_IMP_H_HEADER \ No newline at end of file diff --git a/Jupiter/DLList.h b/Jupiter/DLList.h index d35d84d..561eea4 100644 --- a/Jupiter/DLList.h +++ b/Jupiter/DLList.h @@ -273,4 +273,28 @@ template void Jupiter::DLList::add(T *data) Jupiter::List::length++; } +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::DLList *data) + { + buffer->push(data->size()); + Jupiter::DLList::Node *head = data->getNode(0); + while (head != nullptr) + { + buffer->push(*head->data); + head++; + } + }; + + template static Jupiter::DLList interpret(uint8_t *&head) + { + size_t size_ = *reinterpret_cast(head); + head += sizeof(size_t); + Jupiter::DLList r; + while (size_-- != 0) + r.add(Jupiter::DataBuffer::interpret_data(head)); + return r; + } +}; + #endif // _DLLIST_H_HEADER \ No newline at end of file diff --git a/Jupiter/DataBuffer.cpp b/Jupiter/DataBuffer.cpp new file mode 100644 index 0000000..568d877 --- /dev/null +++ b/Jupiter/DataBuffer.cpp @@ -0,0 +1,121 @@ +/** + * Copyright (C) Justin James - All Rights Reserved. + * Unauthorized use or copying of this file via any medium is strictly prohibited. + * This document is proprietary and confidential. + * This document should be immediately destroyed unless given explicit permission by Justin James. + * Written by Justin James + */ + +#include +#include "DataBuffer.h" +#include "Reference_String.h" + +Jupiter::DataBuffer::DataBuffer() +{ + Jupiter::DataBuffer::base = nullptr; + Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; + Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; + Jupiter::DataBuffer::bufferSize = 0U; +} + +Jupiter::DataBuffer::DataBuffer(size_t size_) +{ + Jupiter::DataBuffer::base = reinterpret_cast(malloc(size_)); + Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; + Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; + Jupiter::DataBuffer::bufferSize = size_; +} + +Jupiter::DataBuffer::~DataBuffer() +{ + free(Jupiter::DataBuffer::base); +} + +void Jupiter::DataBuffer::push(const uint8_t *data, size_t size_) +{ + Jupiter::DataBuffer::secure(size_); + fputs("Pushing: \"", stdout); + while (size_-- != 0) + { + fputc(*data, stdout); + *Jupiter::DataBuffer::end++ = *data++; + } + puts("\""); +} + +size_t Jupiter::DataBuffer::shrink() +{ + Jupiter::DataBuffer::bufferSize = Jupiter::DataBuffer::size(); + + if (Jupiter::DataBuffer::base != Jupiter::DataBuffer::head) + memmove(Jupiter::DataBuffer::base, Jupiter::DataBuffer::head, Jupiter::DataBuffer::bufferSize); + + Jupiter::DataBuffer::base = reinterpret_cast(realloc(Jupiter::DataBuffer::base, Jupiter::DataBuffer::bufferSize)); + Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; + Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + Jupiter::DataBuffer::bufferSize; + return Jupiter::DataBuffer::bufferSize; +} + +size_t Jupiter::DataBuffer::expandBuffer(size_t size_) +{ + Jupiter::DataBuffer::bufferSize += size_; + size_ = Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; + + if (Jupiter::DataBuffer::base != Jupiter::DataBuffer::head) + memmove(Jupiter::DataBuffer::base, Jupiter::DataBuffer::head, size_); + + Jupiter::DataBuffer::base = reinterpret_cast(realloc(Jupiter::DataBuffer::base, Jupiter::DataBuffer::bufferSize)); + Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; + Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + size_; + return Jupiter::DataBuffer::bufferSize; +} + +void Jupiter::DataBuffer::secure(size_t size_) +{ + size_t data_size = Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; + size_ += data_size; + if (Jupiter::DataBuffer::bufferSize < size_) + { + if (Jupiter::DataBuffer::base != Jupiter::DataBuffer::head) + memmove(Jupiter::DataBuffer::base, Jupiter::DataBuffer::head, data_size); + + Jupiter::DataBuffer::base = reinterpret_cast(realloc(Jupiter::DataBuffer::base, size_)); + Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; + Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + data_size; + Jupiter::DataBuffer::bufferSize = size_; + } +} + +void Jupiter::DataBuffer::setBufferSize(size_t size_) +{ + Jupiter::DataBuffer::bufferSize = size_; + size_ = Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; + + if (Jupiter::DataBuffer::base != Jupiter::DataBuffer::head) + memmove(Jupiter::DataBuffer::base, Jupiter::DataBuffer::head, size_); + + Jupiter::DataBuffer::base = reinterpret_cast(realloc(Jupiter::DataBuffer::base, Jupiter::DataBuffer::bufferSize)); + Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; + Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + size_; +} + +size_t Jupiter::DataBuffer::size() const +{ + return Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; +} + +size_t Jupiter::DataBuffer::getBufferSize() const +{ + return Jupiter::DataBuffer::bufferSize; +} + +uint8_t *Jupiter::DataBuffer::getHead() const +{ + return Jupiter::DataBuffer::head; +} + +void Jupiter::DataBuffer::empty() +{ + Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; + Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; +} \ No newline at end of file diff --git a/Jupiter/DataBuffer.h b/Jupiter/DataBuffer.h new file mode 100644 index 0000000..7aa3df3 --- /dev/null +++ b/Jupiter/DataBuffer.h @@ -0,0 +1,216 @@ +/** + * Copyright (C) 2015 Justin James. + * + * This license must be preserved. + * Any applications, libraries, or code which make any use of any + * component of this program must not be commercial, unless explicit + * permission is granted from the original author. The use of this + * program for non-profit purposes is permitted. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * In the event that this license restricts you from making desired use of this program, contact the original author. + * Written by Justin James + */ + +#if !defined _DATABUFFER_H_HEADER +#define _DATABUFFER_H_HEADER + +/** + * @file DataBuffer.h + * @brief Defines a simple data buffer structure. + */ + +#include +#include "Jupiter.h" + +namespace Jupiter +{ + /** + * @brief Provides a data buffer implementation intended for files and sockets. + * DataBuffer behaves as a FIFO single-directional queue. + */ + class JUPITER_API DataBuffer + { + public: + + /** + * @brief Generates an object based on an input head position; the head + * will be moved if the input type can be interpreted. + * + * @return Generated object. + */ + template static T interpret_data(uint8_t *&head); + template class T, typename Y> static T interpret_data(uint8_t *&head); + template class T, typename X, typename Y> static T interpret_data(uint8_t *&head); + template class T, typename X, typename Y, typename Z> static T interpret_data(uint8_t *&head); + + /** + * @brief Copies data from the front of the buffer, without removing it. + * + * @param T Data type + * + * @return Sum of all the elements in the string + */ + template T peek() const; + template class T, typename Y> T peek() const; + template class T, typename X, typename Y> T peek() const; + template class T, typename X, typename Y, typename Z> T peek() const; + + template void peek(T &out) const; + template class T, typename Y> void peek(T &out) const; + template class T, typename X, typename Y> void peek(T &out) const; + template class T, typename X, typename Y, typename Z> void peek(T &out) const; + + /** + * @brief Copies data from the front of the buffer, without removing it. + * Note: Elements will be in the opposite order than concurrent calls + * to peek() would produce. + * + * @param T Data type + * @param size Number of elements to pop + * + * @return Sum of all the elements in the string + */ + template T *peek(size_t size) const; + + /** + * @brief Copies data from the front of the buffer and removes it. + * + * @param T Data type + * + * @return Sum of all the elements in the string + */ + template T pop(); + template class T, typename Y> T pop(); + template class T, typename X, typename Y> T pop(); + template class T, typename X, typename Y, typename Z> T pop(); + + template void pop(T &out); + template class T, typename Y> void pop(T &out); + template class T, typename X, typename Y> void pop(T &out); + template class T, typename X, typename Y, typename Z> void pop(T &out); + + /** + * @brief Copies data from the front of the buffer and removes it. + * Note: Elements will be in the opposite order than concurrent calls + * to pop() would produce. + * + * @param T Data type + * @param size Number of elements to pop + * + * @return Sum of all the elements in the string + */ + template T *pop(size_t size); + + /** + * @brief Adds data to the front of the buffer. + * + * @param T Data type + * @param data Data to add to the buffer + */ + template void push(const T *data); + template void push(const T &data); + + // Specialization: Jupiter::ReadableString + Sub classes + template class T, typename Y> void push(const T *data); + template class T, typename Y> void push(const T &data); + + // SPECIALIZATION TODO: std::deque - std::list - std::forward_list + + // SPECIALIZATION: std::array + template class T, typename X, size_t Y> void push(const T *data); + template class T, typename X, size_t Y> void push(const T &data); + + // SPECIALIZATION: std::vector + template class T, typename X, typename Y> void push(const T *data); + template class T, typename X, typename Y> void push(const T &data); + + // SPECIALIZATION: std::basic_string (std::string / std::wstring / etc) + template class T, typename X, typename Y, typename Z> void push(const T *data); + template class T, typename X, typename Y, typename Z> void push(const T &data); + + /** + * @brief Adds data to the end of the buffer. + * + * @param data Data to add to the buffer + * @param size Number of octets in data to add + */ + void push(const uint8_t *data, size_t size); + + /** + * @brief Shrinks the buffer to the smallest possible size. + * + * @return New size of the buffer in octets. + */ + size_t shrink(); + + /** + * @brief Expands the size of the internal buffer by a set number of octets. + * + * @param size Number of octets to + * @return New size of the buffer in octets. + */ + size_t expandBuffer(size_t size); + + /** + * @brief Guarantees availability for a specified number of octets. + * + * @param size Number of octets to guarantee. + * @return New size of the buffer in octets. + */ + void secure(size_t size); + + /** + * @brief Sets the size of the internal buffer. + * Note: If input 'size' is less than size(), data is removed. + * + * @param size Size to set the buffer to. + * @return New size of the buffer in octets. + */ + void setBufferSize(size_t size); + + /** + * @brief Fetches the size of the data in octets. + * + * @return Size of the data in octets. + */ + size_t size() const; + + /** + * @brief Fetches the size of the buffer in octets. + * + * @return Size of the buffer in octets. + */ + size_t getBufferSize() const; + + /** + * @brief Fetches the head of the buffer + * + * @return Buffer head + */ + uint8_t *getHead() const; + + /** + * @brief Empties the buffer of all elements. + * Note: The internal memory buffer is not freed or reallocated. + */ + void empty(); + + DataBuffer(); + DataBuffer(size_t size); + ~DataBuffer(); + + private: + uint8_t *base; + uint8_t *head; + uint8_t *end; + size_t bufferSize; + }; +} + +#include "DataBuffer_Imp.h" + +#endif // _DATABUFFER_H_HEADER \ No newline at end of file diff --git a/Jupiter/DataBuffer_Imp.h b/Jupiter/DataBuffer_Imp.h new file mode 100644 index 0000000..ab67f1a --- /dev/null +++ b/Jupiter/DataBuffer_Imp.h @@ -0,0 +1,350 @@ +/** + * Copyright (C) 2015 Justin James. + * + * This license must be preserved. + * Any applications, libraries, or code which make any use of any + * component of this program must not be commercial, unless explicit + * permission is granted from the original author. The use of this + * program for non-profit purposes is permitted. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * In the event that this license restricts you from making desired use of this program, contact the original author. + * Written by Justin James + */ + +#if !defined _DATABUFFER_IMP_H_HEADER +#define _DATABUFFER_IMP_H_HEADER + +/** + * @file DataBuffer_Imp.h + * @brief Provides the implementations for DataBuffer template functions. + * Note: Modification of this file is not supported in any way. + */ + +#include +#include + +/** +* IMPLEMENTATION: +* DataBuffer +*/ + +template T Jupiter::DataBuffer::interpret_data(uint8_t *&head) +{ + T r = T(*(reinterpret_cast(head))); + head += sizeof(T); + return r; +} + +template class T, typename Y> static T interpret_data(uint8_t *&head) +{ + return _Jupiter_DataBuffer_partial_specialization_impl_std::interpret(head); +} + +template class T, typename X, typename Y> static T interpret_data(uint8_t *&head) +{ + return _Jupiter_DataBuffer_partial_specialization_impl_std_vector::interpret(head); +} + +template class T, typename X, typename Y, typename Z> static T interpret_data(uint8_t *&head) +{ + return _Jupiter_DataBuffer_partial_specialization_impl_std_string::interpret(head); +} + +// Basic peek + +template T Jupiter::DataBuffer::peek() const +{ + uint8_t *ptr = Jupiter::DataBuffer::head; + return Jupiter::DataBuffer::interpret_data(ptr); +} + +template class T, typename Y> T Jupiter::DataBuffer::peek() const +{ + uint8_t *ptr = Jupiter::DataBuffer::head; + return Jupiter::DataBuffer::interpret_data(ptr); +} + +template class T, typename X, typename Y> T Jupiter::DataBuffer::peek() const +{ + uint8_t *ptr = Jupiter::DataBuffer::head; + return Jupiter::DataBuffer::interpret_data(ptr); +} + +template class T, typename X, typename Y, typename Z> T Jupiter::DataBuffer::peek() const +{ + uint8_t *ptr = Jupiter::DataBuffer::head; + return Jupiter::DataBuffer::interpret_data(ptr); +} + +template void Jupiter::DataBuffer::peek(T &out) const +{ + out = Jupiter::DataBuffer::peek(); +} + +template class T, typename Y> void Jupiter::DataBuffer::peek(T &out) const +{ + out = Jupiter::DataBuffer::peek(); +} + +template class T, typename X, typename Y> void Jupiter::DataBuffer::peek(T &out) const +{ + out = Jupiter::DataBuffer::peek(); +} + +template class T, typename X, typename Y, typename Z> void Jupiter::DataBuffer::peek(T &out) const +{ + out = Jupiter::DataBuffer::peek(); +} + +template T *Jupiter::DataBuffer::peek(size_t size_) const +{ + uint8_t *ptr = Jupiter::DataBuffer::head; + T *r = new T[size_]; + T *itr = r; + while (size_-- != 0) + *itr++ = Jupiter::DataBuffer::interpret_data(ptr); + return r; +} + +// Basic pop + +template T Jupiter::DataBuffer::pop() +{ + return Jupiter::DataBuffer::interpret_data(Jupiter::DataBuffer::head); +} + +template class T, typename Y> T Jupiter::DataBuffer::pop() +{ + return Jupiter::DataBuffer::interpret_data(Jupiter::DataBuffer::head); +} + +template class T, typename X, typename Y> T Jupiter::DataBuffer::pop() +{ + return Jupiter::DataBuffer::interpret_data(Jupiter::DataBuffer::head); +} + +template class T, typename X, typename Y, typename Z> T Jupiter::DataBuffer::pop() +{ + return Jupiter::DataBuffer::interpret_data(Jupiter::DataBuffer::head); +} + +template void Jupiter::DataBuffer::pop(T &out) +{ + out = Jupiter::DataBuffer::pop(); +} + +template class T, typename Y> void Jupiter::DataBuffer::pop(T &out) +{ + out = Jupiter::DataBuffer::pop(); +} + +template class T, typename X, typename Y> void Jupiter::DataBuffer::pop(T &out) +{ + out = Jupiter::DataBuffer::pop(); +} + +template class T, typename X, typename Y, typename Z> void Jupiter::DataBuffer::pop(T &out) +{ + out = Jupiter::DataBuffer::pop(); +} + +template T *Jupiter::DataBuffer::pop(size_t size_) +{ + T *r = new T[size_]; + T *itr = r; + while (size_-- != 0) + *itr++ = Jupiter::DataBuffer::interpret_data(Jupiter::DataBuffer::head); + return r; +} + +// Basic push + +template void Jupiter::DataBuffer::push(const T *data) +{ + Jupiter::DataBuffer::secure(sizeof(T)); + *reinterpret_cast(Jupiter::DataBuffer::end) = *data; + Jupiter::DataBuffer::end += sizeof(T); +} + +template void Jupiter::DataBuffer::push(const T &data) +{ + Jupiter::DataBuffer::push(&data); +} + +// SPECIALIZATION: Jupiter::DataBuffer + +template<> void inline Jupiter::DataBuffer::push(const Jupiter::DataBuffer *data) +{ + size_t size_ = data->size(); + Jupiter::DataBuffer::secure(sizeof(size_t) + size_); + Jupiter::DataBuffer::push(size_); + Jupiter::DataBuffer::push(data->getHead(), size_); +} + +template<> Jupiter::DataBuffer inline Jupiter::DataBuffer::interpret_data(uint8_t *&head_) +{ + size_t size_ = *reinterpret_cast(head_); + head_ += sizeof(size_t); + Jupiter::DataBuffer r = Jupiter::DataBuffer(size_); + while (size_-- != 0) + *r.end++ = *head_++; + return r; +} + +// template / string push + +template class T> struct _Jupiter_DataBuffer_partial_specialization_impl +{ +}; + +template class T, typename Y> void Jupiter::DataBuffer::push(const T *data) +{ + _Jupiter_DataBuffer_partial_specialization_impl::push(this, data); +} + +template class T, typename Y> void Jupiter::DataBuffer::push(const T &data) +{ + Jupiter::DataBuffer::push(&data); +} + +template class T, typename Y> T Jupiter::DataBuffer::interpret_data(uint8_t *&head) +{ + return _Jupiter_DataBuffer_partial_specialization_impl::interpret(head); +} + +// PUSH SPECIALIZATION: std::array + +template class T> struct _Jupiter_DataBuffer_partial_specialization_impl_std_array +{ +}; + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl_std_array +{ + template static void push(Jupiter::DataBuffer *buffer, const std::array *data) + { + buffer->push(Y); + if (std::is_fundamental::value_type>::value) + buffer->push(reinterpret_cast(data->data()), data->size() * sizeof(std::array::value_type)); + else + { + std::array::const_iterator itr = data->begin(); + std::array::const_iterator end = data->end(); + while (itr != end) + buffer->push::value_type>(*itr++); + } + }; +}; + +template class T, typename X, size_t Y> void Jupiter::DataBuffer::push(const T *data) +{ + _Jupiter_DataBuffer_partial_specialization_impl_std_array::push(this, data); +} + +template class T, typename X, size_t Y> void Jupiter::DataBuffer::push(const T &data) +{ + Jupiter::DataBuffer::push(&data); +} + +// SPECIALIZATION: std::vector + +template class T> struct _Jupiter_DataBuffer_partial_specialization_impl_std_vector +{ +}; + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl_std_vector +{ + template static void push(Jupiter::DataBuffer *buffer, const std::vector *data) + { + buffer->push::size_type>(data->size()); + if (std::is_fundamental::value_type>::value) + buffer->push(reinterpret_cast(data->data()), data->size() * sizeof(std::vector::value_type)); + else + { + std::vector::const_iterator itr = data->begin(); + std::vector::const_iterator end = data->end(); + while (itr != end) + buffer->push::value_type>(*itr++); + } + }; + + template static std::vector interpret(uint8_t *&head) + { + size_t size_ = *reinterpret_cast(head); + head += sizeof(size_t); + std::vector r; + r.reserve(size_); + while (size_-- != 0) + r.push_back(Jupiter::DataBuffer::interpret_data::value_type>(head)); + return r; + } +}; + +template class T, typename X, typename Y> void Jupiter::DataBuffer::push(const T *data) +{ + _Jupiter_DataBuffer_partial_specialization_impl_std_vector::push(this, data); +} + +template class T, typename X, typename Y> void Jupiter::DataBuffer::push(const T &data) +{ + Jupiter::DataBuffer::push(&data); +} + +template class T, typename X, typename Y> T Jupiter::DataBuffer::interpret_data(uint8_t *&head) +{ + return _Jupiter_DataBuffer_partial_specialization_impl_std_vector::interpret(head); +} + +// SPECIALIZATION: std::string + +template class T> struct _Jupiter_DataBuffer_partial_specialization_impl_std_string +{ +}; + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl_std_string +{ + template static void push(Jupiter::DataBuffer *buffer, const std::basic_string *data) + { + buffer->push(data->size()); + if (std::is_fundamental::value_type>::value) + buffer->push(reinterpret_cast(data->data()), data->size() * sizeof(X)); + else + { + std::basic_string::const_iterator itr = data->begin(); + std::basic_string::const_iterator end = data->end(); + while (itr != end) + buffer->push::value_type>(*itr++); + } + }; + + template static std::basic_string interpret(uint8_t *&head) + { + size_t size_ = *reinterpret_cast(head); + head += sizeof(size_t); + std::basic_string r; + r.reserve(size_); + while (size_-- != 0) + r.push_back(Jupiter::DataBuffer::interpret_data::value_type>(head)); + return r; + } +}; + +template class T, typename X, typename Y, typename Z> void Jupiter::DataBuffer::push(const T *data) +{ + _Jupiter_DataBuffer_partial_specialization_impl_std_string::push(this, data); +} + +template class T, typename X, typename Y, typename Z> void Jupiter::DataBuffer::push(const T &data) +{ + Jupiter::DataBuffer::push(&data); +} + +template class T, typename X, typename Y, typename Z> T Jupiter::DataBuffer::interpret_data(uint8_t *&head) +{ + return _Jupiter_DataBuffer_partial_specialization_impl_std_string::interpret(head); +} + +#endif // _DATABUFFER_IMP_H_HEADER \ No newline at end of file diff --git a/Jupiter/Jupiter.vcxproj b/Jupiter/Jupiter.vcxproj index b32e5a2..b734a82 100644 --- a/Jupiter/Jupiter.vcxproj +++ b/Jupiter/Jupiter.vcxproj @@ -5,10 +5,18 @@ Debug Win32 + + Debug + x64 + Release Win32 + + Release + x64 + {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8} @@ -23,6 +31,12 @@ Unicode v120 + + Application + true + Unicode + v120 + DynamicLibrary false @@ -30,19 +44,35 @@ Unicode v120 + + DynamicLibrary + false + true + Unicode + v120 + + + + + + + true + + true + false false @@ -50,6 +80,13 @@ C:\dev\OpenSSL\Win32\lib;$(LibraryPath) AllRules.ruleset + + false + false + C:\dev\OpenSSL\Win32\include;$(IncludePath) + C:\dev\OpenSSL\Win32\lib;$(LibraryPath) + AllRules.ruleset + NotUsing @@ -62,7 +99,51 @@ true + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + + + Console + true + + + + Level4 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;JUPITER_EXPORTS;%(PreprocessorDefinitions) + false + %(AdditionalIncludeDirectories) + Async + Speed + 4505 + true + + + Console + true + true + true + NotSet + 0.0 + MachineX86 + + + + + + + %(AdditionalIncludeDirectories) + + + Level4 NotUsing @@ -97,12 +178,16 @@ + + + + @@ -112,6 +197,9 @@ + + + @@ -119,8 +207,12 @@ + + + + diff --git a/Jupiter/Jupiter.vcxproj.filters b/Jupiter/Jupiter.vcxproj.filters index 1a6b281..436b71b 100644 --- a/Jupiter/Jupiter.vcxproj.filters +++ b/Jupiter/Jupiter.vcxproj.filters @@ -46,6 +46,9 @@ {37b5eaf6-0e4f-4609-8518-1b72f93aebe5} + + {aef2e303-8a68-4cf9-8464-c4aef776d3f3} + @@ -102,6 +105,27 @@ Source Files\IRC + + Source Files\Files + + + Source Files\Files + + + Source Files\Files + + + Source Files\Files + + + Source Files\Files + + + Source Files + + + Source Files + @@ -215,6 +239,18 @@ Header Files\Strings + + Header Files + + + Header Files\Files + + + Header Files\DataBuffer + + + Header Files\DataBuffer + diff --git a/Jupiter/List.h b/Jupiter/List.h index 972c737..ab0fbaf 100644 --- a/Jupiter/List.h +++ b/Jupiter/List.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2014 Justin James. + * Copyright (C) 2013-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -24,6 +24,7 @@ */ #include "Jupiter.h" +#include "DataBuffer.h" namespace Jupiter { @@ -74,4 +75,14 @@ namespace Jupiter }; } +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::List *data) + { + buffer->push(data->size()); + for (size_t index = 0; index != data->size(); index++) + buffer->push(*data->get(index)); + }; +}; + #endif // _LIST_H_HEADER \ No newline at end of file diff --git a/Jupiter/Readable_String.h b/Jupiter/Readable_String.h index 5459e50..21b15cc 100644 --- a/Jupiter/Readable_String.h +++ b/Jupiter/Readable_String.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014 Justin James. + * Copyright (C) 2014-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -27,6 +27,7 @@ #include // FILE #include // std::basic_string type #include "InvalidIndex.h" +#include "DataBuffer.h" namespace Jupiter { diff --git a/Jupiter/Readable_String_Imp.h b/Jupiter/Readable_String_Imp.h index 2a03f4c..71708f1 100644 --- a/Jupiter/Readable_String_Imp.h +++ b/Jupiter/Readable_String_Imp.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014 Justin James. + * Copyright (C) 2014-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -1266,4 +1266,16 @@ template template class R> R Jupiter::Readable return R(); } +// Jupiter::DataBuffer specialization + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::Readable_String *data) + { + buffer->secure(sizeof(size_t) + data->size() * sizeof(Y)); + buffer->push(data->size()); + buffer->push(reinterpret_cast(data->ptr()), data->size() * sizeof(Y)); + }; +}; + #endif // _READABLE_STRING_IMP_H_HEADER \ No newline at end of file diff --git a/Jupiter/Reference_String.h b/Jupiter/Reference_String.h index 63078f3..5b4fb59 100644 --- a/Jupiter/Reference_String.h +++ b/Jupiter/Reference_String.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014 Justin James. + * Copyright (C) 2014-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -269,6 +269,11 @@ namespace Jupiter */ Reference_String(const Jupiter::Reference_String &in); + /** + * @brief Conversion constructor for Jupiter::DataBuffer class. + */ + Reference_String(const Jupiter::DataBuffer &in); + static const Jupiter::Reference_String empty; /** Empty instantiation of Reference_String */ protected: diff --git a/Jupiter/Reference_String_Imp.h b/Jupiter/Reference_String_Imp.h index 7d4d649..3cb4b21 100644 --- a/Jupiter/Reference_String_Imp.h +++ b/Jupiter/Reference_String_Imp.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014 Justin James. + * Copyright (C) 2014-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -65,6 +65,10 @@ template Jupiter::Reference_String::Reference_String(const Jupite { } +template Jupiter::Reference_String::Reference_String(const Jupiter::DataBuffer &in) : Reference_String(reinterpret_cast(in.getHead()), in.size() / sizeof(T)) +{ +} + template const T &Jupiter::Reference_String::get(size_t index) const { return Jupiter::Reference_String::str[index]; @@ -233,4 +237,23 @@ template Jupiter::Reference_String Jupiter::Reference_String:: template const Jupiter::Reference_String Jupiter::Reference_String::empty = Jupiter::Reference_String(); +// Jupiter::DataBuffer specialization + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::Reference_String *data) + { + _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); + }; + + template static Jupiter::Reference_String interpret(uint8_t *&head) + { + size_t size_ = *reinterpret_cast(head); + head += sizeof(size_t); + Jupiter::Reference_String r = Jupiter::Reference_String(reinterpret_cast(head), size_); + head += size_; + return r; + } +}; + #endif // _REFERENCE_STRING_IMP \ No newline at end of file diff --git a/Jupiter/SLList.h b/Jupiter/SLList.h index 95190db..3040520 100644 --- a/Jupiter/SLList.h +++ b/Jupiter/SLList.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2014 Justin James. + * Copyright (C) 2013-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -213,4 +213,25 @@ template void Jupiter::SLList::add(T *data) Jupiter::List::length++; } +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::SLList *data) + { + buffer->push(data->size()); + Jupiter::SLList::Node *head = data->getNode(0); + while (head != nullptr) + buffer->push(*head++->data); + }; + + template static Jupiter::SLList interpret(uint8_t *&head) + { + size_t size_ = *reinterpret_cast(head); + head += sizeof(size_t); + Jupiter::SLList r; + while (size_-- != 0) + r.add(Jupiter::DataBuffer::interpret_data(head)); + return r; + } +}; + #endif // _SLLIST_H_HEADER \ No newline at end of file diff --git a/Jupiter/Shift_String_Imp.h b/Jupiter/Shift_String_Imp.h index 41564e6..6fda85b 100644 --- a/Jupiter/Shift_String_Imp.h +++ b/Jupiter/Shift_String_Imp.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2014 Justin James. + * Copyright (C) 2014-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -93,4 +93,14 @@ template bool Jupiter::Shift_String_Type::setBufferSizeNoCopy(siz return false; } +// Jupiter::DataBuffer specialization + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::Shift_String_Type *data) + { + _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); + }; +}; + #endif // _SHIFT_STRING_IMP_H_HEADER \ No newline at end of file diff --git a/Jupiter/String.h b/Jupiter/String.h index ef05285..ff0bd41 100644 --- a/Jupiter/String.h +++ b/Jupiter/String.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2014 Justin James. + * Copyright (C) 2013-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -221,11 +221,12 @@ namespace Jupiter String_Strict(String_Strict &&source); /** Copy Constructors */ - String_Strict(const String_Strict &in) : String_Strict((Readable_String &)in) {} + String_Strict(const String_Strict &in); String_Strict(const Readable_String &in); String_Strict(const std::basic_string &in); String_Strict(const T *in, size_t len); String_Strict(const T *in); + String_Strict(const Jupiter::DataBuffer &in); protected: @@ -422,6 +423,7 @@ namespace Jupiter String_Loose(const std::basic_string &in); String_Loose(const T *in, size_t len); String_Loose(const T *in); + String_Loose(const Jupiter::DataBuffer &in); static const Jupiter::String_Loose empty; /** Empty instantation of String_Loose */ static const size_t start_size = 8; /** Starting size for loose Strings. */ diff --git a/Jupiter/String_Imp.h b/Jupiter/String_Imp.h index 3b0e181..9b65847 100644 --- a/Jupiter/String_Imp.h +++ b/Jupiter/String_Imp.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013-2014 Justin James. + * Copyright (C) 2013-2015 Justin James. * * This license must be preserved. * Any applications, libraries, or code which make any use of any @@ -57,6 +57,10 @@ template Jupiter::String_Strict::String_Strict(Jupiter::String_St { } +template Jupiter::String_Strict::String_Strict(const Jupiter::String_Strict &in) : Jupiter::String_Strict::String_Strict(in.ptr(), in.size()) +{ +} + template Jupiter::String_Strict::String_Strict(const Jupiter::Readable_String &in) : Jupiter::String_Strict::String_Strict(in.ptr(), in.size()) { } @@ -85,6 +89,10 @@ template Jupiter::String_Strict::String_Strict(const T *in) for (size_t index = 0; index != Jupiter::String_Type::length; index++, in++) Jupiter::String_Type::str[index] = *in; } +template Jupiter::String_Strict::String_Strict(const Jupiter::DataBuffer &in) : String_Strict(reinterpret_cast(in.getHead()), in.size() / sizeof(T)) +{ +} + // vformat() template<> size_t inline Jupiter::String_Strict::vformat(const char *format, va_list args) @@ -268,6 +276,25 @@ template Jupiter::String_Strict Jupiter::String_Strict::gotoTo template const Jupiter::String_Strict Jupiter::String_Strict::empty = Jupiter::String_Strict(); +// Jupiter::DataBuffer specialization + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Strict *data) + { + _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); + }; + + template static Jupiter::String_Strict interpret(uint8_t *&head) + { + size_t size_ = *reinterpret_cast(head); + head += sizeof(size_t); + Jupiter::String_Strict r = Jupiter::String_Strict(reinterpret_cast(head), size_); + head += size_; + return r; + } +}; + /** * IMPLEMENTATION: * String_Loose @@ -342,6 +369,10 @@ template Jupiter::String_Loose::String_Loose(const T *in) } } +template Jupiter::String_Loose::String_Loose(const Jupiter::DataBuffer &in) : String_Loose(reinterpret_cast(in.getHead()), in.size() / sizeof(T)) +{ +} + template bool Jupiter::String_Loose::setBufferSize(size_t len) { return Jupiter::Shift_String_Type::setBufferSize(Jupiter::String_Loose::strSize = getPowerTwo32(len)); @@ -535,4 +566,23 @@ template Jupiter::String_Loose Jupiter::String_Loose::gotoToke template const Jupiter::String_Loose Jupiter::String_Loose::empty = Jupiter::String_Loose(); +// Jupiter::DataBuffer specialization + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Loose *data) + { + _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); + }; + + template static Jupiter::String_Loose interpret(uint8_t *&head) + { + size_t size_ = *reinterpret_cast(head); + head += sizeof(size_t); + Jupiter::String_Loose r = Jupiter::String_Loose(reinterpret_cast(head), size_); + head += size_; + return r; + } +}; + #endif // _STRING_IMP_H_HEADER \ No newline at end of file diff --git a/Jupiter/String_Type.h b/Jupiter/String_Type.h index 56c4eba..27a6401 100644 --- a/Jupiter/String_Type.h +++ b/Jupiter/String_Type.h @@ -224,6 +224,7 @@ namespace Jupiter * A copy constructor for std::basic_string. * A copy constructor for C-style strings. * A copy constructor for memory array strings. + * A conversion constructor for Jupiter::DataBuffer */ protected: diff --git a/Jupiter/String_Type_Imp.h b/Jupiter/String_Type_Imp.h index 2785793..4b91d87 100644 --- a/Jupiter/String_Type_Imp.h +++ b/Jupiter/String_Type_Imp.h @@ -511,4 +511,14 @@ namespace Jupiter static struct String_Constructor_Base {} stringConstructorBase; } +// Jupiter::DataBuffer specialization + +template<> struct _Jupiter_DataBuffer_partial_specialization_impl +{ + template static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Type *data) + { + _Jupiter_DataBuffer_partial_specialization_impl::push(buffer, data); + }; +}; + #endif // _STRING_TYPE_IMP_H_HEADER \ No newline at end of file diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index 386614f..5d13d17 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ