Browse Source

Added Jupiter::DataBuffer and appropriate specializations

release/0.19
JustinAJ 10 years ago
parent
commit
95e4c5c826
  1. 10
      Jupiter.sln
  2. 24
      Jupiter/ArrayList.h
  3. 4
      Jupiter/Base64.h
  4. 40
      Jupiter/CString_Imp.h
  5. 24
      Jupiter/DLList.h
  6. 121
      Jupiter/DataBuffer.cpp
  7. 216
      Jupiter/DataBuffer.h
  8. 350
      Jupiter/DataBuffer_Imp.h
  9. 92
      Jupiter/Jupiter.vcxproj
  10. 36
      Jupiter/Jupiter.vcxproj.filters
  11. 13
      Jupiter/List.h
  12. 3
      Jupiter/Readable_String.h
  13. 14
      Jupiter/Readable_String_Imp.h
  14. 7
      Jupiter/Reference_String.h
  15. 25
      Jupiter/Reference_String_Imp.h
  16. 23
      Jupiter/SLList.h
  17. 12
      Jupiter/Shift_String_Imp.h
  18. 6
      Jupiter/String.h
  19. 52
      Jupiter/String_Imp.h
  20. 1
      Jupiter/String_Type.h
  21. 10
      Jupiter/String_Type_Imp.h
  22. BIN
      Release/Jupiter.lib

10
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

24
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<typename T> Jupiter::ArrayList<T>::ArrayList() : ArrayList(Jupiter::Arr
{
}
template<typename T> Jupiter::ArrayList<T>::ArrayList(size_t length)
template<typename T> Jupiter::ArrayList<T>::ArrayList(size_t length_)
{
Jupiter::ArrayList<T>::dataSize = length;
Jupiter::ArrayList<T>::dataSize = length_;
Jupiter::ArrayList<T>::data = new T*[Jupiter::ArrayList<T>::dataSize];
Jupiter::List<T>::length = 0;
}
@ -186,4 +186,22 @@ template<typename T> void Jupiter::ArrayList<T>::emptyAndDelete()
Jupiter::List<T>::length = 0;
}
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::ArrayList>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::ArrayList<Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::List>::push<Y>(buffer, data);
};
template<typename Y> static Jupiter::ArrayList<Y> interpret(uint8_t *&head)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
Jupiter::ArrayList<Y> r = Jupiter::ArrayList<Y>(size_);
while (size_-- != 0)
r.add(Jupiter::DataBuffer::interpret_data<Y>(head));
return r;
}
};
#endif // _ARRAYLIST_H_HEADER

4
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

40
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<typename T> size_t Jupiter::CString_Type<T>::concat(const T c)
template<typename T> const Jupiter::CString_Type<T> Jupiter::CString_Type<T>::empty = Jupiter::CString_Type<T>();
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::CString_Type>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::CString_Type<Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data);
};
template<typename Y> static Jupiter::CString_Type<Y> interpret(uint8_t *&head)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
Jupiter::CString_Type<Y> r = Jupiter::CString_Type<Y>(reinterpret_cast<T *>(head), size_);
head += size_;
return r;
}
};
/**
* IMPLEMENTATION:
* CString_Loose
@ -561,4 +580,23 @@ template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::gotoWo
template<typename T> const Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::empty = Jupiter::CString_Loose<T>();
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::CString_Loose>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::CString_Loose<Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data);
};
template<typename Y> static Jupiter::CString_Loose<Y> interpret(uint8_t *&head)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
Jupiter::CString_Loose<Y> r = Jupiter::CString_Loose<Y>(reinterpret_cast<T *>(head), size_);
head += size_;
return r;
}
};
#endif // _CSTRING_IMP_H_HEADER

24
Jupiter/DLList.h

@ -273,4 +273,28 @@ template<typename T> void Jupiter::DLList<T>::add(T *data)
Jupiter::List<T>::length++;
}
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::DLList>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::DLList<Y> *data)
{
buffer->push<size_t>(data->size());
Jupiter::DLList<Y>::Node *head = data->getNode(0);
while (head != nullptr)
{
buffer->push<Y>(*head->data);
head++;
}
};
template<typename Y> static Jupiter::DLList<Y> interpret(uint8_t *&head)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
Jupiter::DLList<Y> r;
while (size_-- != 0)
r.add(Jupiter::DataBuffer::interpret_data<Y>(head));
return r;
}
};
#endif // _DLLIST_H_HEADER

121
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 <justin.aj@hotmail.com>
*/
#include <cstdlib>
#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<uint8_t *>(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<uint8_t *>(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<uint8_t *>(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<uint8_t *>(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<uint8_t *>(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;
}

216
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 <justin.aj@hotmail.com>
*/
#if !defined _DATABUFFER_H_HEADER
#define _DATABUFFER_H_HEADER
/**
* @file DataBuffer.h
* @brief Defines a simple data buffer structure.
*/
#include <cstdint>
#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<typename T> static T interpret_data(uint8_t *&head);
template<template<typename> class T, typename Y> static T<Y> interpret_data(uint8_t *&head);
template<template<typename, typename> class T, typename X, typename Y> static T<X, Y> interpret_data(uint8_t *&head);
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> static T<X, Y, Z> 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<typename T> T peek() const;
template<template<typename> class T, typename Y> T<Y> peek() const;
template<template<typename, typename> class T, typename X, typename Y> T<X, Y> peek() const;
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> T<X, Y, Z> peek() const;
template<typename T> void peek(T &out) const;
template<template<typename> class T, typename Y> void peek(T<Y> &out) const;
template<template<typename, typename> class T, typename X, typename Y> void peek(T<X, Y> &out) const;
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> void peek(T<X, Y, Z> &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<typename T> 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<typename T> T pop();
template<template<typename> class T, typename Y> T<Y> pop();
template<template<typename, typename> class T, typename X, typename Y> T<X, Y> pop();
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> T<X, Y, Z> pop();
template<typename T> void pop(T &out);
template<template<typename> class T, typename Y> void pop(T<Y> &out);
template<template<typename, typename> class T, typename X, typename Y> void pop(T<X, Y> &out);
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> void pop(T<X, Y, Z> &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<typename T> 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<typename T> void push(const T *data);
template<typename T> void push(const T &data);
// Specialization: Jupiter::ReadableString + Sub classes
template<template<typename> class T, typename Y> void push(const T<Y> *data);
template<template<typename> class T, typename Y> void push(const T<Y> &data);
// SPECIALIZATION TODO: std::deque - std::list - std::forward_list
// SPECIALIZATION: std::array
template<template<typename, size_t> class T, typename X, size_t Y> void push(const T<X, Y> *data);
template<template<typename, size_t> class T, typename X, size_t Y> void push(const T<X, Y> &data);
// SPECIALIZATION: std::vector
template<template<typename, typename> class T, typename X, typename Y> void push(const T<X, Y> *data);
template<template<typename, typename> class T, typename X, typename Y> void push(const T<X, Y> &data);
// SPECIALIZATION: std::basic_string (std::string / std::wstring / etc)
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> void push(const T<X, Y, Z> *data);
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> void push(const T<X, Y, Z> &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

350
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 <justin.aj@hotmail.com>
*/
#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 <vector>
#include <array>
/**
* IMPLEMENTATION:
* DataBuffer
*/
template<typename T> T Jupiter::DataBuffer::interpret_data(uint8_t *&head)
{
T r = T(*(reinterpret_cast<T *>(head)));
head += sizeof(T);
return r;
}
template<template<typename> class T, typename Y> static T<Y> interpret_data(uint8_t *&head)
{
return _Jupiter_DataBuffer_partial_specialization_impl_std<T>::interpret<Y>(head);
}
template<template<typename, typename> class T, typename X, typename Y> static T<X, Y> interpret_data(uint8_t *&head)
{
return _Jupiter_DataBuffer_partial_specialization_impl_std_vector<T>::interpret<X, Y>(head);
}
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> static T<X, Y, Z> interpret_data(uint8_t *&head)
{
return _Jupiter_DataBuffer_partial_specialization_impl_std_string<T>::interpret<X, Y, Z>(head);
}
// Basic peek
template<typename T> T Jupiter::DataBuffer::peek() const
{
uint8_t *ptr = Jupiter::DataBuffer::head;
return Jupiter::DataBuffer::interpret_data<T>(ptr);
}
template<template<typename> class T, typename Y> T<Y> Jupiter::DataBuffer::peek() const
{
uint8_t *ptr = Jupiter::DataBuffer::head;
return Jupiter::DataBuffer::interpret_data<T, Y>(ptr);
}
template<template<typename, typename> class T, typename X, typename Y> T<X, Y> Jupiter::DataBuffer::peek() const
{
uint8_t *ptr = Jupiter::DataBuffer::head;
return Jupiter::DataBuffer::interpret_data<T, X, Y>(ptr);
}
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> T<X, Y, Z> Jupiter::DataBuffer::peek() const
{
uint8_t *ptr = Jupiter::DataBuffer::head;
return Jupiter::DataBuffer::interpret_data<T, X, Y, Z>(ptr);
}
template<typename T> void Jupiter::DataBuffer::peek(T &out) const
{
out = Jupiter::DataBuffer::peek<T>();
}
template<template<typename> class T, typename Y> void Jupiter::DataBuffer::peek(T<Y> &out) const
{
out = Jupiter::DataBuffer::peek<T, Y>();
}
template<template<typename, typename> class T, typename X, typename Y> void Jupiter::DataBuffer::peek(T<X, Y> &out) const
{
out = Jupiter::DataBuffer::peek<T, X, Y>();
}
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> void Jupiter::DataBuffer::peek(T<X, Y, Z> &out) const
{
out = Jupiter::DataBuffer::peek<T, X, Y, Z>();
}
template<typename T> 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<T>(ptr);
return r;
}
// Basic pop
template<typename T> T Jupiter::DataBuffer::pop()
{
return Jupiter::DataBuffer::interpret_data<T>(Jupiter::DataBuffer::head);
}
template<template<typename> class T, typename Y> T<Y> Jupiter::DataBuffer::pop()
{
return Jupiter::DataBuffer::interpret_data<T, Y>(Jupiter::DataBuffer::head);
}
template<template<typename, typename> class T, typename X, typename Y> T<X, Y> Jupiter::DataBuffer::pop()
{
return Jupiter::DataBuffer::interpret_data<T, X, Y>(Jupiter::DataBuffer::head);
}
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> T<X, Y, Z> Jupiter::DataBuffer::pop()
{
return Jupiter::DataBuffer::interpret_data<T, X, Y, Z>(Jupiter::DataBuffer::head);
}
template<typename T> void Jupiter::DataBuffer::pop(T &out)
{
out = Jupiter::DataBuffer::pop<T>();
}
template<template<typename> class T, typename Y> void Jupiter::DataBuffer::pop(T<Y> &out)
{
out = Jupiter::DataBuffer::pop<T, Y>();
}
template<template<typename, typename> class T, typename X, typename Y> void Jupiter::DataBuffer::pop(T<X, Y> &out)
{
out = Jupiter::DataBuffer::pop<T, X, Y>();
}
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> void Jupiter::DataBuffer::pop(T<X, Y, Z> &out)
{
out = Jupiter::DataBuffer::pop<T, X, Y, Z>();
}
template<typename T> T *Jupiter::DataBuffer::pop(size_t size_)
{
T *r = new T[size_];
T *itr = r;
while (size_-- != 0)
*itr++ = Jupiter::DataBuffer::interpret_data<T>(Jupiter::DataBuffer::head);
return r;
}
// Basic push
template<typename T> void Jupiter::DataBuffer::push(const T *data)
{
Jupiter::DataBuffer::secure(sizeof(T));
*reinterpret_cast<T *>(Jupiter::DataBuffer::end) = *data;
Jupiter::DataBuffer::end += sizeof(T);
}
template<typename T> void Jupiter::DataBuffer::push(const T &data)
{
Jupiter::DataBuffer::push<T>(&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_t>(size_);
Jupiter::DataBuffer::push(data->getHead(), size_);
}
template<> Jupiter::DataBuffer inline Jupiter::DataBuffer::interpret_data(uint8_t *&head_)
{
size_t size_ = *reinterpret_cast<size_t *>(head_);
head_ += sizeof(size_t);
Jupiter::DataBuffer r = Jupiter::DataBuffer(size_);
while (size_-- != 0)
*r.end++ = *head_++;
return r;
}
// template / string push
template<template<typename> class T> struct _Jupiter_DataBuffer_partial_specialization_impl
{
};
template<template<typename> class T, typename Y> void Jupiter::DataBuffer::push(const T<Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl<T>::push<Y>(this, data);
}
template<template<typename> class T, typename Y> void Jupiter::DataBuffer::push(const T<Y> &data)
{
Jupiter::DataBuffer::push<T, Y>(&data);
}
template<template<typename> class T, typename Y> T<Y> Jupiter::DataBuffer::interpret_data(uint8_t *&head)
{
return _Jupiter_DataBuffer_partial_specialization_impl<T>::interpret<Y>(head);
}
// PUSH SPECIALIZATION: std::array
template<template<typename, size_t> class T> struct _Jupiter_DataBuffer_partial_specialization_impl_std_array
{
};
template<> struct _Jupiter_DataBuffer_partial_specialization_impl_std_array<std::array>
{
template<typename X, size_t Y> static void push(Jupiter::DataBuffer *buffer, const std::array<X, Y> *data)
{
buffer->push<size_t>(Y);
if (std::is_fundamental<std::array<X, Y>::value_type>::value)
buffer->push(reinterpret_cast<const uint8_t *>(data->data()), data->size() * sizeof(std::array<X, Y>::value_type));
else
{
std::array<X, Y>::const_iterator itr = data->begin();
std::array<X, Y>::const_iterator end = data->end();
while (itr != end)
buffer->push<std::array<X, Y>::value_type>(*itr++);
}
};
};
template<template<typename, size_t> class T, typename X, size_t Y> void Jupiter::DataBuffer::push(const T<X, Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl_std_array<T>::push<X, Y>(this, data);
}
template<template<typename, size_t> class T, typename X, size_t Y> void Jupiter::DataBuffer::push(const T<X, Y> &data)
{
Jupiter::DataBuffer::push<T, X, Y>(&data);
}
// SPECIALIZATION: std::vector
template<template<typename, typename> class T> struct _Jupiter_DataBuffer_partial_specialization_impl_std_vector
{
};
template<> struct _Jupiter_DataBuffer_partial_specialization_impl_std_vector<std::vector>
{
template<typename X, typename Y> static void push(Jupiter::DataBuffer *buffer, const std::vector<X, Y> *data)
{
buffer->push<std::vector<X, Y>::size_type>(data->size());
if (std::is_fundamental<std::vector<X, Y>::value_type>::value)
buffer->push(reinterpret_cast<const uint8_t *>(data->data()), data->size() * sizeof(std::vector<X, Y>::value_type));
else
{
std::vector<X, Y>::const_iterator itr = data->begin();
std::vector<X, Y>::const_iterator end = data->end();
while (itr != end)
buffer->push<std::vector<X, Y>::value_type>(*itr++);
}
};
template<typename X, typename Y> static std::vector<X, Y> interpret(uint8_t *&head)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
std::vector<X, Y> r;
r.reserve(size_);
while (size_-- != 0)
r.push_back(Jupiter::DataBuffer::interpret_data<std::vector<X, Y>::value_type>(head));
return r;
}
};
template<template<typename, typename> class T, typename X, typename Y> void Jupiter::DataBuffer::push(const T<X, Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl_std_vector<T>::push<X, Y>(this, data);
}
template<template<typename, typename> class T, typename X, typename Y> void Jupiter::DataBuffer::push(const T<X, Y> &data)
{
Jupiter::DataBuffer::push<T, X, Y>(&data);
}
template<template<typename, typename> class T, typename X, typename Y> T<X, Y> Jupiter::DataBuffer::interpret_data(uint8_t *&head)
{
return _Jupiter_DataBuffer_partial_specialization_impl_std_vector<T>::interpret<X, Y>(head);
}
// SPECIALIZATION: std::string
template<template<typename, typename, typename> class T> struct _Jupiter_DataBuffer_partial_specialization_impl_std_string
{
};
template<> struct _Jupiter_DataBuffer_partial_specialization_impl_std_string<std::basic_string>
{
template<typename X, typename Y, typename Z> static void push(Jupiter::DataBuffer *buffer, const std::basic_string<X, Y, Z> *data)
{
buffer->push(data->size());
if (std::is_fundamental<std::basic_string<X, Y, Z>::value_type>::value)
buffer->push(reinterpret_cast<const uint8_t *>(data->data()), data->size() * sizeof(X));
else
{
std::basic_string<X, Y, Z>::const_iterator itr = data->begin();
std::basic_string<X, Y, Z>::const_iterator end = data->end();
while (itr != end)
buffer->push<std::basic_string<X, Y, Z>::value_type>(*itr++);
}
};
template<typename X, typename Y, typename Z> static std::basic_string<X, Y, Z> interpret(uint8_t *&head)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
std::basic_string<X, Y, Z> r;
r.reserve(size_);
while (size_-- != 0)
r.push_back(Jupiter::DataBuffer::interpret_data<std::basic_string<X, Y, Z>::value_type>(head));
return r;
}
};
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> void Jupiter::DataBuffer::push(const T<X, Y, Z> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl_std_string<T>::push<X, Y, Z>(this, data);
}
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> void Jupiter::DataBuffer::push(const T<X, Y, Z> &data)
{
Jupiter::DataBuffer::push<T, X, Y, Z>(&data);
}
template<template<typename, typename, typename> class T, typename X, typename Y, typename Z> T<X, Y, Z> Jupiter::DataBuffer::interpret_data(uint8_t *&head)
{
return _Jupiter_DataBuffer_partial_specialization_impl_std_string<T>::interpret<X, Y, Z>(head);
}
#endif // _DATABUFFER_IMP_H_HEADER

92
Jupiter/Jupiter.vcxproj

@ -5,10 +5,18 @@
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}</ProjectGuid>
@ -23,6 +31,12 @@
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
@ -30,19 +44,35 @@
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<RunCodeAnalysis>false</RunCodeAnalysis>
@ -50,6 +80,13 @@
<LibraryPath>C:\dev\OpenSSL\Win32\lib;$(LibraryPath)</LibraryPath>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<RunCodeAnalysis>false</RunCodeAnalysis>
<IncludePath>C:\dev\OpenSSL\Win32\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\dev\OpenSSL\Win32\lib;$(LibraryPath)</LibraryPath>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
@ -62,7 +99,51 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;JUPITER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<EnablePREfast>false</EnablePREfast>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling>Async</ExceptionHandling>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<DisableSpecificWarnings>4505</DisableSpecificWarnings>
<C99Support>true</C99Support>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ShowProgress>NotSet</ShowProgress>
<Version>0.0</Version>
<TargetMachine>MachineX86</TargetMachine>
</Link>
<ProjectReference>
<LinkLibraryDependencies>
</LinkLibraryDependencies>
</ProjectReference>
<ResourceCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
@ -97,12 +178,16 @@
<ClCompile Include="Base64.cpp" />
<ClCompile Include="Base64C.c" />
<ClCompile Include="Command.cpp" />
<ClCompile Include="Config.cpp" />
<ClCompile Include="DataBuffer.cpp" />
<ClCompile Include="File.cpp" />
<ClCompile Include="Functions.c" />
<ClCompile Include="Hash.c" />
<ClCompile Include="INIFile.cpp" />
<ClCompile Include="IRC.cpp" />
<ClCompile Include="IRC_Client.cpp" />
<ClCompile Include="IRC_Server.cpp" />
<ClCompile Include="JSON.cpp" />
<ClCompile Include="Jupiter.cpp" />
<ClCompile Include="Plugin.cpp" />
<ClCompile Include="Queue.cpp" />
@ -112,6 +197,9 @@
<ClCompile Include="TCPSocket.cpp" />
<ClCompile Include="Timer.cpp" />
<ClCompile Include="UDPSocket.cpp" />
<ClCompile Include="XINI.cpp" />
<ClCompile Include="XML.cpp" />
<ClCompile Include="YAML.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ArrayList.h" />
@ -119,8 +207,12 @@
<ClInclude Include="Command.h" />
<ClInclude Include="CString.h" />
<ClInclude Include="CString_Imp.h" />
<ClInclude Include="Database.h" />
<ClInclude Include="DataBuffer.h" />
<ClInclude Include="DataBuffer_Imp.h" />
<ClInclude Include="DLList.h" />
<ClInclude Include="File.h" />
<ClInclude Include="Hash.h" />
<ClInclude Include="InvalidIndex.h" />
<ClInclude Include="IRC.h" />
<ClInclude Include="IRC_Numerics.h" />

36
Jupiter/Jupiter.vcxproj.filters

@ -46,6 +46,9 @@
<Filter Include="Source Files\Object Extensions">
<UniqueIdentifier>{37b5eaf6-0e4f-4609-8518-1b72f93aebe5}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\DataBuffer">
<UniqueIdentifier>{aef2e303-8a68-4cf9-8464-c4aef776d3f3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Functions.c">
@ -102,6 +105,27 @@
<ClCompile Include="IRC_Client.cpp">
<Filter>Source Files\IRC</Filter>
</ClCompile>
<ClCompile Include="XML.cpp">
<Filter>Source Files\Files</Filter>
</ClCompile>
<ClCompile Include="Config.cpp">
<Filter>Source Files\Files</Filter>
</ClCompile>
<ClCompile Include="JSON.cpp">
<Filter>Source Files\Files</Filter>
</ClCompile>
<ClCompile Include="YAML.cpp">
<Filter>Source Files\Files</Filter>
</ClCompile>
<ClCompile Include="XINI.cpp">
<Filter>Source Files\Files</Filter>
</ClCompile>
<ClCompile Include="Hash.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DataBuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Functions.h">
@ -215,6 +239,18 @@
<ClInclude Include="Reference_String_Imp.h">
<Filter>Header Files\Strings</Filter>
</ClInclude>
<ClInclude Include="Hash.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Database.h">
<Filter>Header Files\Files</Filter>
</ClInclude>
<ClInclude Include="DataBuffer_Imp.h">
<Filter>Header Files\DataBuffer</Filter>
</ClInclude>
<ClInclude Include="DataBuffer.h">
<Filter>Header Files\DataBuffer</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Jupiter.rc">

13
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<Jupiter::List>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::List<Y> *data)
{
buffer->push<size_t>(data->size());
for (size_t index = 0; index != data->size(); index++)
buffer->push<Y>(*data->get(index));
};
};
#endif // _LIST_H_HEADER

