Commit 6d79895c authored by Miro Knejp's avatar Miro Knejp Committed by Jacob Potter

Cleanup record constructor with function call writer

parent b4f335b9
......@@ -10,14 +10,11 @@
namespace textsort {
struct ItemList final {
std::vector<std::string> items;
ItemList(
std::vector<std::string> items) :
items(std::move(items)) {
}
ItemList(std::vector<std::string> items)
: items(std::move(items))
{}
};
} // namespace textsort
......@@ -18,7 +18,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface TXSSortItems ()
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::textsort::SortItems>::Handle cppRef;
@property (nonatomic, readonly) ::djinni::DbxCppWrapperCache<::textsort::SortItems>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems>&)cppRef;
......@@ -33,7 +33,7 @@ auto SortItems::toCpp(ObjcType objc) -> CppType
auto SortItems::fromCpp(const CppType& cpp) -> ObjcType
{
return !cpp ? nil : djinni::DbxCppWrapperCache<::textsort::SortItems>::getInstance()->get(cpp, [] (const auto& p)
return !cpp ? nil : ::djinni::DbxCppWrapperCache<::textsort::SortItems>::getInstance()->get(cpp, [] (const auto& p)
{
return [[TXSSortItems alloc] initWithCpp:p];
});
......
......@@ -27,7 +27,7 @@ public:
auto TextboxListener::toCpp(ObjcType objc) -> CppType
{
return objc ? djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr;
return objc ? ::djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr;
}
auto TextboxListener::fromCpp(const CppType& cpp) -> ObjcType
......
......@@ -186,7 +186,6 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
generateHppConstants(w, r.consts)
// Field definitions.
for (f <- r.fields) {
w.wl
writeDoc(w, f.doc)
w.wl(marshal.fieldType(f.ty) + " " + idCpp.field(f.ident) + ";")
}
......@@ -206,27 +205,13 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
}
// Constructor.
w.wl
if (r.fields.nonEmpty) {
w.wl(actualSelf + "(").nestedN(2) {
val skipFirst = SkipFirst()
for (f <- r.fields) {
skipFirst { w.wl(",") }
w.w(marshal.fieldType(f.ty) + " " + idCpp.local(f.ident))
}
w.wl(") :")
w.nested {
val skipFirst = SkipFirst()
for (f <- r.fields) {
skipFirst { w.wl(",") }
w.w(idCpp.field(f.ident) + "(std::move(" + idCpp.local(f.ident) + "))")
}
w.wl(" {")
}
}
w.wl("}")
} else {
w.wl(actualSelf + "() {};")
if(r.fields.nonEmpty) {
writeAlignedCall(w, actualSelf + "(", r.fields, ")", f => marshal.fieldType(f.ty) + " " + idCpp.local(f.ident))
w.wl
val init = (f: Field) => idCpp.field(f.ident) + "(std::move(" + idCpp.local(f.ident) + "))"
w.wl(": " + init(r.fields.head))
r.fields.tail.map(f => ", " + init(f)).foreach(w.wl)
w.wl("{}")
}
if (r.ext.cpp) {
......
......@@ -8,42 +8,32 @@
#include <utility>
struct AssortedIntegers final {
int8_t eight;
int16_t sixteen;
int32_t thirtytwo;
int64_t sixtyfour;
std::experimental::optional<int8_t> o_eight;
std::experimental::optional<int16_t> o_sixteen;
std::experimental::optional<int32_t> o_thirtytwo;
std::experimental::optional<int64_t> o_sixtyfour;
bool operator==(const AssortedIntegers & other) const;
bool operator!=(const AssortedIntegers & other) const;
AssortedIntegers(
int8_t eight,
int16_t sixteen,
int32_t thirtytwo,
int64_t sixtyfour,
std::experimental::optional<int8_t> o_eight,
std::experimental::optional<int16_t> o_sixteen,
std::experimental::optional<int32_t> o_thirtytwo,
std::experimental::optional<int64_t> o_sixtyfour) :
eight(std::move(eight)),
sixteen(std::move(sixteen)),
thirtytwo(std::move(thirtytwo)),
sixtyfour(std::move(sixtyfour)),
o_eight(std::move(o_eight)),
o_sixteen(std::move(o_sixteen)),
o_thirtytwo(std::move(o_thirtytwo)),
o_sixtyfour(std::move(o_sixtyfour)) {
}
AssortedIntegers(int8_t eight,
int16_t sixteen,
int32_t thirtytwo,
int64_t sixtyfour,
std::experimental::optional<int8_t> o_eight,
std::experimental::optional<int16_t> o_sixteen,
std::experimental::optional<int32_t> o_thirtytwo,
std::experimental::optional<int64_t> o_sixtyfour)
: eight(std::move(eight))
, sixteen(std::move(sixteen))
, thirtytwo(std::move(thirtytwo))
, sixtyfour(std::move(sixtyfour))
, o_eight(std::move(o_eight))
, o_sixteen(std::move(o_sixteen))
, o_thirtytwo(std::move(o_thirtytwo))
, o_sixtyfour(std::move(o_sixtyfour))
{}
};
......@@ -8,16 +8,12 @@
#include <utility>
struct ClientReturnedRecord final {
int64_t record_id;
std::string content;
ClientReturnedRecord(
int64_t record_id,
std::string content) :
record_id(std::move(record_id)),
content(std::move(content)) {
}
ClientReturnedRecord(int64_t record_id,
std::string content)
: record_id(std::move(record_id))
, content(std::move(content))
{}
};
......@@ -27,16 +27,12 @@ struct Constants final {
static const std::experimental::optional<int32_t> OPTIONAL_INTEGER_CONSTANT;
static const Constants OBJECT_CONSTANT;
int32_t some_integer;
std::string some_string;
Constants(
int32_t some_integer,
std::string some_string) :
some_integer(std::move(some_integer)),
some_string(std::move(some_string)) {
}
Constants(int32_t some_integer,
std::string some_string)
: some_integer(std::move(some_integer))
, some_string(std::move(some_string))
{}
};
......@@ -7,12 +7,9 @@
#include <utility>
struct DateRecord final {
std::chrono::system_clock::time_point created_at;
DateRecord(
std::chrono::system_clock::time_point created_at) :
created_at(std::move(created_at)) {
}
DateRecord(std::chrono::system_clock::time_point created_at)
: created_at(std::move(created_at))
{}
};
......@@ -9,12 +9,9 @@
#include <utility>
struct MapDateRecord final {
std::unordered_map<std::string, std::chrono::system_clock::time_point> dates_by_id;
MapDateRecord(
std::unordered_map<std::string, std::chrono::system_clock::time_point> dates_by_id) :
dates_by_id(std::move(dates_by_id)) {
}
MapDateRecord(std::unordered_map<std::string, std::chrono::system_clock::time_point> dates_by_id)
: dates_by_id(std::move(dates_by_id))
{}
};
......@@ -10,12 +10,9 @@
#include <vector>
struct MapListRecord final {
std::vector<std::unordered_map<std::string, int64_t>> map_list;
MapListRecord(
std::vector<std::unordered_map<std::string, int64_t>> map_list) :
map_list(std::move(map_list)) {
}
MapListRecord(std::vector<std::unordered_map<std::string, int64_t>> map_list)
: map_list(std::move(map_list))
{}
};
......@@ -9,12 +9,9 @@
#include <utility>
struct MapRecord final {
std::unordered_map<std::string, int64_t> map;
MapRecord(
std::unordered_map<std::string, int64_t> map) :
map(std::move(map)) {
}
MapRecord(std::unordered_map<std::string, int64_t> map)
: map(std::move(map))
{}
};
......@@ -9,12 +9,9 @@
#include <vector>
struct NestedCollection final {
std::vector<std::unordered_set<std::string>> set_list;
NestedCollection(
std::vector<std::unordered_set<std::string>> set_list) :
set_list(std::move(set_list)) {
}
NestedCollection(std::vector<std::unordered_set<std::string>> set_list)
: set_list(std::move(set_list))
{}
};
......@@ -8,12 +8,9 @@
#include <vector>
struct PrimitiveList final {
std::vector<int64_t> list;
PrimitiveList(
std::vector<int64_t> list) :
list(std::move(list)) {
}
PrimitiveList(std::vector<int64_t> list)
: list(std::move(list))
{}
};
......@@ -8,9 +8,7 @@
#include <utility>
struct RecordWithDerivings final {
int32_t key1;
std::string key2;
bool operator==(const RecordWithDerivings & other) const;
......@@ -19,11 +17,9 @@ struct RecordWithDerivings final {
bool operator>(const RecordWithDerivings & other) const;
bool operator<=(const RecordWithDerivings & other) const;
bool operator>=(const RecordWithDerivings & other) const;
RecordWithDerivings(
int32_t key1,
std::string key2) :
key1(std::move(key1)),
key2(std::move(key2)) {
}
RecordWithDerivings(int32_t key1,
std::string key2)
: key1(std::move(key1))
, key2(std::move(key2))
{}
};
......@@ -8,9 +8,7 @@
#include <utility>
struct RecordWithNestedDerivings final {
int32_t key;
RecordWithDerivings rec;
bool operator==(const RecordWithNestedDerivings & other) const;
......@@ -19,11 +17,9 @@ struct RecordWithNestedDerivings final {
bool operator>(const RecordWithNestedDerivings & other) const;
bool operator<=(const RecordWithNestedDerivings & other) const;
bool operator>=(const RecordWithNestedDerivings & other) const;
RecordWithNestedDerivings(
int32_t key,
RecordWithDerivings rec) :
key(std::move(key)),
rec(std::move(rec)) {
}
RecordWithNestedDerivings(int32_t key,
RecordWithDerivings rec)
: key(std::move(key))
, rec(std::move(rec))
{}
};
......@@ -8,12 +8,9 @@
#include <utility>
struct SetRecord final {
std::unordered_set<std::string> set;
SetRecord(
std::unordered_set<std::string> set) :
set(std::move(set)) {
}
SetRecord(std::unordered_set<std::string> set)
: set(std::move(set))
{}
};
......@@ -30,7 +30,7 @@ public:
auto ClientInterface::toCpp(ObjcType objc) -> CppType
{
return objc ? djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr;
return objc ? ::djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr;
}
auto ClientInterface::fromCpp(const CppType& cpp) -> ObjcType
......
......@@ -16,7 +16,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface DBCppException ()
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::CppException>::Handle cppRef;
@property (nonatomic, readonly) ::djinni::DbxCppWrapperCache<::CppException>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::CppException>&)cppRef;
......@@ -31,7 +31,7 @@ auto CppException::toCpp(ObjcType objc) -> CppType
auto CppException::fromCpp(const CppType& cpp) -> ObjcType
{
return !cpp ? nil : djinni::DbxCppWrapperCache<::CppException>::getInstance()->get(cpp, [] (const auto& p)
return !cpp ? nil : ::djinni::DbxCppWrapperCache<::CppException>::getInstance()->get(cpp, [] (const auto& p)
{
return [[DBCppException alloc] initWithCpp:p];
});
......
......@@ -22,7 +22,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface DBTestHelpers ()
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::TestHelpers>::Handle cppRef;
@property (nonatomic, readonly) ::djinni::DbxCppWrapperCache<::TestHelpers>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::TestHelpers>&)cppRef;
......@@ -37,7 +37,7 @@ auto TestHelpers::toCpp(ObjcType objc) -> CppType
auto TestHelpers::fromCpp(const CppType& cpp) -> ObjcType
{
return !cpp ? nil : djinni::DbxCppWrapperCache<::TestHelpers>::getInstance()->get(cpp, [] (const auto& p)
return !cpp ? nil : ::djinni::DbxCppWrapperCache<::TestHelpers>::getInstance()->get(cpp, [] (const auto& p)
{
return [[DBTestHelpers alloc] initWithCpp:p];
});
......
......@@ -14,7 +14,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface DBToken ()
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::Token>::Handle cppRef;
@property (nonatomic, readonly) ::djinni::DbxCppWrapperCache<::Token>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::Token>&)cppRef;
......@@ -29,7 +29,7 @@ auto Token::toCpp(ObjcType objc) -> CppType
auto Token::fromCpp(const CppType& cpp) -> ObjcType
{
return !cpp ? nil : djinni::DbxCppWrapperCache<::Token>::getInstance()->get(cpp, [] (const auto& p)
return !cpp ? nil : ::djinni::DbxCppWrapperCache<::Token>::getInstance()->get(cpp, [] (const auto& p)
{
return [[DBToken alloc] initWithCpp:p];
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment