未验证 提交 32c699d8 编写于 作者: W wanderingbort 提交者: GitHub

Merge pull request #1359 from michaelbpaulson/master

feat(scope): Scope was missing from the api for single index tables.
...@@ -366,7 +366,7 @@ struct table { ...@@ -366,7 +366,7 @@ struct table {
/** /**
* @brief Fetches a record from the table. * @brief Fetches a record from the table.
* @details Fetches a record from the table. * @details Fetches a record from the table.
* @param p - reference to primary key to retrieve * @param p - reference to primary key to retrieve
* @param r - reference to a record to load the value to. * @param r - reference to a record to load the value to.
* @param s - account scope. default is current scope of the class * @param s - account scope. default is current scope of the class
...@@ -381,7 +381,7 @@ struct table { ...@@ -381,7 +381,7 @@ struct table {
/** /**
* @brief Store a record in the table. * @brief Store a record in the table.
* @details Store a record in the table. * @details Store a record in the table.
* @param r - reference to a record to store. * @param r - reference to a record to store.
* @param s - account scope. default is current scope of the class * @param s - account scope. default is current scope of the class
* *
...@@ -394,7 +394,7 @@ struct table { ...@@ -394,7 +394,7 @@ struct table {
/** /**
* @brief Update a record in the table. * @brief Update a record in the table.
* @details Update a record in the table. * @details Update a record in the table.
* @param r - reference to a record to update. * @param r - reference to a record to update.
* @param s - account scope. default is current scope of the class * @param s - account scope. default is current scope of the class
* *
...@@ -407,7 +407,7 @@ struct table { ...@@ -407,7 +407,7 @@ struct table {
/** /**
* @brief Remove a record from the table. * @brief Remove a record from the table.
* @details Remove a record from the table. * @details Remove a record from the table.
* @param r - reference to a record to remove. * @param r - reference to a record to remove.
* @param s - account scope. default is current scope of the class * @param s - account scope. default is current scope of the class
* *
...@@ -421,7 +421,7 @@ struct table { ...@@ -421,7 +421,7 @@ struct table {
template<> template<>
struct table_impl<sizeof(uint64_t),0> { struct table_impl<sizeof(uint64_t),0> {
static int32_t front_primary( uint64_t code, uint64_t scope, uint64_t table_n, void* data, uint32_t len ) { static int32_t front_primary( uint64_t code, uint64_t scope, uint64_t table_n, void* data, uint32_t len ) {
return front_i64( code, scope, table_n, data, len ); return front_i64( code, scope, table_n, data, len );
} }
...@@ -533,108 +533,117 @@ struct table_impl<sizeof(uint64_t),0> { ...@@ -533,108 +533,117 @@ struct table_impl<sizeof(uint64_t),0> {
*/ */
template<uint64_t code, uint64_t scope, uint64_t table_n, uint64_t bta, typename Record, typename PrimaryType> template<uint64_t code, uint64_t scope, uint64_t table_n, uint64_t bta, typename Record, typename PrimaryType>
struct table<code,scope,table_n,bta,Record,PrimaryType,void> { struct table<code,scope,table_n,bta,Record,PrimaryType,void> {
private: private:
typedef table_impl<sizeof( PrimaryType ),0> impl; typedef table_impl<sizeof( PrimaryType ),0> impl;
static_assert( sizeof(PrimaryType) <= sizeof(Record), "invalid template parameters" ); static_assert( sizeof(PrimaryType) <= sizeof(Record), "invalid template parameters" );
public: public:
typedef PrimaryType primary; typedef PrimaryType primary;
/** /**
* @brief Primary Index of the Table * @brief Primary Index of the Table
*/ */
struct primary_index { struct primary_index {
/** /**
* @param r - reference to a record to store the front. * @param r - reference to a record to store the front.
* * @param s - scope; defaults to scope of the class.
* @return true if successfully retrieved the front of the table. *
*/ * @return true if successfully retrieved the front of the table.
static bool front( Record& r ) { */
return impl::front_primary( code, scope, table_n, &r, sizeof(Record) ) == sizeof(Record); static bool front( Record& r, uint64_t s = scope ) {
} return impl::front_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record);
}
/**
* @param r - reference to a record to store the back. /**
* * @param r - reference to a record to store the back.
* @return true if successfully retrieved the back of the table. * @param s - scope; defaults to scope of the class.
*/ *
static bool back( Record& r ) { * @return true if successfully retrieved the back of the table.
return impl::back_primary( code, scope, table_n, &r, sizeof(Record) ) == sizeof(Record); */
} static bool back( Record& r, uint64_t s = scope ) {
return impl::back_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record);
/** }
* @param r - reference to store the next record. Must be initialized with a key.
* /**
* @return true if successfully retrieved the next record. * @param r - reference to store the next record. Must be initialized with a key.
*/ * @param s - scope; defaults to scope of the class.
static bool next( Record& r ) { *
return impl::next_primary( code, scope, table_n, &r, sizeof(Record) ) == sizeof(Record); * @return true if successfully retrieved the next record.
} */
static bool next( Record& r, uint64_t s = scope ) {
/** return impl::next_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record);
* @param r - reference to store previous record. Must be initialized with a key. }
*
* @return true if successfully retrieved the previous record. /**
*/ * @param r - reference to store previous record. Must be initialized with a key.
static bool previous( Record& r ) { * @param s - scope; defaults to scope of the class.
return impl::previous_primary( code, scope, table_n, &r, sizeof(Record) ) == sizeof(Record); *
} * @return true if successfully retrieved the previous record.
*/
/** static bool previous( Record& r, uint64_t s = scope ) {
* @param p - reference to the primary key to retrieve the record. return impl::previous_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record);
* @param r - reference to hold the result of the query. }
* @param s - scope; defaults to scope of the class.
* @return true if successfully retrieved the record. /**
*/ * @param p - reference to the primary key to retrieve the record.
static bool get( const PrimaryType& p, Record& r, uint64_t s = scope ) { * @param r - reference to hold the result of the query.
*reinterpret_cast<PrimaryType*>(&r) = p; * @param s - scope; defaults to scope of the class.
return impl::load_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); * @return true if successfully retrieved the record.
} */
static bool get( const PrimaryType& p, Record& r, uint64_t s = scope ) {
/** *reinterpret_cast<PrimaryType*>(&r) = p;
* @param p - reference to the primary key to retrieve the lower bound. return impl::load_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record);
* @param r - reference to hold the result of the query. }
* @return true if successfully retrieved the record.
*/ /**
static bool lower_bound( const PrimaryType& p, Record& r ) { * @param p - reference to the primary key to retrieve the lower bound.
*reinterpret_cast<PrimaryType*>(&r) = p; * @param r - reference to hold the result of the query.
return impl::lower_bound_primary( code, scope, table_n, &r, sizeof(Record) ) == sizeof(Record); * @param s - scope; defaults to scope of the class.
} * @return true if successfully retrieved the record.
*/
/** static bool lower_bound( const PrimaryType& p, Record& r, uint64_t s = scope ) {
* @param p - reference to the primary key to retrieve the upper bound. *reinterpret_cast<PrimaryType*>(&r) = p;
* @param r - reference to hold the result of the query. return impl::lower_bound_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record);
* @return true if successfully retrieved the record. }
*/
static bool upper_bound( const PrimaryType& p, Record& r ) { /**
*reinterpret_cast<PrimaryType*>(&r) = p; * @param p - reference to the primary key to retrieve the upper bound.
return impl::upper_bound_primary( code, scope, table_n, &r, sizeof(Record) ) == sizeof(Record); * @param r - reference to hold the result of the query.
} * @param s - scope; defaults to scope of the class.
* @return true if successfully retrieved the record.
/** */
* @param r - reference to record to be removed. static bool upper_bound( const PrimaryType& p, Record& r, uint64_t s = scope ) {
* @return true if successfully removed. *reinterpret_cast<PrimaryType*>(&r) = p;
*/ return impl::upper_bound_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record);
static bool remove( const Record& r ) { }
return impl::remove( scope, table_n, &r ) != 0;
} /**
}; * @param r - reference to record to be removed.
* @param s - scope; defaults to scope of the class.
* @return true if successfully removed.
*/
static bool remove( const Record& r, uint64_t s = scope ) {
return impl::remove( s, table_n, &r ) != 0;
}
};
/** /**
* @brief Fetches the front of the table * @brief Fetches the front of the table
* @details Fetches the front of the table * @details Fetches the front of the table
* @param r - reference to hold the value * @param r - reference to hold the value
* @return true if successfully retrieved the front * @param s - scope; defaults to scope of the class.
*/ * @return true if successfully retrieved the front
static bool front( Record& r ) { return primary_index::front(r); } */
static bool front( Record& r, uint64_t s = scope ) { return primary_index::front(r, s); }
/** /**
* @brief Fetches the back of the table * @brief Fetches the back of the table
* @details Fetches the back of the table * @details Fetches the back of the table
* @param r - reference to hold the value * @param r - reference to hold the value
* @return true if successfully retrieved the back * @param s - scope; defaults to scope of the class.
*/ * @return true if successfully retrieved the back
static bool back( Record& r ) { return primary_index::back(r); } */
static bool back( Record& r, uint64_t s = scope ) { return primary_index::back(r, s); }
/** /**
* @brief Retrieves the record for the specified primary key * @brief Retrieves the record for the specified primary key
...@@ -644,21 +653,21 @@ struct table<code,scope,table_n,bta,Record,PrimaryType,void> { ...@@ -644,21 +653,21 @@ struct table<code,scope,table_n,bta,Record,PrimaryType,void> {
* @param s - scope; defaults to scope of the class. * @param s - scope; defaults to scope of the class.
* @return true if get succeeds. * @return true if get succeeds.
*/ */
static bool get( const PrimaryType& p, Record& r, uint64_t s = scope ) { static bool get( const PrimaryType& p, Record& r, uint64_t s = scope ) {
*reinterpret_cast<PrimaryType*>(&r) = p; *reinterpret_cast<PrimaryType*>(&r) = p;
return impl::load_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); return impl::load_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record);
} }
/** /**
* @brief Retrieves a record based on initialized primary key value * @brief Retrieves a record based on initialized primary key value
* @details Retrieves a record based on initialized primary key value * @details Retrieves a record based on initialized primary key value
* @param r - reference of a record to hold return value; must be initialized to the primary key to be fetched. * @param r - reference of a record to hold return value; must be initialized to the primary key to be fetched.
* @param s - scope; defaults to scope of the class. * @param s - scope; defaults to scope of the class.
* @return true if get succeeds. * @return true if get succeeds.
*/ */
static bool get( Record& r, uint64_t s = scope ) { static bool get( Record& r, uint64_t s = scope ) {
return impl::load_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); return impl::load_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record);
} }
/** /**
* @brief Store a record to the table * @brief Store a record to the table
...@@ -667,9 +676,9 @@ struct table<code,scope,table_n,bta,Record,PrimaryType,void> { ...@@ -667,9 +676,9 @@ struct table<code,scope,table_n,bta,Record,PrimaryType,void> {
* @param s - scope; defaults to scope of the class. * @param s - scope; defaults to scope of the class.
* @return true if store succeeds. * @return true if store succeeds.
*/ */
static bool store( const Record& r, uint64_t s = scope, uint64_t b = bta ) { static bool store( const Record& r, uint64_t s = scope, uint64_t b = bta ) {
return impl::store( s, table_n, b, &r, sizeof(r) ) != 0; return impl::store( s, table_n, b, &r, sizeof(r) ) != 0;
} }
/** /**
* @brief Update a record in the table. * @brief Update a record in the table.
...@@ -678,9 +687,9 @@ struct table<code,scope,table_n,bta,Record,PrimaryType,void> { ...@@ -678,9 +687,9 @@ struct table<code,scope,table_n,bta,Record,PrimaryType,void> {
* @param s - scope; defaults to scope of the class. * @param s - scope; defaults to scope of the class.
* @return true if update succeeds. * @return true if update succeeds.
*/ */
static bool update( const Record& r, uint64_t s = scope, uint64_t b = bta ) { static bool update( const Record& r, uint64_t s = scope, uint64_t b = bta ) {
return impl::update( s, table_n, b, &r, sizeof(r) ) != 0; return impl::update( s, table_n, b, &r, sizeof(r) ) != 0;
} }
/** /**
* @brief Remove a record from the table. * @brief Remove a record from the table.
...@@ -689,14 +698,15 @@ struct table<code,scope,table_n,bta,Record,PrimaryType,void> { ...@@ -689,14 +698,15 @@ struct table<code,scope,table_n,bta,Record,PrimaryType,void> {
* @param s - scope; defaults to scope of the class. * @param s - scope; defaults to scope of the class.
* @return true if remove succeeds. * @return true if remove succeeds.
*/ */
static bool remove( const Record& r, uint64_t s = scope ) { static bool remove( const Record& r, uint64_t s = scope ) {
return impl::remove( s, table_n, &r ) != 0; return impl::remove( s, table_n, &r ) != 0;
} }
}; /// @} singleindextable }; /// @} singleindextable
template<> template<>
struct table_impl_obj<char*> { struct table_impl_obj<char*> {
static int32_t store( account_name scope, table_name table_n, account_name bta, char* key, uint32_t keylen, char* data, uint32_t datalen ) { static int32_t store( account_name scope, table_name table_n, account_name bta, char* key, uint32_t keylen, char* data, uint32_t datalen ) {
return store_str( scope, table_n, bta, key, keylen, data, datalen ); return store_str( scope, table_n, bta, key, keylen, data, datalen );
} }
...@@ -784,7 +794,7 @@ struct var_table { ...@@ -784,7 +794,7 @@ struct var_table {
int32_t update( primary key, uint32_t keylen, char* record, uint32_t len ) { int32_t update( primary key, uint32_t keylen, char* record, uint32_t len ) {
return impl::update( scope, table_n, bta, key, keylen, record, len ); return impl::update( scope, table_n, bta, key, keylen, record, len );
} }
/** /**
* @brief Fetches the front of the table * @brief Fetches the front of the table
* @details Fetches the front of the table * @details Fetches the front of the table
...@@ -822,7 +832,7 @@ struct var_table { ...@@ -822,7 +832,7 @@ struct var_table {
*/ */
int32_t load( primary key, uint32_t keylen, char* record, uint32_t len ) { int32_t load( primary key, uint32_t keylen, char* record, uint32_t len ) {
return impl::load( code, scope, table_n, key, keylen, record, len ); return impl::load( code, scope, table_n, key, keylen, record, len );
} }
/** /**
* @brief Fetches a record which key is next of the given key * @brief Fetches a record which key is next of the given key
...@@ -836,7 +846,7 @@ struct var_table { ...@@ -836,7 +846,7 @@ struct var_table {
int32_t next( primary key, uint32_t keylen, char* record, uint32_t len ) { int32_t next( primary key, uint32_t keylen, char* record, uint32_t len ) {
return impl::next( code, scope, table_n, key, keylen, record, len ); return impl::next( code, scope, table_n, key, keylen, record, len );
} }
/** /**
* @brief Fetches a record which key is previous of the given key * @brief Fetches a record which key is previous of the given key
* @details Fetches a record which key is previous of the given key * @details Fetches a record which key is previous of the given key
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册