Skip to content

Commit

Permalink
Rename metkit_request to metkit_marsrequest
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisspyB committed Dec 11, 2024
1 parent 1b03851 commit 3907511
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 45 deletions.
34 changes: 17 additions & 17 deletions src/metkit/api/metkit_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ extern "C" {

// ---------------------------------------------------------------------------------------------------------------------

struct metkit_request_t : public metkit::mars::MarsRequest {
struct metkit_marsrequest_t : public metkit::mars::MarsRequest {
using metkit::mars::MarsRequest::MarsRequest;
metkit_request_t(const metkit::mars::MarsRequest& k) :
metkit_marsrequest_t(const metkit::mars::MarsRequest& k) :
metkit::mars::MarsRequest(k) {}
};

Expand Down Expand Up @@ -152,7 +152,7 @@ int metkit_initialise() {
// PARSING
// -----------------------------------------------------------------------------

int metkit_parse_mars_request(const char* str, metkit_requestiterator_t** requests, bool strict) {
int metkit_parse_marsrequest(const char* str, metkit_requestiterator_t** requests, bool strict) {
return tryCatch([requests, str, strict] {
ASSERT(requests);
ASSERT(str);
Expand All @@ -165,21 +165,21 @@ int metkit_parse_mars_request(const char* str, metkit_requestiterator_t** reques
// REQUEST
// -----------------------------------------------------------------------------

int metkit_new_request(metkit_request_t** request) {
int metkit_new_marsrequest(metkit_marsrequest_t** request) {
return tryCatch([request] {
ASSERT(request);
*request = new metkit_request_t();
*request = new metkit_marsrequest_t();
});
}

int metkit_free_request(const metkit_request_t* request) {
int metkit_free_marsrequest(const metkit_marsrequest_t* request) {
return tryCatch([request] {
ASSERT(request);
delete request;
});
}

int metkit_request_add(metkit_request_t* request, const char* param, const char* values[], int numValues) {
int metkit_marsrequest_add(metkit_marsrequest_t* request, const char* param, const char* values[], int numValues) {
return tryCatch([request, param, values, numValues] {
ASSERT(request);
ASSERT(param);
Expand All @@ -193,23 +193,23 @@ int metkit_request_add(metkit_request_t* request, const char* param, const char*
});
}

int metkit_request_set_verb(metkit_request_t* request, const char* verb) {
int metkit_marsrequest_set_verb(metkit_marsrequest_t* request, const char* verb) {
return tryCatch([request, verb] {
ASSERT(request);
ASSERT(verb);
request->verb(verb);
});
}

int metkit_request_verb(const metkit_request_t* request, const char** verb) {
int metkit_marsrequest_verb(const metkit_marsrequest_t* request, const char** verb) {
return tryCatch([request, verb] {
ASSERT(request);
ASSERT(verb);
*verb = request->verb().c_str();
});
}

int metkit_request_has_param(const metkit_request_t* request, const char* param, bool* has) {
int metkit_marsrequest_has_param(const metkit_marsrequest_t* request, const char* param, bool* has) {
return tryCatch([request, param, has] {
ASSERT(request);
ASSERT(param);
Expand All @@ -218,15 +218,15 @@ int metkit_request_has_param(const metkit_request_t* request, const char* param,
});
}

int metkit_request_params(const metkit_request_t* request, metkit_paramiterator_t** params) {
int metkit_marsrequest_params(const metkit_marsrequest_t* request, metkit_paramiterator_t** params) {
return tryCatch([request, params] {
ASSERT(request);
ASSERT(params);
*params = new metkit_paramiterator_t(request->params());
});
}

int metkit_request_count_values(const metkit_request_t* request, const char* param, size_t* count) {
int metkit_marsrequest_count_values(const metkit_marsrequest_t* request, const char* param, size_t* count) {
return tryCatch([request, param, count] {
ASSERT(request);
ASSERT(param);
Expand All @@ -235,7 +235,7 @@ int metkit_request_count_values(const metkit_request_t* request, const char* par
});
}

int metkit_request_value(const metkit_request_t* request, const char* param, int index, const char** value) {
int metkit_marsrequest_value(const metkit_marsrequest_t* request, const char* param, int index, const char** value) {
return tryCatch([request, param, index, value] {
ASSERT(request);
ASSERT(param);
Expand All @@ -244,7 +244,7 @@ int metkit_request_value(const metkit_request_t* request, const char* param, int
});
}

int metkit_request_values(const metkit_request_t* request, const char* param, const char** values[], size_t* numValues) {
int metkit_marsrequest_values(const metkit_marsrequest_t* request, const char* param, const char** values[], size_t* numValues) {
return tryCatch([request, param, values, numValues] {
ASSERT(request);
ASSERT(param);
Expand All @@ -259,7 +259,7 @@ int metkit_request_values(const metkit_request_t* request, const char* param, co
});
}

int metkit_request_expand(const metkit_request_t* request, metkit_request_t* expandedRequest, bool inherit, bool strict) {
int metkit_marsrequest_expand(const metkit_marsrequest_t* request, metkit_marsrequest_t* expandedRequest, bool inherit, bool strict) {
return tryCatch([request, expandedRequest, inherit, strict] {
ASSERT(request);
ASSERT(expandedRequest);
Expand All @@ -269,7 +269,7 @@ int metkit_request_expand(const metkit_request_t* request, metkit_request_t* exp
});
}

int metkit_request_merge(metkit_request_t* request, const metkit_request_t* otherRequest) {
int metkit_marsrequest_merge(metkit_marsrequest_t* request, const metkit_marsrequest_t* otherRequest) {
return tryCatch([request, otherRequest] {
ASSERT(request);
ASSERT(otherRequest);
Expand All @@ -295,7 +295,7 @@ int metkit_requestiterator_next(metkit_requestiterator_t* list) {
}});
}

int metkit_requestiterator_request(const metkit_requestiterator_t* list, metkit_request_t* request) {
int metkit_requestiterator_request(const metkit_requestiterator_t* list, metkit_marsrequest_t* request) {
return tryCatch([list, request] {
ASSERT(list);
ASSERT(request);
Expand Down
32 changes: 16 additions & 16 deletions src/metkit/api/metkit_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ extern "C" {
* TYPES
* -----*/

struct metkit_request_t;
typedef struct metkit_request_t metkit_request_t;
struct metkit_marsrequest_t;
typedef struct metkit_marsrequest_t metkit_marsrequest_t;

struct metkit_requestiterator_t;
/** RequestIterator for iterating over vector of Request instances */
Expand Down Expand Up @@ -78,7 +78,7 @@ int metkit_initialise();
* @param requests Allocates RequestIterator object
* @return int Error code
*/
int metkit_parse_mars_request(const char* str, metkit_requestiterator_t** requests, bool strict = false);
int metkit_parse_marsrequest(const char* str, metkit_requestiterator_t** requests, bool strict = false);

/* ---------------------------------------------------------------------------------------------------------------------
* REQUEST
Expand All @@ -88,13 +88,13 @@ int metkit_parse_mars_request(const char* str, metkit_requestiterator_t** reques
* @param request new Request instance
* @return int Error code
*/
int metkit_new_request(metkit_request_t** request);
int metkit_new_marsrequest(metkit_marsrequest_t** request);

/** Deallocates Request object and associated resources.
* @param request Request instance
* @return int Error code
*/
int metkit_free_request(const metkit_request_t* request);
int metkit_free_marsrequest(const metkit_marsrequest_t* request);

/** Add parameter and values to request
* @param request Request instance
Expand All @@ -103,45 +103,45 @@ int metkit_free_request(const metkit_request_t* request);
* @param numValues number of values
* @return int Error code
*/
int metkit_request_add(metkit_request_t* request, const char* param, const char* values[], int numValues);
int metkit_marsrequest_add(metkit_marsrequest_t* request, const char* param, const char* values[], int numValues);

/** Set verb in Request object
* @param request Request instance
* @param verb verb to set
* @return int Error code
*/
int metkit_request_set_verb(metkit_request_t* request, const char* verb);
int metkit_marsrequest_set_verb(metkit_marsrequest_t* request, const char* verb);

/** Returns the verb in Request object
* @param request Request instance
* @param verb verb in request
* @return int Error code
*/
int metkit_request_verb(const metkit_request_t* request, const char** verb);
int metkit_marsrequest_verb(const metkit_marsrequest_t* request, const char** verb);

/** Returns whether parameter is in Request object
* @param request Request instance
* @param param parameter name
* @param has whether parameter exists in request
* @return int Error code
*/
int metkit_request_has_param(const metkit_request_t* request, const char* param, bool* has);
int metkit_marsrequest_has_param(const metkit_marsrequest_t* request, const char* param, bool* has);

/** Returns ParamIterator of parameters in request. Resulting ParamIterator
* must be deallocated with metkit_free_paramiterator
* @param request Request instance
* @param params Allocates ParamIterator object for parameter names in request
* @return int Error code
*/
int metkit_request_params(const metkit_request_t* request, metkit_paramiterator_t** params);
int metkit_marsrequest_params(const metkit_marsrequest_t* request, metkit_paramiterator_t** params);

/** Returns number of values for specific parameter in Request object
* @param request Request instance
* @param param parameter name in request
* @param count number of values for param in request
* @return int Error code
*/
int metkit_request_count_values(const metkit_request_t* request, const char* param, size_t* count);
int metkit_marsrequest_count_values(const metkit_marsrequest_t* request, const char* param, size_t* count);

/** Returns value for specific parameter and index in Request object
* @param request Request instance
Expand All @@ -150,7 +150,7 @@ int metkit_request_count_values(const metkit_request_t* request, const char* par
* @param value retrieved value
* @return int Error code
*/
int metkit_request_value(const metkit_request_t* request, const char* param, int index, const char** value);
int metkit_marsrequest_value(const metkit_marsrequest_t* request, const char* param, int index, const char** value);

/** Returns values for specific parameter Request object
* @param request Request instance
Expand All @@ -159,7 +159,7 @@ int metkit_request_value(const metkit_request_t* request, const char* param, int
* @param numValues number of values for param in request
* @return int Error code
*/
int metkit_request_values(const metkit_request_t* request, const char* param, const char** values[], size_t* numValues);
int metkit_marsrequest_values(const metkit_marsrequest_t* request, const char* param, const char** values[], size_t* numValues);

/** Populates empty Request object by expanding existing request
* @param request Request instance to be expanded
Expand All @@ -168,14 +168,14 @@ int metkit_request_values(const metkit_request_t* request, const char* param, co
* @param strict it true, raise error rather than warning on invalid values
* @return int Error code
*/
int metkit_request_expand(const metkit_request_t* request, metkit_request_t* expandedRequest, bool inherit = true, bool strict = false);
int metkit_marsrequest_expand(const metkit_marsrequest_t* request, metkit_marsrequest_t* expandedRequest, bool inherit = true, bool strict = false);

/** Merges other Request object into existing request
* @param request Request instance to contain result of merge
* @param otherRequest other Request instance to merge
* @return int Error code
*/
int metkit_request_merge(metkit_request_t* request, const metkit_request_t* otherRequest);
int metkit_marsrequest_merge(metkit_marsrequest_t* request, const metkit_marsrequest_t* otherRequest);

/* ---------------------------------------------------------------------------------------------------------------------
* REQUEST ITERATOR
Expand All @@ -198,7 +198,7 @@ int metkit_requestiterator_next(metkit_requestiterator_t* list);
* @param request empty Request instance to populate with data
* @return int Error code
*/
int metkit_requestiterator_request(const metkit_requestiterator_t* list, metkit_request_t* request);
int metkit_requestiterator_request(const metkit_requestiterator_t* list, metkit_marsrequest_t* request);

/* ---------------------------------------------------------------------------------------------------------------------
* PARAM ITERATOR
Expand Down
24 changes: 12 additions & 12 deletions tests/test_c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,55 @@ namespace metkit::test {

CASE( "Request get/set" ) {

metkit_request_t* request = nullptr;
metkit_marsrequest_t* request = nullptr;

metkit_new_request(&request);
metkit_new_marsrequest(&request);
EXPECT(request);

// set/get verb
metkit_request_set_verb(request, "retrieve");
metkit_marsrequest_set_verb(request, "retrieve");
const char* verb = nullptr;
metkit_request_verb(request, &verb);
metkit_marsrequest_verb(request, &verb);
EXPECT(strcmp(verb, "retrieve") == 0);

// set array of values
const char* dates[] = {"20200101", "20200102", "20200103"};
metkit_request_add(request, "date", dates, 3);
metkit_marsrequest_add(request, "date", dates, 3);

// set single value
const char* expver = "xxxx";
metkit_request_add(request, "expver", &expver, 1);
metkit_marsrequest_add(request, "expver", &expver, 1);

// check values
bool has = false;
metkit_request_has_param(request, "date", &has);
metkit_marsrequest_has_param(request, "date", &has);
EXPECT(has);

metkit_request_has_param(request, "random", &has);
metkit_marsrequest_has_param(request, "random", &has);
EXPECT(!has);

size_t count = 0;
metkit_request_count_values(request, "date", &count);
metkit_marsrequest_count_values(request, "date", &count);
EXPECT_EQUAL(count, 3);

for (size_t i = 0; i < count; i++) {
const char* value = nullptr;
metkit_request_value(request, "date", i, &value);
metkit_marsrequest_value(request, "date", i, &value);
EXPECT(strcmp(value, dates[i]) == 0);
}

// all values
const char** values = nullptr;
count = 0;
metkit_request_values(request, "date", &values, &count);
metkit_marsrequest_values(request, "date", &values, &count);
EXPECT_EQUAL(count, 3);

for (size_t i = 0; i < count; i++) {
EXPECT(strcmp(values[i], dates[i]) == 0);
}

// done
metkit_free_request(request);
metkit_free_marsrequest(request);
}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 3907511

Please sign in to comment.