Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
gamgee::SharedField< TYPE > Class Template Reference

A class template to hold the values of a specific Variant's shared field. More...

#include <shared_field.h>

Public Member Functions

 SharedField ()
 default constructor of an empty SharedField More...
 
 SharedField (const std::shared_ptr< bcf1_t > &body, const bcf_info_t *const info_ptr)
 creates a new SharedField pointing to the shared byte array inside the variant object More...
 
 SharedField (const SharedField &other)=delete
 copying of the SharedField object is not allowed. Use move constructor instead. More...
 
SharedFieldoperator= (const SharedField &other)=delete
 copying of the SharedField object is not allowed. Use move constructor instead. More...
 
 SharedField (SharedField &&other)=default
 safely moves the data from one SharedField to a new one without making any copies More...
 
SharedFieldoperator= (SharedField &&other)=default
 safely moves the data from one SharedField to the other without making any copies More...
 
bool operator== (const SharedField &other) const
 compares two SharedField objects in the following order: memory address, size and values. More...
 
bool operator!= (const SharedField &other) const
 compares two SharedField objects in the following order: memory address, size and values. More...
 
TYPE operator[] (const uint32_t index) const
 random access to a given value for reading or writing More...
 
SharedFieldIterator< TYPE > begin () const
 create a new iterator pointing to the begining of the values of this field More...
 
SharedFieldIterator< TYPE > end () const
 create a new iterator pointing to the end of the values of this field More...
 
uint32_t size () const
 the number of values in this SharedField (values per sample) More...
 
bool empty () const
 checks if the object is empty. More...
 
bool missing () const
 simple overload of empty to work with gamgee's missing API More...
 
TYPE front () const
 convenience function to access the first element More...
 
TYPE back () const
 convenience function to access the last element More...
 
template<>
uint32_t size () const
 
template<>
std::string operator[] (const uint32_t index) const
 

Detailed Description

template<class TYPE>
class gamgee::SharedField< TYPE >

A class template to hold the values of a specific Variant's shared field.

The role of this class is to perform the pointer manipulations behind the scenes that permit the user to navigate the values of a field without making any copies and benefiting from data locality (all the data is stored contiguously in memory).

For example, the allele number shared field (AN) will hold one integer value. A ranksum test field for example could hold a vector of floats. The SharedField object will hold all these values for a shared field in a random access (and random access iterator compatible) way. The SharedField can be used in any algorithm of the STL that requires random access iterators.

A typical use of the SharedField can be exemplified by the following:

const auto an = variant_record.shared_integer_field("AN");
for_each(an.begin(), an.end(), [](const auto x) { cout << x[0] << endl; });

SharedField objects can also be used in for loops like so:

for (const auto q : variant_record.shared_string_field("CULPRIT"))
cout << q << endl;

Or directly like so:

const auto ab = variant_record.shared_float_field("AB");
cout << ab[0] << endl;

While the SharedField objects are not really intended to be created by the user, they are returned by many accessors in the Variant API like the Variant::shared_integer_field() example above. Utilizing them correctly can really simplify your work by leveraging the power of the STL functions.

Note
all methods are inlined on purpose because they are so simple
Template Parameters
TYPEthe output type desired for the given tag. For example for AN's typically you would request an int32_t. Conversions are allowed if possible.

Constructor & Destructor Documentation

template<class TYPE>
gamgee::SharedField< TYPE >::SharedField ( )
inline

default constructor of an empty SharedField

Warning
since private members are immutable, creating an empty SharedField like this means that it will stay empty forever (desired immutability effect)
Note
empty shared fields are created when the field requested is missing in the Variant record
template<class TYPE>
gamgee::SharedField< TYPE >::SharedField ( const std::shared_ptr< bcf1_t > &  body,
const bcf_info_t *const  info_ptr 
)
inlineexplicit

creates a new SharedField pointing to the shared byte array inside the variant object

Parameters
bodythe the bcf1_t structure to hold a shared pointer to
info_ptrthe info field pointer inside the body
template<class TYPE>
gamgee::SharedField< TYPE >::SharedField ( const SharedField< TYPE > &  other)
delete

copying of the SharedField object is not allowed. Use move constructor instead.

template<class TYPE>
gamgee::SharedField< TYPE >::SharedField ( SharedField< TYPE > &&  other)
default

safely moves the data from one SharedField to a new one without making any copies

Member Function Documentation

template<class TYPE>
TYPE gamgee::SharedField< TYPE >::back ( ) const
inline

convenience function to access the last element

template<class TYPE>
SharedFieldIterator<TYPE> gamgee::SharedField< TYPE >::begin ( ) const
inline

create a new iterator pointing to the begining of the values of this field

template<class TYPE>
bool gamgee::SharedField< TYPE >::empty ( ) const
inline

checks if the object is empty.

Note
empty objects are returned when the requested field is missing
template<class TYPE>
SharedFieldIterator<TYPE> gamgee::SharedField< TYPE >::end ( ) const
inline

create a new iterator pointing to the end of the values of this field

template<class TYPE>
TYPE gamgee::SharedField< TYPE >::front ( ) const
inline

convenience function to access the first element

template<class TYPE>
bool gamgee::SharedField< TYPE >::missing ( ) const
inline

simple overload of empty to work with gamgee's missing API

template<class TYPE>
bool gamgee::SharedField< TYPE >::operator!= ( const SharedField< TYPE > &  other) const
inline

compares two SharedField objects in the following order: memory address, size and values.

Parameters
othersomething to compare to
Returns
true if the objects are not the same (memory address-wise), or contain different number of values, or the values are not exactly the same. Value comparison is dictated by TYPE's operator== implementation
template<class TYPE>
SharedField& gamgee::SharedField< TYPE >::operator= ( const SharedField< TYPE > &  other)
delete

copying of the SharedField object is not allowed. Use move constructor instead.

template<class TYPE>
SharedField& gamgee::SharedField< TYPE >::operator= ( SharedField< TYPE > &&  other)
default

safely moves the data from one SharedField to the other without making any copies

template<class TYPE>
bool gamgee::SharedField< TYPE >::operator== ( const SharedField< TYPE > &  other) const
inline

compares two SharedField objects in the following order: memory address, size and values.

Parameters
othersomething to compare to
Returns
true if the objects are the same (memory address-wise), or contain exactly the same values. Value comparison is dictated by TYPE's operator== implementation
template<class TYPE>
TYPE gamgee::SharedField< TYPE >::operator[] ( const uint32_t  index) const
inline

random access to a given value for reading or writing

Parameters
indexmust be between 0 and the number of values for this record
Note
implementation guarantees this operation to be O(1)
Exceptions
std::out_of_rangeif index is out of range or entire field is missing and trying to access invalid memory
Returns
the value in that index
template<>
std::string gamgee::SharedField< std::string >::operator[] ( const uint32_t  index) const
inline
template<class TYPE>
uint32_t gamgee::SharedField< TYPE >::size ( ) const
inline

the number of values in this SharedField (values per sample)

template<>
uint32_t gamgee::SharedField< std::string >::size ( ) const
inline

The documentation for this class was generated from the following file: