Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement FieldValue for null, boolean, and array in C++. #637

Merged
merged 8 commits into from
Jan 17, 2018

Conversation

zxu123
Copy link
Contributor

@zxu123 zxu123 commented Jan 10, 2018

Discussion

go/firestorecppfieldvalue

Testing

unit test

API Changes

n/a

@zxu123 zxu123 self-assigned this Jan 10, 2018
# See the License for the specific language governing permissions and
# limitations under the License.

# firebase_firestore_util is the interface of this module. The rest of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is firebase_firestore_model :-).

There shouldn't be any multi-platform shenanigans here so I think you can just remove this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. It's a bad copy&paste =D

*/

#include "Firestore/core/src/firebase/firestore/model/field_value.h"
#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline between the include of this class and anything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

public:

/** The order of types in Firestore; this order is defined by the backend. */
typedef enum {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer enum class TypeOrder { ... }; to this kind of enum. The values inside the enumeration can be unqualified (i.e. they can be Null, Boolean, etc.).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* All the different kinds of values that can be stored in fields in
* a document.
*/
typedef enum {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar feedback here: enum class Type. Also Type is the principal concept here and TypeOrder is secondary.

You may even be able to make TypeOrder a private enum.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. TypeOrder is used in subtype and test; so not making private.

} Type;

/** Returns the TypeOrder for this value. */
virtual TypeOrder type_order() const = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, let's see if we can make this a non-virtual setup using a tagged union. With this arrangement all FieldValues will need to be allocated on the heap and accessed by pointer.

If the tagged union mechanism doesn't work then this class needs a virtual destructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Just one thing. Now since each subtype has no relation with FieldValue, the old logic of constant value (NullValue, TrueValue, FalseValue) needs to be defined in a reasonable way. I am thinking make constants of type FieldValue (instead of each individual subtype) but not sure. Generally those subtype is kinda internal to the FieldValue and user should almost use FieldValue. Then one can assign a FieldValue to one of those constant value to save a bit footprint on memory and cpu for allocation. How do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the extra types (NullValue, BooleanValue, ArrayValue, etc) don't really buy us anything.

We can just make the values of the underlying types direct members of the union.

At that point, yes, I agree the static instances should be of type FieldValue :-).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

virtual Type type() const = 0;

/** Compares against another FieldValue. */
virtual int Compare(const FieldValue& other) const = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C++ idiom for comparison is operator<.

Probably this should declared as

friend bool operator< (const FieldValue& lhs, const FieldValue& rhs);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare returns three values, -1, 0, 1. We can add the common comparison operator on top of Compare(); and probably make Compare() private.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare: is an Objective-C mechanism, defined for compatibility with Objective-C containers. You can see how native types implement it:

https://developer.apple.com/documentation/foundation/nsnumber/1413562-compare?language=objc

In C++ ordered containers use a comparator whose default is usually std::less which invokes operator< on the types to be inserted. Because of this no external usage of Compare should ever exist.

The standard way to implement the other operators is like this:

inline bool operator> (const X& lhs, const X& rhs){ return rhs < lhs; }
inline bool operator<=(const X& lhs, const X& rhs){ return !(lhs > rhs); }
inline bool operator>=(const X& lhs, const X& rhs){ return !(lhs < rhs); }

Meanwhile for any type that implements operator< the multi-valued return can be implemented generically (though I'm probably getting the direction wrong). Indeed we can include something like this in our toolbox for interoperating with Objective-C.

template <typename T>
NSComparisonResult Compare(const T& lhs, const T& rhs) {
  if (lhs < rhs) {
    return NSOrderedAscending;
  } else if (rhs < lhs) {
    return NSOrderedDescending;
  } else {
    return NSOrderedSame;
  }

} Type;

/** Returns the TypeOrder for this value. */
virtual TypeOrder type_order() const = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the extra types (NullValue, BooleanValue, ArrayValue, etc) don't really buy us anything.

We can just make the values of the underlying types direct members of the union.

At that point, yes, I agree the static instances should be of type FieldValue :-).

virtual Type type() const = 0;

/** Compares against another FieldValue. */
virtual int Compare(const FieldValue& other) const = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare: is an Objective-C mechanism, defined for compatibility with Objective-C containers. You can see how native types implement it:

https://developer.apple.com/documentation/foundation/nsnumber/1413562-compare?language=objc

In C++ ordered containers use a comparator whose default is usually std::less which invokes operator< on the types to be inserted. Because of this no external usage of Compare should ever exist.

The standard way to implement the other operators is like this:

inline bool operator> (const X& lhs, const X& rhs){ return rhs < lhs; }
inline bool operator<=(const X& lhs, const X& rhs){ return !(lhs > rhs); }
inline bool operator>=(const X& lhs, const X& rhs){ return !(lhs < rhs); }

