Skip to content

Commit

Permalink
using cmake to manage projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Madokakaroto authored and Madokakaroto committed Apr 6, 2017
1 parent c5b66dc commit a965c5f
Show file tree
Hide file tree
Showing 629 changed files with 88,070 additions and 1,536 deletions.
File renamed without changes.
Empty file added example/json_example.cpp
Empty file.
27 changes: 27 additions & 0 deletions example/msgpack_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iguana/msgpack.hpp>

namespace client
{
struct game
{
std::string name;
double price;
};
REFLECTION(game, name, price);
}

int main(void)
{
client::game game = { "overwatch", 258.0 };

iguana::memory_buffer buffer;
iguana::msgpack::to_msgpack(buffer, game);

auto buf = buffer.release();
client::game g2;
iguana::msgpack::from_msgpack(g2, buf.data(), buf.size());

std::cout << g2.name << " - " << g2.price << std::endl;

return 0;
}
29 changes: 29 additions & 0 deletions example/xml_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iguana/xml.hpp>

namespace client
{
struct madoka
{
std::string onegayi;
double power;
};

REFLECTION(madoka, onegayi, power);
}

int main(void)
{
client::madoka m = { "Majyosine", 99999.999 };

iguana::string_stream ss;
iguana::xml::to_xml(ss, m);

auto xml_str = ss.str();
std::cout << xml_str << std::endl;

client::madoka m2;
iguana::xml::from_xml(m2, xml_str.data(), xml_str.length());

std::cout << m2.onegayi << " - " << m2.power << std::endl;
return 0;
}
165 changes: 0 additions & 165 deletions iguana.vcxproj

This file was deleted.

39 changes: 0 additions & 39 deletions iguana.vcxproj.filters

This file was deleted.

File renamed without changes.
124 changes: 124 additions & 0 deletions iguana/detail/string_stream.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#pragma once

namespace iguana
{
template <typename alloc_ty>
struct basic_string_stream
{
private:
alloc_ty alloc;
public:
enum { good, read_overflow };

char* m_header_ptr;
char* m_read_ptr;
char* m_write_ptr;
char* m_tail_ptr;
int m_status;
std::size_t m_length;

enum { INIT_BUFF_SIZE = 1024 };

basic_string_stream()
: m_length(INIT_BUFF_SIZE)
, m_status(good)
{
this->m_header_ptr = this->alloc.allocate(INIT_BUFF_SIZE);
this->m_read_ptr = this->m_header_ptr;
this->m_write_ptr = this->m_header_ptr;
this->m_tail_ptr = this->m_header_ptr + m_length;
}

~basic_string_stream()
{
this->alloc.deallocate(m_header_ptr, this->m_length);
}

inline std::size_t write(const char * buffer)
{
return write(buffer, strlen(buffer));
}

inline std::size_t read(const char * buffer, std::size_t len)
{
if (this->m_read_ptr + len > this->m_tail_ptr)
{
m_status = read_overflow;
return 0;
}
std::memcpy(buffer, this->m_read_ptr, len);
this->m_read_ptr += len;
return len;
}

inline std::size_t growpup(std::size_t want_size)
{
std::size_t new_size = ((want_size + INIT_BUFF_SIZE - 1) / INIT_BUFF_SIZE)*INIT_BUFF_SIZE;
std::size_t write_pos = this->m_write_ptr - this->m_header_ptr;
std::size_t read_pos = this->m_read_ptr - this->m_header_ptr;
char * temp = this->m_header_ptr;
this->m_header_ptr = this->alloc.allocate(new_size);
std::memcpy(this->m_header_ptr, temp, this->m_length);
this->alloc.deallocate(temp, this->m_length);
this->m_length = new_size;
this->m_write_ptr = this->m_header_ptr + write_pos;
this->m_read_ptr = this->m_header_ptr + read_pos;
this->m_tail_ptr = this->m_header_ptr + m_length;
return new_size;
}

inline std::size_t write(const char * buffer, std::size_t len)
{
std::size_t writed_len = this->m_write_ptr + len - this->m_header_ptr;
if (writed_len > this->m_length)
{
this->growpup(writed_len);
}
std::memcpy((void*)this->m_write_ptr, buffer, len);
this->m_write_ptr += len;
return len;
}

inline void put(char c)
{
std::size_t writed_len = this->m_write_ptr + 1 - this->m_header_ptr;
if (writed_len > this->m_length)
{
this->growpup(writed_len);
}
*this->m_write_ptr = c;
++this->m_write_ptr;
}

inline bool bad()const { return m_status != good; }

inline void clear()
{
this->m_read_ptr = this->m_header_ptr;
this->m_write_ptr = this->m_header_ptr;
}

inline const char * data() const
{
return this->m_header_ptr;
}

std::basic_string<char, std::char_traits<char>, alloc_ty> str()
{
std::basic_string<char, std::char_traits<char>, alloc_ty> s(this->m_header_ptr, this->write_length());
return s;
}

inline ::std::size_t read_length() const
{
return this->m_read_ptr - this->m_header_ptr;
}

inline ::std::size_t write_length() const
{
return this->m_write_ptr - this->m_header_ptr;
}
};

typedef basic_string_stream<std::allocator<char>> string_stream;
}
File renamed without changes.
Loading

0 comments on commit a965c5f

Please sign in to comment.