3
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 <cstdio> // FILE
#include <string> // std::basic_string<T> type
#include "InvalidIndex.h"
#include "DataBuffer.h"
namespace Jupiter
{

14
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<typename T> template<template<typename> class R> R<T> Jupiter::Readable
return R<T>();
}
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::Readable_String<Y> *data)
{
buffer->secure(sizeof(size_t) + data->size() * sizeof(Y));
buffer->push<size_t>(data->size());
buffer->push(reinterpret_cast<const uint8_t *>(data->ptr()), data->size() * sizeof(Y));
};
};
#endif // _READABLE_STRING_IMP_H_HEADER

7
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<T> &in);
/**
* @brief Conversion constructor for Jupiter::DataBuffer class.
*/
Reference_String(const Jupiter::DataBuffer &in);
static const Jupiter::Reference_String<T> empty; /** Empty instantiation of Reference_String */
protected:

25
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<typename T> Jupiter::Reference_String<T>::Reference_String(const Jupite
{
}
template<typename T> Jupiter::Reference_String<T>::Reference_String(const Jupiter::DataBuffer &in) : Reference_String(reinterpret_cast<T *>(in.getHead()), in.size() / sizeof(T))
{
}
template<typename T> const T &Jupiter::Reference_String<T>::get(size_t index) const
{
return Jupiter::Reference_String<T>::str[index];
@ -233,4 +237,23 @@ template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::
template<typename T> const Jupiter::Reference_String<T> Jupiter::Reference_String<T>::empty = Jupiter::Reference_String<T>();
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Reference_String>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::Reference_String<Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data);
};
template<typename Y> static Jupiter::Reference_String<Y> interpret(uint8_t *&head)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
Jupiter::Reference_String<Y> r = Jupiter::Reference_String<Y>(reinterpret_cast<Y *>(head), size_);
head += size_;
return r;
}
};
#endif // _REFERENCE_STRING_IMP