Meanwhile for any type that implements operator< the multi-valued return can be implemented generically (though I'm probably getting the direction wrong). Indeed we can include something like this in our toolbox for interoperating with Objective-C.

template <typename T>
NSComparisonResult Compare(const T& lhs, const T& rhs) {
  if (lhs < rhs) {
    return NSOrderedAscending;
  } else if (rhs < lhs) {
    return NSOrderedDescending;
  } else {
    return NSOrderedSame;
  }

if (left == right) {
switch(lhs.type()) {
case FieldValue::Type::Null:
return Compare(lhs.value_->null_value_, rhs.value_->null_value_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If both types are Null they compare equal by definition so there's nothing to actually compare (i.e. this can always just return 0;).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


FieldValue::~FieldValue() {
switch(tag_) {
case FieldValue::Type::Array:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can cut down on the verbosity in here by doing this after the #includes

using FieldValue::Type;
using FieldValue::TypeOrder;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Object,
};

/** The order of types in Firestore; this order is defined by the backend. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting in this comment why this exists separately from Type.

In particular: Long and Double are compared together and Timestamp and ServerTimestamp are compared together.

I wonder if we can get rid of TypeOrder altogether if we have a Comparable(Type left_type, Type right_type) function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea of getting rid of TypeOrder. We can also just switch-case on the implied TypeOrder and do comparison without any other helper function. The only thing to take care of is to group the Type of the same TypeOrder in the enum definition in the same TypeOrder order as server does. Since we do not expose Type to public api, we are free to rearrange the enum order.

Timestamp,
ServerTimestamp,
String,
Binary,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is Blob, not Binary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

namespace firestore {
namespace model {

class NullValue {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating separate types for these I think you could just have static factory methods on FieldValue. Something like

class FieldValue {
 public:
  static const FieldValue& NullValue();
  static const FieldValue& BooleanValue(bool value);
  // ...
}

const FieldValue& FieldValue::NullValue() {
  static FieldValue kNullInstance(Type::Null);
  return kNullInstance;
}

const FieldValue& FieldValue::BooleanValue(bool value) {
  static FieldValue kTrueInstance(Type::Boolean, true);
  static FieldValue kFalseInstance(Type::Boolean, false);
  return value ? kTrueInstance : kFalseInstance;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

@zxu123 zxu123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored. PTAL.


FieldValue::~FieldValue() {
switch(tag_) {
case FieldValue::Type::Array:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (left == right) {
switch(lhs.type()) {
case FieldValue::Type::Null:
return Compare(lhs.value_->null_value_, rhs.value_->null_value_);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Timestamp,
ServerTimestamp,
String,
Binary,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Object,
};

/** The order of types in Firestore; this order is defined by the backend. */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea of getting rid of TypeOrder. We can also just switch-case on the implied TypeOrder and do comparison without any other helper function. The only thing to take care of is to group the Type of the same TypeOrder in the enum definition in the same TypeOrder order as server does. Since we do not expose Type to public api, we are free to rearrange the enum order.

} Type;

/** Returns the TypeOrder for this value. */
virtual TypeOrder type_order() const = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

namespace firestore {
namespace model {

class NullValue {};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite all the comments in here I really like the direction this is heading.

In particular, the insight that we could use placement new to initialize the union is fantastic. It's bulletproof and doesn't require memset or any other hacks like that.

namespace firestore {
namespace model {

using Type = FieldValue::Type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're not spelling the unqualified type name differently this can just be

using FieldValue::Type;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work since FieldValue is not namespace.

/Users/zxu/Documents/GitHub/firebase-ios-sdk/Firestore/core/src/firebase/firestore/model/field_value.cc:29:19: error: using declaration
cannot refer to class member
using FieldValue::Type;
~~~~~~~~~~~~^
/Users/zxu/Documents/GitHub/firebase-ios-sdk/Firestore/core/src/firebase/firestore/model/field_value.cc:29:7: note: use an alias
declaration instead
using FieldValue::Type;
^
Type =

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprising! Thanks for pointing out the details.


namespace {

bool Comparable(Type lhs, Type rhs) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments. In particular since this deviates from the other platforms it's worth commenting on how this is different and why.

In this case, this is equivalent to the type order on the other platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

switch(tag_) {
case Type::Array:
tag_ = Type::Null;
value_.array_value_.~vector();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

* backend.
*/
enum class Type {
Null, // Null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./scripts/style.sh should align these comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* All the different kinds of values that can be stored in fields in
* a document. The types of the same comparison order should be defined
* together as a group. The order of each group is defined by the Firestore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order is defined publicly. Perhaps link to this document?

https://firebase.google.com/docs/firestore/manage-data/data-types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private:
explicit FieldValue(bool value) : tag_(Type::Boolean), value_(value) {}

void ResetUnion();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments please. In particular it's useful to know that after it runs, the type will be set to Null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking it twice, I think the combine of the two helper is more than enough a.k.a. we can reset by copy from null. The extra cost is minimal. In other words, all the logic can be put in operator= directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack.


switch(lhs.type()) {
case Type::Null:
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I gave you the wrong idea here. This should be return false; since the type is bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

EXPECT_TRUE(small == small);
EXPECT_FALSE(small == large);
}
} // namespace model
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


using Type = FieldValue::Type;

TEST(FieldValue, NullType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test of assignment. In particular, please add a test showing something like this works and verify that we correctly destroy the vector.

FieldValue value = FieldValue::NullValue();
value = FieldValue::ArrayValue(std::vector<const FieldValue>{
  FieldValue::BooleanValue(true),
  FieldValue::BooleanValue(false)
});
value = FieldValue::NullValue();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


/** Returns constants. */
static const FieldValue& NullValue();
static const FieldValue& BooleanValue(bool value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The javascript SDK defines BooleanValue::TRUE.

For consistency's sake we should probably have

static const FieldValue& True();
static const FieldValue& False();

in addition to this method. As in the JS SDK, this implementation can delegate to those as appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. We already have NullValue(); so added TrueValue() and FalseValue(). Let me know if you prefer True() and False() (and Null()).

@zxu123 zxu123 changed the title implement FieldValue for null and boolean. implement FieldValue for null, boolean, and array in C++. Jan 12, 2018
Copy link
Contributor Author

@zxu123 zxu123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored and lint-fixed.

namespace firestore {
namespace model {

using Type = FieldValue::Type;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work since FieldValue is not namespace.

/Users/zxu/Documents/GitHub/firebase-ios-sdk/Firestore/core/src/firebase/firestore/model/field_value.cc:29:19: error: using declaration
cannot refer to class member
using FieldValue::Type;
~~~~~~~~~~~~^
/Users/zxu/Documents/GitHub/firebase-ios-sdk/Firestore/core/src/firebase/firestore/model/field_value.cc:29:7: note: use an alias
declaration instead
using FieldValue::Type;
^
Type =


namespace {

bool Comparable(Type lhs, Type rhs) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

value_.array_value_.~vector();
break;
default:
; // The other types where there is nothing to worry about.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, at least for cmake:

/Users/zxu/Documents/GitHub/firebase-ios-sdk/Firestore/core/src/firebase/firestore/model/field_value.cc:60:13: error:
label at end of compound statement: expected statement
default:
^
;
1 error generated.


FieldValue& FieldValue::operator=(const FieldValue& value) {
// Not same type. Destruct old type first.
if (tag_ != value.tag_) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


switch(lhs.type()) {
case Type::Null:
return 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


using Type = FieldValue::Type;

TEST(FieldValue, NullType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

EXPECT_TRUE(small == small);
EXPECT_FALSE(small == large);
}
} // namespace model
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* All the different kinds of values that can be stored in fields in
* a document. The types of the same comparison order should be defined
* together as a group. The order of each group is defined by the Firestore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* backend.
*/
enum class Type {
Null, // Null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

union UnionValue {
// There is no null type as tag_ alone is enough for Null FieldValue.
bool boolean_value_;
std::vector<FieldValue> array_value_;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is now very close. Thanks for working through this.

namespace firestore {
namespace model {

using Type = FieldValue::Type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprising! Thanks for pointing out the details.

}

FieldValue FieldValue::ArrayValue(const std::vector<const FieldValue>& value) {
return ArrayValue(std::move(std::vector<const FieldValue>(value)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the std::move unnecessary here since the anonymous std::vector you've constructed here is already an rvalue?

This would be a little more obvious if you split the copy up from the invocation of the move constructor, e.g.

std::vector<const FieldValue> copy(value);
return ArrayValue(std::move(copy));

However, if you're just going to immediately copy the incoming value you can declare the parameter as by-value and let the compiler do it for you.

I.e. you can make this:

FieldValue FieldValue::ArrayValue(std::vector<const FieldValue> value) {
  return ArrayValue(std::move(value));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiled under Xcode this also generates a warning:

⚠️ /Users/travis/build/firebase/firebase-ios-sdk/Firestore/core/src/firebase/firestore/model/field_value.cc:119:21: moving a temporary object prevents copy elision [-Wpessimizing-move]
return ArrayValue(std::move(std::vector(value)));
^

You could definitely fix this just by removing the std::move.

Copy link
Contributor Author

@zxu123 zxu123 Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, going with the first way. The second way needs to remove the other constructor by rvalue reference or get ambiguous definition. So I'd keep both constructor, copy and move, which is now common in C++11 e.g. in std::vector (http://www.cplusplus.com/reference/vector/vector/vector/).


TEST(FieldValue, Assignment) {
FieldValue clone = FieldValue::TrueValue();
const FieldValue null_value = FieldValue::NullValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also copy. Did you mean to make this a reference? (const FieldValue& null_value would do it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, bad name. Meant to test copy operator=. (The next test case tests move operator=.)

FieldValue clone = FieldValue::TrueValue();
const FieldValue null_value = FieldValue::NullValue();
clone = null_value;
EXPECT_EQ(FieldValue::NullValue(), clone);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: FieldValue::TrueValue() should remain unchanged:

EXPECT_EQUAL(Type::Boolean, FieldValue::TrueValue());

Or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

FieldValue null_value = FieldValue::NullValue();
clone = std::move(null_value);
EXPECT_EQ(FieldValue::NullValue(), clone);
clone = std::move(clone);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really surprised this works.

The point of std::move to indicate that after the call that name will not be used again. The value with that name becomes invalid immediately after std::move returns (but before the assignment).

See here for more discussion:
https://stackoverflow.com/questions/24604285/behaviour-of-move-assignment-to-self

Sorry, I should have been clearer: it's the copy constructor/copy assignment that need to work when copying *this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works since the move operator= implementation for FieldValue uses std::swap and thus both sides are still well-defined after the call. I can go the other design (self-check+move), if that is more preferred. How do you think?

TEST(FieldValue, ArrayType) {
const FieldValue empty =
FieldValue::ArrayValue(std::vector<const FieldValue>{});
std::vector<const FieldValue> small_value_array = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what the names small_value_array and large_value_array mean here. The small one seems longer than the large one.

Also, you can skip the assignment when initializing.

std::vector<const FieldValue> small_value_array{
  // ...
};

Copy link
Contributor Author

@zxu123 zxu123 Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. small and large means the FieldValue constructed from them are small and large respective, not the array itself. Let me change it to another set of name to avoid confusion.

FIREBASE_EXPAND_STRINGIFY(expression)); \
} \
} while(0)
#define FIREBASE_ASSERT_WITH_EXPRESSION(condition, expression) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a surprising whitespace change. Are you on clang-format 6?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, clang-format version 6.0.0 (tags/google/stable/2017-11-14).

case Type::Array:
return lhs.array_value_ < rhs.array_value_;
default:
FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is wrong with our assertion declaration because this is generating a compile-time error:

❌ /Users/travis/build/firebase/firebase-ios-sdk/Firestore/core/src/firebase/firestore/model/field_value.cc:146:1: control may reach end of non-void function [-Werror,-Wreturn-type]

Copy link
Contributor Author

@zxu123 zxu123 Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is possible assertion does not break the flow for certain build (this case here) and thus still require a return value. The C++ sdk actually have macros like FIREBASE_ASSERT_RETURN and FIREBASE_ASSERT_RETURN_VOID, which however does not support message. Let me add a return value explicitly.

Copy link
Contributor Author

@zxu123 zxu123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take another look

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zxu123 zxu123 merged commit cac2c3f into master Jan 17, 2018
@zxu123 zxu123 deleted the cpp/fieldvalue branch January 17, 2018 18:18
rsgowman added a commit that referenced this pull request Mar 8, 2018
* Version bump for 4.8.1 Release

Updated the version numbers of pods which are being released in 4.8.1

* Update from master

Picking up a few last-minute changes to CHANGELOGs and tests for 4.8.1
release.

* Update Core info for M21.1

Update missing version bump for M21.1 for FirebaseCore.

* Remove over-aggressive assert.

closeWithFinalState: assumes delegate != nil, but that is not true if when
startWithdelegate: was called we entered backoff (performBackoffWithDelegate:)
and so self.delegate did not get assigned yet.

We could rework the code to make the assertion hold, but per offline
discussion this assert doesn't represent an invariant that we care about
and so I'm just removing it.

* Remove over-aggressive closeWithFinalState: delegate assert. (#656)

Fixes #596. closeWithFinalState: asserted delegate != nil, but that is not true if when
startWithdelegate: was called we entered backoff (performBackoffWithDelegate:)
and so self.delegate did not get assigned yet.

We could rework the code to make the assertion hold, but per offline
discussion this assert doesn't represent an invariant that we care about
maintaining and so I'm just removing it.

* Increase FirebaseAuth version for M21.1

This version was missed in the M21.1 version bump PR.

* Fix import formatting (#660)

* Fix issue @morganchen12 discovered where we weren't properly creating FIRQueryDocumentSnapshot instances. (#662)

* Validate clang-format compliance in travis (#648)

* Build gRPC for Firestore C++ (#652)

* Clean up quoting and other minor issues

* Reorganize CMake build output

Make it clearer which parts of the output pertain to external projects.

* Use a consistent ordering of ExternalProject arguments

* Prevent the top-level build from running in parallel

This prevents spurious failures when running make -j.

* Actually parse arguments in the xcodebuild function

* Use ExternalProject features when available

  * submodule limits from CMake 3.0
  * shallow clones from CMake 3.6
  * git progress output from CMake 3.8

* Only build the parts of leveldb we need

Skip building the tools and other libraries

* Avoid installing ExternalProjects

Consume build output directly so that we can build just the targets we
need. Installing causes all targets to be built.

This doesn't matter as much for these targets but the gRPC build
includes a ton of stuff we don't need so it's worth adopting this as a
general strategy.

* Define an external build for grpc

* Test that grpc can link successfully.

* Add a FindGRPC CMake module

* Actually comment ExternalProjext_GitSource

* Inject infoDictionary to fix flakey tests. (#664)

* Inject infoDictionary to fix flakey tests.

* Remove outdated comment, update format.

* Fix issue @morganchen12 discovered where we weren't properly creating FIRQueryDocumentSnapshot instances. (#662)

* Travis - run tests only for changed code (#665)

* Add assert_test to the Xcode build (#671)

* Exclude stdio-backed assert from the Xcode build

* Add assert_test to the Xcode build

* Enable warnings in the CMake build (#669)

* Enable warnings when building with GCC or clang

* Fix warnings

* Fix C++ lint errors (#668)

* Misc style.sh fixes

  * Allow test-only to use a revision; to check your changes since
    master:

    ./scripts/style.sh test-only master
  * Avoid diffing deleted files
  * 80 columns

* Fix C++ lint errors

* implement FieldValue for null, boolean, and array in C++. (#637)

* implement FieldValue for null and boolean.

* refactoring to use union type instead of poly

* refactor using union design intead of poly

* refactoring to use anonymous union and fix styles

* small fix

* add field_value_test to the project

* fix warning of cmake and fix style

* Simplify integration with googletest (#672)

This makes it possible to build the Firestore subproject with CLion
because it no longer needs to be told where googletest is.

* Add a cc_library to the CMake build (#670)

* Rewrite cc_test to take named arguments

Cut down on build file verbosity by having cc_test take SOURCES and
DEPENDS. The separate invocation of target_link_libraries is no longer
necessary.

* Add a cc_library rule to parallel cc_test

This cuts down on build file verbosity.

* Automatically add OBJC_FLAGS to cc_libraries if applicable

* Exclude platform-specific libraries from 'all'

This is makes it possible to declare this kind of library
unconditionally. Usage within a test or as a dependency will actually
trigger building.

* Restore secure_random_test.cc; clean-up comments

* Fix CMake build and lint warnings in field_value.cc (#677)

Fixes these cpplint warnings:

Firestore/core/src/firebase/firestore/model/field_value.cc:162:  Semicolon defining empty statement. Use {} instead.  [whitespace/semicolon] [5]
Firestore/core/src/firebase/firestore/model/field_value.cc:170:  Semicolon defining empty statement. Use {} instead.  [whitespace/semicolon] [5]
Firestore/core/src/firebase/firestore/model/field_value.cc:126:  Add #include <utility> for swap  [build/include_what_you_use] [4]

* Listen sequence numbers (#675)

* Generate and save sequence numbers for listens

* Add documentation

* Fix include path

* Fix unavailable comment

* Review feedback

* Fix build warnings by making void parameter explicit (#681)

* Add platform detection logic for SecureRandom (#676)

* Add CMake platform detection logic for SecureRandom

Now only builds secure_random_arc4random.cc if available.

Remove firebase/firestore/base/port.h. Nothing else was in that
directory.

* Add a SecureRandom implementation that uses OpenSSL

This is usable on Linux, Windows, and Android

* Properly check return from RAND_bytes

* Port comparison to C++ (#678)

This reimplements our comparison functions as C++ Comparators and then provides compatibility shims for interoperating with existing Objective-C usage.

A few specialized comparators aren't suitable for porting but only have a single usage (e.g. CompareBytes for comparing NSData * instances). In these cases I've moved them into the caller.

* Use int32_t for typeof(ID) in FSTDocumentReference

* Migrate callers of FSTComparison.h to Objective-C++

* Port comparison to C++

* Migrate usages of FSTComparison.h to C++ equivalents

* Remove FSTComparison

* Use Comparator in FieldValue. (#686)

* style.sh - output unformatted files in test-only and ignore generated config.h (#690)

* Cleanup imports and isEqual (#685)

* Fix headers

* Fix isEqual verbosity

* Fix isEqual for nullable properties

* Fix nullability on FSTTestDocSnapshot

* Fixing spelling error in FIRStorageErrors

* Update travis to use CocoaPods 1.4.0 (#692)

* add FIRUser behavior to documentation

* Disable Messaging build warnings (#697)

* Update FirebaseMessaging protos (#696)

* Adding enable/disable property to FCM token auto Initialization

* revert unrelated changes

* revert unrelated changes

* revert unrelated changes

* Adds explicit core graphics dependency to auth (#700)

* Properly publish Abseil sources as a part of the podspec (#704)

* Properly include abseil sources
* Exclude abseil tests

* Implement the rest of FieldValue types for C++ (#687)

* implement FieldValue for null and boolean.
* Implement number and string FieldValue.
* Implement object FieldValue.
* implement timestamp FieldValue.
* Implement number and string FieldValue.
* implement public type `Blob` and `GeoPoint`
* implement Blob FieldValue
* Implement GeoPoint FieldValue
* refactoring `Blob`

* README - FirebaseCore source pod must be included with all source pods (#705)

* Fix incorrect deprecation message (#688)

* Fix incorrect deprecation message for Obj-C and Swift

* Update CHANGELOG for M21.1 release (#679)

* normalize string_util (#708)

* refactoring string_util
* port string_util to iOS

* implement `TargetIdGenerator` in C++ for Firestore (#701)

* implement `TargetIdGenerator`

* address changes

* adding unit test for auto init enable function (#710)

* port TargetIdGenerator to iOS (#709)

* port TargetIdGenerator to iOS

* fix style

* move pointer property to instance variable

* TriggerTravis

* normalize and port the rest of Firebase/Port code (#713)

* normalize bits
* normalize ordered_code

* Fix b/72502745: OnlineState changes cause limbo document crash. (#470) (#714)

[PORT OF firebase/firebase-js-sdk#470]

Context: I made a previous change to raise isFromCache=true events when the
client goes offline. As part of this change I added an assert for
"OnlineState should not affect limbo documents", which it turns out was not
valid because:
* When we go offline, we set the view to non-current and call
	View.applyChanges().
* View.applyChanges() calls applyTargetChange() even though there's no target
	change and it recalculates limbo documents.
* When the view is not current, we consider no documents to be in limbo.
* Therefore all limbo documents are removed and so applyChanges() ends up
	returning unexpected LimboDocumentChanges.

Fix: I've modified the View logic so that we don't recalculate limbo documents
(and generate LimboDocumentChanges) when the View is not current, so now my
assert holds and there should be less spurious removal / re-adding of limbo
documents.

* travis: check for copyright in sources (#717)

* Add the C++ linter to the repo (#720)

* Fix a number of c++ build errors (#715)

* Move -fvisibility-inlines-hidden from common_flags to cxx_flags

This option isn't supported by C (and causes the build to fail under
at least rodete).

Manifested error was:

```
-- Looking for include file openssl/rand.h
-- Looking for include file openssl/rand.h - not found
CMake Error at core/src/firebase/firestore/util/CMakeLists.txt:94 (message):
  No implementation for SecureRandom available.

-- Configuring incomplete, errors occurred!
```

which is completely misleading. :(

* Fix exception include for std::logic_error

Was causing compiler error on (at least) rodete.

(http://en.cppreference.com/w/cpp/error/logic_error suggests that
stdexcept is the correct header.)

* Remove 'const' from vector contents.

vectors cannot contain const objects as the contained objects are
required to be assignable and copy constructable. (Not *quite* strictly
true; since c++11, this requirement now depends on the operations
performed on the container. But my compiler objects at any rate.)

http://en.cppreference.com/w/cpp/container/vector

https://stackoverflow.com/questions/8685257/why-cant-you-put-a-const-object-into-a-stl-container

* Add brackets as suggested (required) by my compiler.

* Add missing include

For LLONG_MIN, etc.

* Enable gnu extension to c++11 for firestore/util *test*.

We disable them by default (in cmake/CompilerSetup.cmake) but our tests
requires hexidecimal floating point, which is not supported in c++11
(though is supported in C++17, gnu++11, and others).

http://en.cppreference.com/w/cpp/language/floating_literal
https://bugzilla.redhat.com/show_bug.cgi?id=1321986

* Fix printf format for uint64_t

http://en.cppreference.com/w/cpp/types/integer
https://stackoverflow.com/questions/9225567/how-to-print-a-int64-t-type-in-c

* Allow 0 length printf template strings in tests.

* Get rid of a multi line comment.

The backslash is apparently interpreted by the compiler cause the next
line to be ignored too. In this case, the next line is (currently) a
comment, and would be ignored anyways. (But that doesn't stop the
compiler from yelling.)

* Run ./scripts/style.sh

* Version updates to 4.8.2 (#722)

* Use fixed-sized types (#719)

Should have caught this during review, but cpplint caught it

*  Import iterator_adaptors from google3 (#718)

* Import iterator_adapters from google3

* Remove -Wconversion which is annoyingly hard to satisfy

* Strip dependency on absl_container from iterator_adapters_test

* Format and lint iterator_adaptors

* More flexible copyright checking in Travis

* Add changelog entry for my last PR (oops) and also add a few that we missed last release. (#724)

* Add absl_strings to firebase_firestore_util_test dependencies (#725)

Required to link the test on rodete.

* Firestore DatabaseId in C++ (#727)

* Implement DataBaseId in C++

* add database_id_test to project

* fix project

* address changes

* fix style

* Schema migrations for LevelDB (#728)

* Implement schema versions

* Style fixes

* newlines, copyrights, assumptions

* Fix nullability

* Raw ptr -> shared_ptr

* kVersionTableGlobal -> kVersionGlobalTable

* Drop utils, move into static methods

* Drop extra include

* Add a few more comments

* Move version constant into migrations file

* formatting?

* Fix comment

* [FCM] Add completion handler to subscribe/unsubscribe topic actions

Added functionality not exposed in public header yet. I would leave to next FCM SDK owner to expose this functionality (and follow any required review process).

Bugs:
72701086

* Fix tests.

* Move all Firestore Objective-C to Objective-C++ (#734)

* Move all Firestore files to Objective-C++
* Update project file references
* Don't use module imports from Objective-C++
* Use extern "C" for C-accessible globals
* Work around more stringent type checking in Objective-C++
  * NSMutableDictionary ivars aren't implicitly casted to NSDictionary
  * FSTMaybeDocument callback can't be passed a function that accepts
    FSTDocument
  * NSComparisonResult can't be multiplied by -1 without casting
* Add a #include <inttypes.h> where needed
* Avoid using C++ keywords as variables
* Remove #if __cplusplus guards

* Start on ArraySortedMap in C++ (#721)

* Implement ArraySortedMap.remove
* Implement ArraySortedMap.insert
* Ensure ArraySortedMap.insert avoids copying on duplicates
* Port more ArraySortedMapTests

* Remove predecessorKey,Object,Document, etc (#735)

This is dead code.

I think it was probably useful in the RTDB because of the way it notified of changes, but we give changes with indexes in Firestore so I think we don't need it.

* Align tests and integration test header search paths (#737)

* fix (#739)

* Increase expectation timeout to 25 seconds. (#744)

I'm doing this to:
1) Experimentally see if it improves the flakiness we've been seeing in the Query Conformance Tests.
2) Insulate us from the fact that GRPC seems to take a /minimum/ of 10 seconds to reconnect (at least in some cases) after a connection failure.

I've opened b/72864027 to revisit this in the future.

* fix null block execution crash

* Make sure Firestore/core/include is in the podspec (#748)

* Skip 'update' step for external dependencies

We check them out from a git tag, so this *should* be a noop. However,
cmake seems to want to rebuild these dependencies every time you run
make as it assumes the dependency *might* have been updated. (In
practice, this isn't completely awful, as make notices the files haven't
changed, so files don't actually get recompiled. But the configure step
is still re-run and all the files still need to be rescanned.)

Skipping the update step speeds up the build considerably.

On my linux box, running:
  cmake .. && make -j && time make -j
takes ~8.5s prior to this CL and ~6.5 afterwards. (6s is used by the
test suite.) The upcoming protobuf addition would otherwise have made
this much worse. (It takes a long time to ./configure.)

* Add ability to build nanopb and protobuf

* Add instructions for building nanopb protos

Currently only supported on osx

* Add generated nanopb protos.

100% machine generated (except adding of the license).

* Import "well-known" protos (and generated nanopb files)

For use by nanopb (which otherwise doesn't know what to do with these.)

* Hook up nanopb to firestorep project

Use remote/serializer placeholder class as a hook for the test to ensure
nanopb headers can be found, and test can be linked.

* style.sh now ignores generated nanopb files

* ./style.sh

* Eliminate sequencing dependencies

We originally had this as it was thought that cmake would spawn n*m jobs
(where n is the number of jobs it was instructed to create, ie. make
-j8, and m is the number of external projects.) However, it isn't
supposed to do that, and doesn't appear to be doing that right now. So
we'll remove this.

If the problem re-appears, we'll add these back in. (Symptom was being
unable to spawn /bin/sh.)

* Downgrade nanopb from 0.4.0-dev to 0.3.8.

Also regenerate the protos

* Minor refactoring

* Ignore trailing whitespace in autogenerated nanopb files

* Update abseil-cpp to a new upstream (#754)

Update to bf7fc9986e20f664958fc227547fd8d2fdcf863e

* Add StrCat, StrJoin and the rest of //strings from abseil-cpp (#756)

From abseil-cpp version bf7fc9986e20f664958fc227547fd8d2fdcf863e

* Fix xcode build errors re nanopb

Involves adding PODS_ROOT/nanopb to include path (to allow include
<pb.h>) and Firestore/Protos/nanopb to include path (to allow include
"google/api/annotations.pb.h" and similar).

In both cases, this is to allow auto-generated code to function
properly.

* Fix firebaes typo (#755)

* Implement Firestore DatabaseInfo and port both Database{Id,Info} C++ to the iOS code (#738)

* implement Firestore DatabaseInfo in C++

* temporary stash changes; blocking on the massive renaming of .m to .mm

* add database_info_test to project

* finish port DatabaseId and fix style, modular fixing DatabaseInfo

* port DatabaseInfo

* remove FSTDatabase{ID,Info} and their tests from project

* fix unit test

* use namespace alias

* use namespace alias, leftover

* address more changes

* refactoring to use raw pointer instead of value for property

* address changes

* remove self->

* fix style

* remove the name suffix Alloc

* fix a bug

* C++ port: port FSTFieldPath and FSTResourcePath to C++ (#749)

Similar to Objective-C, FieldPath and ResourcePath share most of their interface (and implementation) by deriving from BasePath (using CRTP, so that factory methods in BasePath can return an instance of the derived class).

* Creating CHANGELOG for FCM (#764)

* add CHANGELOG for FCM

* fix the typo

* avoid using initWithSuiteName which does not support iOS 7 (#765)

* Updates version of Firebase Auth in Changelog (#771)

* Updates version of Firebase Auth in Changelog

* addresses comments

* Update CHANGELOG for Firestore v0.10.1 (#768)

* Explicitly specify the default constructor to FieldPath (#773)

Xcode prior to 8.3 does not accept an explicitly defaulted constructor
(`= default`) for the purposes of default initializing a const object.

This fixes a build failure under Xcode 8.2:

```
Firestore/core/src/firebase/firestore/model/field_path.cc:144:26: error: default initialization of an object of const type 'const firebase::firestore::model::FieldPath' without a user-provided default constructor
  static const FieldPath empty_path;
```

* Update deprecation message for Firestore. (#758)

* Update FIRFirestore.h

* Provide full command to enable debugging.

* Version bumps for 4.9.0 (#774)

* cmake build fixes (#770)

* Fix nanopb (in cmake build)

Look for binaries in the src dir (since that's where we build now.) This
error would be masked if a previous build had completed prior to
switching nanopb to build out of src.

Also, don't patch the protoc path multiple times. This could be
triggered by (eg) 'make && make clean && make'.

* Add resource_path.{h,cc} to the cmake build

* Fix signed/unsigned int comparison warnings

* Ensure FieldValue tag_ is initialized during cp/mv ctor.

Otherwise, the assignment operator attempts to deallocate based on the
(uninitialized) tag_ variable, posssibly leading to segfaults.

* Fix tests that throw exceptions.

The (previous) tests checked to ensure that an abort() occurs, but if
ABSL_HAVE_EXCEPTIONS is defined on non-macos (which is currently the
default) then the assertions will throw a std::logic_error rather than
abort()ing.

On macos, an exception is thrown too, but the exception doesn't derrive
from std::exception, so ASSERT_DEATH_* doesn't catch it (hence why
ASSERT_DEATH_* actually works.)

To resolve this, I've switched to ASSERT_ANY_THROW.

* Let Travis run for `CMake` test and `lint.sh` (#769)

* Fix nanopb (in cmake build)

Look for binaries in the src dir (since that's where we build now.) This
error would be masked if a previous build had completed prior to
switching nanopb to build out of src.

Also, don't patch the protoc path multiple times. This could be
triggered by (eg) 'make && make clean && make'.

* Add resource_path.{h,cc} to the cmake build

* Fix signed/unsigned int comparison warnings

* let Travis run for `CMake` test and `lint.sh`

* Ensure FieldValue tag_ is initialized during cp/mv ctor.

Otherwise, the assignment operator attempts to deallocate based on the
(uninitialized) tag_ variable, posssibly leading to segfaults.

* address change

* fix trailing space

* address change

* moving Firestore checks closer together

* Fix tests that throw exceptions.

The (previous) tests checked to ensure that an abort() occurs, but if
ABSL_HAVE_EXCEPTIONS is defined on non-macos (which is currently the
default) then the assertions will throw a std::logic_error rather than
abort()ing.

On macos, an exception is thrown too, but the exception doesn't derrive
from std::exception, so ASSERT_DEATH_* doesn't catch it (hence why
ASSERT_DEATH_* actually works.)

To resolve this, I've switched to ASSERT_ANY_THROW.

* ./scripts/lint.sh

* Move FieldValue::tag_ initializer to be in class.

* check Travis ulimit

* check travis limit

* set make -j 200 instead of unlimited

* use cpu core number instead of 200

* port Firestore Auth module in C++ (#733)

* Implement firestore/auth/user

* add user to project and some fixes

* implement firestore/auth/{credentials_provider,empty_credentials_provider}

* implement firestore/auth/firebase_credentials_provider

* refactoring firebase_credentials_provider and add (disabled but working) unit test

* add auth test to project

* address changes

* small fix to style and project

* fix the firebase_credentials_provider_test

* fix style

* address changes

* revert the change to static mutex_

* remove my custom plist path

* fix style

* address changes

* refactoring FirebaseCredentialsProvider to fix the issue w.r.t. auth global dispatch queue

* add /*force_refresh=*/ tag to bool literal for style purpose

* Use a shared_ptr/weak_ptr handoff on FirebaseCredentialsProvider (#778)

* Revert "refactoring FirebaseCredentialsProvider to fix the issue w.r.t. auth global dispatch queue"

This reverts commit 87175a4.

* Use a shared_ptr/weak_ptr handoff on FirebaseCredentialsProvider

This avoids any problems with callsbacks retaining pointers to objects
destroyed by a C++ destructor

* port Firestore SnapshotVersion in C++ (#767)

* implement SnapshotVersion and test

* Fix Core CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF warnings (#779)

* C++ port: add C++ equivalent of FSTDocumentKey. (#762)

Also move kDocumentKeyPath to the only point of usage - make it a static
member variable of FieldPath.

* Strawman C++ API (#763)

Incomplete, and what does exist in still slightly vague. It's expected
that this will change.

* Move to explicit nil check. (#782)

* Update FieldValue of type Reference (#775)

* update FieldValue of type Reference

* address change

* fix bad path string literal in test

* use ReferenceValue and qualified name

* Port Firestore Document to C++ (#777)

* implement SnapshotVersion and test

* update project

* implement MaybeDocument and test

* move snapshot-version from core to model

* fix a bug

* implement Document and test

* implement NoDocument

* adding type tag and fix style

* fix a few bugs, discovered after merging and test run.

* add assert to check FieldValue type and more test for comparision.

* address changes

* allow moving FieldValue to construct Document.

* address changes

* add document tests to project

* use std::less convention

* make Type::Unknown static initializer

* Cleaning up implicit retain for the RTDB and Storage

* Fix double parsing on 32 bit devices. (#787)

* Keep track of number of queries in the query cache (#776)

* Implement schema versions

* Style fixes

* newlines, copyrights, assumptions

* Fix nullability

* Raw ptr -> shared_ptr

* kVersionTableGlobal -> kVersionGlobalTable

* Drop utils, move into static methods

* Drop extra include

* Add a few more comments

* Move version constant into migrations file

* formatting?

* Fix comment

* Split add and update queryData

* Work on adding targetCount

* More work on count

* Using shared_ptr

* Implement count for query cache

* use quotes

* Add cast

* Styling

* Revert year bump in copyright

* Add adversarial key to migration test

* Add comment

* Fix style

* style fix

* fix flaky test (#788)

* Fix off-by-one error in Auth changelog (#789)

* Serialize and deserialize null (#783)

* Build (grpc's) nanopb with -DPB_FIELD_16BIT

We require (at least) 16 bit fields. (By default, nanopb uses 8 bit
fields, ie allowing up to 256 field tags.)

Also note that this patch adds this to grpc's nanopb, rather than to our
nanopb. We'll need to eventually either:
a) we instruct grpc to use our nanopb
b) we rely on grpc's nanopb instead of using our own.

(^ marked as a TODO for now.)

* Add some dependant protos

Imported from protobuf. Nanopb requires these to be present (though
anything using libprotobuf does not, as these are already built into
that.)

* Add generated nanopb protos based off of newly added proto definitions

* Build the nanopb protos

* Serialize and deserialize null

* Actually ignore events on inactive streams, rather than just logging that we're going to. (#790)

* Improve documentation on auto-init property in FCM. (#792)

* Fixed capitalization of init in test function. (#797)

* Update README.md with code markup (#800)

Add code markup to a few paths for consistency.

* replacing Auth/FSTUser by C++ auth implementation (#804)

* replacing Auth/FSTUser by C++ auth implementation

* address changes

* DispatchQueue delayed callback improvements + testing (#784)

Basically a port of firebase/firebase-js-sdk@a1e346f and firebase/firebase-js-sdk@fce4168

* Introduces a DelayedCallback helper class in FSTDispatchQueue to encapsulate delayed callback logic.
* Adds cancellation support.
* Updates the idle timer in FSTStream to use new cancellation support.
* Adds a FSTTimerId enum for identifying delayed operations on the queue and uses it to identify our existing backoff and idle timers.
* Added containsDelayedCallback: and runDelayedCallbacksUntil: methods to FSTDispatchQueue which can be used from tests to check for the presence of a callback or to schedule them to run early.
* Removes FSTTestDispatchQueue and changes idle tests to use new test methods.

* Enable -Wcomma for our build; disable it for abseil. (#799)

In order to use different cflags for abseil, this patch splits it out
into a subspec within the pod.

The cmake side of things "just works" since Firestore/CMakeLists.txt
includes abseil before setting our compiler flags.

* Serialize (and deserialize) bool values (#791)

* Require official 1.4.0 for min CocoaPods version (#806)

* Disable -Wrange-loop-analysis for abseil (#807)

absl includes code like this:
```
void fn(std::initializer_list<absl::string_view> pieces) {
  ...
  for (const absl::string_view piece : pieces) total_size += piece.size();
```

clang objects, suggesting that a reference should be used instead, i.e.:
```
  for (const absl::string_view& piece : pieces) total_size += piece.size();
```

But:
a) we don't want to touch absl code
b) string_views are cheap to copy (and absl recommends copying
string_views rather than taking references as it may result in smaller
code)
c) some brief, naive benchmarking suggests there's no significant
different in this case (i.e. (b) is correct.)

Note that -Wrange-loop-analysis is already exlicitly enabled in our
cmake build.

* Delete stale Firestore instances after FIRApp is deleted. (#809)

* replacing FSTGetTokenResult by C++ Token implementation (#805)

* replacing Auth/FSTUser by C++ auth implementation

* address changes

* replacing FSTGetTokenResult by C++ Token implementation

* address changes

* address changes

* fix another const& v.s. dispatch bug

* fix more const& v.s. dispatch bug  zxu123 committed

* fix

* passing by value in callback

* Fix two stream close issues (b/73167987, b/73382103). (#810)

* Fix b/73167987: Upon receiving a permanent write error when we had additional
  pendingWrites to send, we were restarting the stream with a new delegate and
  then immediately setting the delegate to nil, causing the stream to ignore
  all GRPC events for the stream.
* Fix b/73382103: We were attempting to gracefully teardown the write stream (i.e.
  send an empty WriteRequest) even when the stream was already failed due
  to an error. This caused no harm other than log pollution, but I fixed it.
* Use -[GRPCCall setResponseDispatchQueue] to dispatch GRPC callbacks directly onto the Firestore worker queue. This saves a double-dispatch and simplifies our logic.
* Add stricter assertions regarding stream state now that dispatch queue / callback filter race conditions are eliminated.

* [En|De]codeUnsignedVarint -> [En|De]codeVarint (#817)

* [En|De]codeUnsignedVarint -> [En|De]codeVarint

The 'unsigned' portion was misleading, as these varints work with both
signed and unsigned integers. (The 'signed' varints also work with both
signed and unsigned integers, but use zig-zag encoding so that negative
numbers are encoded more efficiently. Note that 'signed' varints aren't
used in the Value proto, so won't appear in the serializer class for at
least the short term.)

Added some docstrings to help disambiguate this.

* Make FSTTimestamp into a public Firestore class (#698)

- FSTTimestamp is now FIRTimestamp, under Firestore/Source/{Public,API}. This is a temporary solution; eventually, FIRTimestamp is supposed to live somewhere under Firebase;
- move most internal Timestamp methods to the public header (the only exception is ISOString).

* Fix implicit retain self warnings (#808)

Xcode has starting warning about us implicitly retaining self references
within blocks. This commit fixes it by explicitly mentioning self. No
real changes are introduced here; this is effectively just making
implicit behaviour explicit.

* Accept FIRTimestamp where NSDate is currently accepted as a parameter (#823)

* Fix trivial mem leak in the test suite (#828)

Reduces noise while running valgrind so that I can see the leaks that
I'm introducing. :/

* Serialize (and deserialize) int64 values (#818) (#829)

*  Avoid wrapping and rewrapping NSStrings when constructing DatabaseId (#833)

* Avoid wrapping and rewrapping NSStrings when constructing DatabaseId

* Shorten DatabaseId::kDefaultDatabaseId

* Fix Firestore tests for M22 (#834)

* Add FIRFirestoreTests to the Firestore Xcode project

* Avoid waitForExpectations:timeout:

This API was added in Xcode 8.3, but we still build production releases
with Xcode 8.2. waitForExpectationsWithTimeout:handler: is available
from Xcode 7.2.

* Add AppForUnitTesting

Add a utility for constructing a Firebase App for testing.

* Handle the nil UID from FIRAuth

* Avoid running CMake tests twice

* Only build app_testing on Apple platforms

* Revise test.sh messages

* Avoid warnings about failing to override a designated initializer (#832)

* address PR comments

* Refactor [En|De]codeVarint to be symetric wrt tags (#837)

Since we can't decode a value before knowing it's type, I've pulled the
tag handling out of these methods.

More context over here:
#829

* Fix lint warnings (#840)

* Don't build firebase_firestore_testutil_apple on non-apple platforms. (#841)

Was failing the cmake build on linux.

* Initial Carthage distribution instructions (#821)

I couldn't find a way to get the Carthage installer to install Resources, so withdrawing Firestore and Invites. The other 11 components passed testing.

* Update CHANGELOG for release (#845)

* improve the documentations on auto init property

* adjust the comments

* Add build infrastructure for Codable support in Firestore (#815)

* Add Firestore_SwiftTests_iOS target to Xcode

* Add FirebaseFirestoreSwift podspec

* Add Firestore_SwiftTests_iOS to the Podfile

* Add CodableGeoPoint and tests

* Version FirebaseFirestoreSwift separately

* Move -messageWasLogged to FIRTestCase

This makes it accessible to other test classes.

* Add third-party library version registration

This will allow us to collect the version of platform libraries that
developers use in conjunction with Firebase.

* Fixes clang warnings for Auth (#848)

* Fixes clang warnings for Auth

* Addresses comments

* Revert "Move -messageWasLogged to FIRTestCase"

This reverts commit dfda142.

* Add tests for useragent

Tests a variety of simple use cases.

* Auto-style swift sources (#847)

* Fix bash style issues

* Exclude additional build output directories

* Format swift files with scripts/style.sh

* Reformat swift sources

* Allow swiftformat 0.32.0 on travis

* PR feedback

* Add FirebaseCore version reporting

I've also added clearing of the library names for tests to avoid the
auto found versions on load.

* Deflake tests

* Updating RTDB Changelog for v4.1..5

* Update CHANGELOG.md

* Style fixes

* Change library name

* Update CHANGELOG.md

* Update CHANGELOG.md

* Add XCode and Apple SDK versions

* Update CHANGELOG for Firestore v0.10.2 (#856)

* Manually fix clang-format issues

* Remove unnecessary nonnull annotations

* Update changelog for release (#857)

* Updates changelog in preparation for release

* Adds another change.

* Update Core CHANGELOG for 4.0.16 (#858)

* Convert cmake build to (mostly) use urls rather than git clones (#852)

Exception: grpc. Due to it's use of git submodules, it's not completely trivial to convert it (though probably wouldn't be too much more work.)

This helps address our build being throttled. (Maybe. This assumes github allows more fetching of tgz's than clones.) It should also speed up our build times.

The downloaded tarballs are placed into ${PROJECT_BINARY_DIR}/downloads. This allows for eventual caching in travis.

* Eliminate TypedValue and serialize direct from FieldValue to bytes. (#860)

This will likely only apply for proto messages that use 'oneof's. (Because we need to serialize these manually.)

The problem was that as we were adding additional types, TypeValue was evolving into a parallel implementation of the FieldValue union.

When serializing/deserializing oneofs we need to supply a custom value to serialize and a custom function to do the work. There's no value in translating from FieldValue to TypeValue just to store as this custom object. We might as well just store the FieldValue model directly and write the custom serializer/deserializer to use the model directly.

* replacing Auth by C++ auth implementation (#802)

* lazy replacing FST(Firebase)CredentialsProvider by (Firebase)CredentialsProvider

* lazy replacing FSTUser by User

* adding error-code parameter to TokenListener

* actually use const user& instead of pointer; also add an error util

* add HashUser and pass into the unordered_map

* use User in test

* use c++ CredentialsProvider and subclass in test

* fix unit test

* use explicit capture in lambda instead of capture all by reference

* cache currentUser explicitly when reset sync engineer test driver

* objc object should be captured by value in lambda

* replacing Auth/FSTUser by C++ auth implementation

* address changes

* replacing FSTGetTokenResult by C++ Token implementation

* address changes

* fix unintentional change in merging

* patch the change in objc Auth up-stream

* somehow, the lambda-version of set-user-change-listener does not work... fallback to block

* address changes

* fix another const& v.s. dispatch bug

* fix more const& v.s. dispatch bug  zxu123 committed

* fix a bad sync line

* address changes

* address change

* address change

* fix upstream change from merge

* fix upstream changes

* Suggested fixes for cpp/port_auth (#846)

* Get rid of MockDatastore factory

This avoids the need to statically allocate (and leak) a credentials
provider

* Use absl::make_unique

std::make_unique technically does not exist until C++14.

* #include <utility> for std::move

* Use std::future for the initial user

* fix style

* Add FieldValue.boolean_value() (#862)

* style.sh (for swift)

* remove forward declarations for classes that no longer exist
minafarid pushed a commit to minafarid/firebase-ios-sdk that referenced this pull request Jun 6, 2018
* implement FieldValue for null and boolean.

* refactoring to use union type instead of poly

* refactor using union design intead of poly

* refactoring to use anonymous union and fix styles

* small fix

* add field_value_test to the project

* fix warning of cmake and fix style
@firebase firebase locked and limited conversation to collaborators Nov 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants