Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
a-maurice committed Oct 17, 2024
1 parent eb775e1 commit 25de448
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions analytics/src/analytics_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ void AddToBundle(JNIEnv* env, jobject bundle, const char* key, int64_t value) {
env->DeleteLocalRef(key_string);
}

// Add an ArrayList to the given Bundle.
void AddArrayListToBundle(JNIEnv* env, jobject bundle, const char* key,
jobject arraylist) {
jstring key_string = env->NewStringUTF(key);
Expand All @@ -365,6 +366,7 @@ void AddArrayListToBundle(JNIEnv* env, jobject bundle, const char* key,
env->DeleteLocalRef(key_string);
}

// Add a Bundle to the given Bundle.
void AddBundleToBundle(JNIEnv* env, jobject bundle, const char* key,
jobject inner_bundle) {
jstring key_string = env->NewStringUTF(key);
Expand All @@ -375,8 +377,11 @@ void AddBundleToBundle(JNIEnv* env, jobject bundle, const char* key,
env->DeleteLocalRef(key_string);
}

// Declared here so that it can be used, defined below.
jobject MapToBundle(JNIEnv* env, const std::map<Variant, Variant>& map);

// Converts the given vector into a Java ArrayList. It is up to the
// caller to delete the local reference when done.
jobject VectorToArrayList(JNIEnv* env, const std::vector<Variant>& vector) {
jobject arraylist = env->NewObject(
util::array_list::GetClass(),
Expand All @@ -388,6 +393,7 @@ jobject VectorToArrayList(JNIEnv* env, const std::vector<Variant>& vector) {
env->CallBooleanMethod(
arraylist, util::array_list::GetMethodId(util::array_list::kAdd),
bundle);
util::CheckAndClearJniExceptions(env);
env->DeleteLocalRef(bundle);
} else {
LogError("VectorToArrayList: Unsupported type (%s) within vector.",
Expand All @@ -397,6 +403,7 @@ jobject VectorToArrayList(JNIEnv* env, const std::vector<Variant>& vector) {
return arraylist;
}

// Converts and adds the Variant to the given Bundle.
bool AddVariantToBundle(JNIEnv* env, jobject bundle, const char* key,
const Variant& value) {
if (value.is_int64()) {
Expand Down Expand Up @@ -428,6 +435,8 @@ bool AddVariantToBundle(JNIEnv* env, jobject bundle, const char* key,
return true;
}

// Converts the given map into a Java Bundle. It is up to the caller
// to delete the local reference when done.
jobject MapToBundle(JNIEnv* env, const std::map<Variant, Variant>& map) {
jobject bundle =
env->NewObject(util::bundle::GetClass(),
Expand Down
4 changes: 4 additions & 0 deletions analytics/src/analytics_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ void LogEvent(const char* name) {
[FIRAnalytics logEventWithName:@(name) parameters:@{}];
}

// Declared here so that it can be used, defined below.
NSDictionary* MapToDictionary(const std::map<Variant, Variant>& map);

// Converts the given vector into an ObjC NSArray of ObjC objects.
NSArray* VectorToArray(const std::vector<Variant>& vector) {
NSMutableArray* array = [NSMutableArray arrayWithCapacity:vector.size()];
for (const Variant& element : vector) {
Expand All @@ -247,6 +249,7 @@ void LogEvent(const char* name) {
return array;
}

// Converts and adds the Variant to the given Dictionary.
bool AddVariantToDictionary(NSMutableDictionary* dict, NSString* key, const Variant& value) {
if (value.is_int64()) {
[dict setObject:[NSNumber numberWithLongLong:value.int64_value()] forKey:key];
Expand All @@ -273,6 +276,7 @@ bool AddVariantToDictionary(NSMutableDictionary* dict, NSString* key, const Vari
return true;
}

// Converts the given map into an ObjC dictionary of ObjC objects.
NSDictionary* MapToDictionary(const std::map<Variant, Variant>& map) {
NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:map.size()];
for (const auto& pair : map) {
Expand Down

0 comments on commit 25de448

Please sign in to comment.