Skip to content

Commit

Permalink
Merge pull request #52 from BrainlessLabs/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
BrainlessLabs authored Sep 10, 2018
2 parents 8829d18 + 1bcc4a6 commit 96dc1c2
Show file tree
Hide file tree
Showing 6 changed files with 19,051 additions and 12 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
36 changes: 30 additions & 6 deletions include/blib/bun/impl/orm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ namespace blib {
return value;
}

auto tojson_string(std::string& value)->std::string {
const std::string quote("'");
inline auto tojson_string(std::string const& value)->std::string {
const std::string quote("\"");
const std::string ret = quote + value + quote;
return ret;
}
Expand Down Expand Up @@ -598,16 +598,40 @@ namespace blib {
std::string& _str;
const std::vector<std::string>& _member_names;
int _count;
bool _apply_comma;

template<typename IT, bool IsCompositeType>
struct _ToJsonImpl {
public:
static void impl(IT const& obj, const std::string& obj_name, bool const apply_comma, std::string& str) {
const std::string comma = apply_comma ? "," : "";
str += fmt::format("{}\"{}\": {}", comma, obj_name, tojson_string(obj));
}
};

template<typename IT>
struct _ToJsonImpl<IT, true> {
public:
static void impl(IT const& obj, const std::string& obj_name, bool const apply_comma, std::string& str) {
const std::string comma = apply_comma ? "," : "";
str += fmt::format("{}\"{}\":{}", comma, obj_name, to_json<IT>(obj));
}
};

public:
ToJson(std::string & str) :_str(str), _member_names(TypeMetaData<T>::member_names()), _count(2) {
ToJson(std::string & str) :
_str(str),
_member_names(TypeMetaData<T>::member_names()),
_count(2),
_apply_comma(false) {
}

template <typename O>
void operator()(O const& x) const {
const std::string member_name = _member_names.at(const_cast<ToJson*>(this)->_count++);
const std::string obj_name = blib::bun::__private::to_valid_query_string(member_name, "'");
_str += fmt::format("{} : {}", obj_name, to_json<O>(x));
ToJson::_ToJsonImpl<O, IsComposite<O>::value>::impl(x, member_name, _apply_comma, _str);
const_cast<ToJson*>(this)->_apply_comma = true;
}
};

Expand All @@ -619,8 +643,8 @@ namespace blib {
inline static std::string objToJson(T const& obj) {
std::string str;
boost::fusion::for_each(obj, QueryHelper<T>::ToJson(str));
str += "{" + str + "}";
return str;
const std::string ret_string = "{" + str + "}";
return ret_string;
}


Expand Down
Loading

0 comments on commit 96dc1c2

Please sign in to comment.