23
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<typename T> void Jupiter::SLList<T>::add(T *data)
Jupiter::List<T>::length++;
}
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::SLList>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::SLList<Y> *data)
{
buffer->push<size_t>(data->size());
Jupiter::SLList<Y>::Node *head = data->getNode(0);
while (head != nullptr)
buffer->push<Y>(*head++->data);
};
template<typename Y> static Jupiter::SLList<Y> interpret(uint8_t *&head)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
Jupiter::SLList<Y> r;
while (size_-- != 0)
r.add(Jupiter::DataBuffer::interpret_data<Y>(head));
return r;
}
};
#endif // _SLLIST_H_HEADER

12
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<typename T> bool Jupiter::Shift_String_Type<T>::setBufferSizeNoCopy(siz
return false;
}
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Shift_String_Type>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::Shift_String_Type<Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data);
};
};
#endif // _SHIFT_STRING_IMP_H_HEADER

6
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<T> &&source);
/** Copy Constructors */
String_Strict(const String_Strict<T> &in) : String_Strict((Readable_String<T> &)in) {}
String_Strict(const String_Strict<T> &in);
String_Strict(const Readable_String<T> &in);
String_Strict(const std::basic_string<T> &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<T> &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<T> empty; /** Empty instantation of String_Loose */
static const size_t start_size = 8; /** Starting size for loose Strings. */

52
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<typename T> Jupiter::String_Strict<T>::String_Strict(Jupiter::String_St
{
}
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::String_Strict<T> &in) : Jupiter::String_Strict<T>::String_Strict(in.ptr(), in.size())
{
}
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::Readable_String<T> &in) : Jupiter::String_Strict<T>::String_Strict(in.ptr(), in.size())
{
}
@ -85,6 +89,10 @@ template<typename T> Jupiter::String_Strict<T>::String_Strict(const T *in)
for (size_t index = 0; index != Jupiter::String_Type<T>::length; index++, in++) Jupiter::String_Type<T>::str[index] = *in;
}
template<typename T> Jupiter::String_Strict<T>::String_Strict(const Jupiter::DataBuffer &in) : String_Strict(reinterpret_cast<T *>(in.getHead()), in.size() / sizeof(T))
{
}
// vformat()
template<> size_t inline Jupiter::String_Strict<char>::vformat(const char *format, va_list args)
@ -268,6 +276,25 @@ template<typename T> Jupiter::String_Strict<T> Jupiter::String_Strict<T>::gotoTo
template<typename T> const Jupiter::String_Strict<T> Jupiter::String_Strict<T>::empty = Jupiter::String_Strict<T>();
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Strict>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Strict<Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data);
};
template<typename Y> static Jupiter::String_Strict<Y> interpret(uint8_t *&head)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
Jupiter::String_Strict<Y> r = Jupiter::String_Strict<Y>(reinterpret_cast<Y *>(head), size_);
head += size_;
return r;
}
};
/**
* IMPLEMENTATION:
* String_Loose
@ -342,6 +369,10 @@ template<typename T> Jupiter::String_Loose<T>::String_Loose(const T *in)
}
}
template<typename T> Jupiter::String_Loose<T>::String_Loose(const Jupiter::DataBuffer &in) : String_Loose(reinterpret_cast<T *>(in.getHead()), in.size() / sizeof(T))
{
}
template<typename T> bool Jupiter::String_Loose<T>::setBufferSize(size_t len)
{
return Jupiter::Shift_String_Type<T>::setBufferSize(Jupiter::String_Loose<T>::strSize = getPowerTwo32(len));
@ -535,4 +566,23 @@ template<typename T> Jupiter::String_Loose<T> Jupiter::String_Loose<T>::gotoToke
template<typename T> const Jupiter::String_Loose<T> Jupiter::String_Loose<T>::empty = Jupiter::String_Loose<T>();
// Jupiter::DataBuffer specialization
template<> struct _Jupiter_DataBuffer_partial_specialization_impl<Jupiter::String_Loose>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Loose<Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data);
};
template<typename Y> static Jupiter::String_Loose<Y> interpret(uint8_t *&head)
{
size_t size_ = *reinterpret_cast<size_t *>(head);
head += sizeof(size_t);
Jupiter::String_Loose<Y> r = Jupiter::String_Loose<Y>(reinterpret_cast<T *>(head), size_);
head += size_;
return r;
}
};
#endif // _STRING_IMP_H_HEADER

1
Jupiter/String_Type.h

@ -224,6 +224,7 @@ namespace Jupiter
* A copy constructor for std::basic_string<T>.
* A copy constructor for C-style strings.
* A copy constructor for memory array strings.
* A conversion constructor for Jupiter::DataBuffer
*/
protected:

10
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<Jupiter::String_Type>
{
template<typename Y> static void push(Jupiter::DataBuffer *buffer, const Jupiter::String_Type<Y> *data)
{
_Jupiter_DataBuffer_partial_specialization_impl<Jupiter::Readable_String>::push<Y>(buffer, data);
};
};
#endif // _STRING_TYPE_IMP_H_HEADER

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save