Skip to content

Commit

Permalink
move type enums to specReader library
Browse files Browse the repository at this point in the history
issue #31
  • Loading branch information
Valentin Noel committed Aug 5, 2013
1 parent 58ce7a0 commit 2517b19
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 134 deletions.
1 change: 1 addition & 0 deletions libraries/basicElement/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project.StaticLibrary(
libraries = [
libs.common,
libs.boost_python,
libs.specReader,
],
shared = True
)
24 changes: 12 additions & 12 deletions libraries/basicElement/src/Data/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace data_element
{

Data::Data()
: Element( Element::eTypeData )
: Element( eTypeData )
, _data( NULL )
{
_subType = Element::eDataTypeRaw;
_subType = eDataTypeRaw;
_size = 0;
}

Data::Data( const Element::EDataType& subType )
: Element( Element::eTypeData )
Data::Data( const EDataType& subType )
: Element( eTypeData )
, _data( NULL )
{
_subType = subType;
Expand Down Expand Up @@ -158,10 +158,10 @@ std::string Data::getStringFromType()
std::string type;
switch( getDataSubType() )
{
case Element::eStatusUnknown : type = "unknown"; break;
case Element::eDataTypeAscii : type = "ascii"; break;
case Element::eDataTypeHexa : type = "hexa"; break;
case Element::eDataTypeRaw : type = "raw"; break;
case eStatusUnknown : type = "unknown"; break;
case eDataTypeAscii : type = "ascii"; break;
case eDataTypeHexa : type = "hexa"; break;
case eDataTypeRaw : type = "raw"; break;
}
return type;
}
Expand All @@ -171,10 +171,10 @@ std::string Data::getStringFromData()
std::string data;
switch( getDataSubType() )
{
case Element::eStatusUnknown : data = ""; break;
case Element::eDataTypeAscii : data = getAscii(); break;
case Element::eDataTypeHexa : data = getHexa(); break;
case Element::eDataTypeRaw : data = ""; break;
case eStatusUnknown : data = ""; break;
case eDataTypeAscii : data = getAscii(); break;
case eDataTypeHexa : data = getHexa(); break;
case eDataTypeRaw : data = ""; break;
}
return data;
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/basicElement/src/Data/Data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Data : public Element
{
public:
Data();
Data( const Element::EDataType& subType );
Data( const EDataType& subType );
~Data();

void setData ( const char* data, const size_t& size );
Expand All @@ -24,7 +24,7 @@ class Data : public Element

void setSpecData( const std::string& specValue );

EStatus checkData();
Element::EStatus checkData();
std::vector< std::pair< std::string, std::string > > getElementInfo();

Data& operator=( const Data& other );
Expand Down
4 changes: 2 additions & 2 deletions libraries/basicElement/src/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ void Element::setLabel( const std::string& label )
_label = label;
}

Element::ENumberType Element::getNumberSubType()
ENumberType Element::getNumberSubType()
{
if( _type != eTypeNumber )
return eNumberTypeUnknown;
return ( ENumberType ) _subType;
}

Element::EDataType Element::getDataSubType()
EDataType Element::getDataSubType()
{
if( _type != eTypeData )
return eDataTypeUnknown;
Expand Down
34 changes: 1 addition & 33 deletions libraries/basicElement/src/Element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,14 @@

#include <string>
#include "common.hpp"
#include <specDefinition.hpp>

namespace basic_element
{

class Element
{
public:
enum EType
{
eTypeUnknown = 0,
eTypeNumber,
eTypeExif,
eTypeData,
eTypeKlv
};

enum ENumberType
{
eNumberTypeUnknown = 0,
eNumberTypeInt8,
eNumberTypeUInt8,
eNumberTypeInt16,
eNumberTypeUInt16,
eNumberTypeInt32,
eNumberTypeUInt32,
eNumberTypeInt64,
eNumberTypeUInt64,
eNumberTypeFloat,
eNumberTypeDouble,
eNumberTypeIeeeExtended
};

enum EDataType
{
eDataTypeUnknown = 0,
eDataTypeAscii,
eDataTypeHexa,
eDataTypeRaw
};

enum EStatus
{
eStatusUnknown = 0,
Expand Down
24 changes: 12 additions & 12 deletions libraries/basicElement/src/Number/Number.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace number_element

template< typename NumberType >
Number< NumberType >::Number()
: Element( Element::eTypeNumber )
: Element( eTypeNumber )
{
setSubType();
setSize();
Expand Down Expand Up @@ -189,37 +189,37 @@ std::string Number< ieeeExtended >::getStringFromType() { return "ieeeExtended";


template< >
void Number< int8 >::setSubType() { _subType = Element::eNumberTypeInt8; }
void Number< int8 >::setSubType() { _subType = eNumberTypeInt8; }

template< >
void Number< uint8 >::setSubType() { _subType = Element::eNumberTypeUInt8; }
void Number< uint8 >::setSubType() { _subType = eNumberTypeUInt8; }

template< >
void Number< int16 >::setSubType() { _subType = Element::eNumberTypeInt16; }
void Number< int16 >::setSubType() { _subType = eNumberTypeInt16; }

template< >
void Number< uint16 >::setSubType() { _subType = Element::eNumberTypeUInt16; }
void Number< uint16 >::setSubType() { _subType = eNumberTypeUInt16; }

template< >
void Number< int32 >::setSubType() { _subType = Element::eNumberTypeInt32; }
void Number< int32 >::setSubType() { _subType = eNumberTypeInt32; }

template< >
void Number< uint32 >::setSubType() { _subType = Element::eNumberTypeUInt32; }
void Number< uint32 >::setSubType() { _subType = eNumberTypeUInt32; }

template< >
void Number< int64 >::setSubType() { _subType = Element::eNumberTypeInt64; }
void Number< int64 >::setSubType() { _subType = eNumberTypeInt64; }

template< >
void Number< uint64 >::setSubType() { _subType = Element::eNumberTypeUInt64; }
void Number< uint64 >::setSubType() { _subType = eNumberTypeUInt64; }

template< >
void Number< float >::setSubType() { _subType = Element::eNumberTypeFloat; }
void Number< float >::setSubType() { _subType = eNumberTypeFloat; }

template< >
void Number< double >::setSubType() { _subType = Element::eNumberTypeDouble; }
void Number< double >::setSubType() { _subType = eNumberTypeDouble; }

template< >
void Number< ieeeExtended >::setSubType() { _subType = Element::eNumberTypeIeeeExtended; }
void Number< ieeeExtended >::setSubType() { _subType = eNumberTypeIeeeExtended; }

}
}
52 changes: 26 additions & 26 deletions libraries/basicElement/tests/element/dataTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BOOST_AUTO_TEST_CASE( basic_element_data )
BOOST_CHECK_EQUAL( data.getLabel(), label );
}
{
dbe::Data data( be::Element::eDataTypeHexa );
dbe::Data data( eDataTypeHexa );
char buffer[] = { 0x7f, 0x05, 0x32 };

data.setData( buffer, 3 );
Expand All @@ -27,14 +27,14 @@ BOOST_AUTO_TEST_CASE( basic_element_data )
BOOST_CHECK_EQUAL( data.getHexa(), "7f0532" );
}
{
dbe::Data data( be::Element::eDataTypeAscii );
dbe::Data data( eDataTypeAscii );
char buffer[] = { 0x48, 0x65, 0x6c, 0x6c, 0x6f };

data.setData( buffer, 5 );
BOOST_CHECK_EQUAL( data.getAscii(), "Hello" );
}
{
dbe::Data data( be::Element::eDataTypeRaw );
dbe::Data data( eDataTypeRaw );
char buffer[] = {'d','a','t','a'};

data.setData( buffer, 4 );
Expand All @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE( basic_element_data )
ref.push_back( 32 );
ref.push_back( 255 );

dbe::Data data( be::Element::eDataTypeRaw );
dbe::Data data( eDataTypeRaw );
char buffer[ ref.size() ];
for( size_t i = 0; i < ref.size(); i++ )
buffer[i] = ref.at(i);
Expand All @@ -74,30 +74,30 @@ BOOST_AUTO_TEST_CASE( basic_element_data_hexa )
{
LOG_INFO( "\n>>> basic_element_data_hexa <<<" );
{
dbe::Data data( be::Element::eDataTypeHexa );
dbe::Data data( eDataTypeHexa );
BOOST_CHECK_EQUAL( data.checkData(), be::Element::eStatusPassOver );
}
{
dbe::Data data( be::Element::eDataTypeHexa );
dbe::Data data( eDataTypeHexa );
data.setSpecData( "ff00" );
BOOST_CHECK_EQUAL( data.checkData(), be::Element::eStatusInvalid );
}
{
dbe::Data data( be::Element::eDataTypeHexa );
dbe::Data data( eDataTypeHexa );
data.setSpecData( "ff00" );
char buffer[] = { static_cast< char >( 0xff ), 0x00 };
data.setData( buffer, sizeof( buffer ) );
BOOST_CHECK_EQUAL( data.checkData(), be::Element::eStatusValid );
}
{
dbe::Data data( be::Element::eDataTypeHexa );
dbe::Data data( eDataTypeHexa );
data.setSpecData( "ff00" );
char buffer[] = { 0x00, static_cast< char >( 0xff ) };
data.setData( buffer, sizeof( buffer ) );
BOOST_CHECK_EQUAL( data.checkData(), be::Element::eStatusInvalid );
}
{
dbe::Data data( be::Element::eDataTypeHexa );
dbe::Data data( eDataTypeHexa );
data.setSpecData( "ff00" );
data.setBigEndianness( false );
char buffer[] = { 0x00, static_cast< char >( 0xff ) };
Expand All @@ -110,30 +110,30 @@ BOOST_AUTO_TEST_CASE( basic_element_data_ascii )
{
LOG_INFO( "\n>>> basic_element_data_ascii <<<" );
{
dbe::Data data( be::Element::eDataTypeAscii );
dbe::Data data( eDataTypeAscii );
BOOST_CHECK_EQUAL( data.checkData(), be::Element::eStatusPassOver );
}
{
dbe::Data data( be::Element::eDataTypeAscii );
dbe::Data data( eDataTypeAscii );
data.setSpecData( "data" );
BOOST_CHECK_EQUAL( data.checkData(), be::Element::eStatusInvalid );
}
{
dbe::Data data( be::Element::eDataTypeAscii );
dbe::Data data( eDataTypeAscii );
data.setSpecData( "data" );
char buffer[] = {'d','a','t','a'};
data.setData( buffer, sizeof( buffer ) );
BOOST_CHECK_EQUAL( data.checkData(), be::Element::eStatusValid );
}
{
dbe::Data data( be::Element::eDataTypeAscii );
dbe::Data data( eDataTypeAscii );
data.setSpecData( "atad" );
char buffer[] = {'d','a','t','a'};
data.setData( buffer, sizeof( buffer ) );
BOOST_CHECK_EQUAL( data.checkData(), be::Element::eStatusInvalid );
}
{
dbe::Data data( be::Element::eDataTypeAscii );
dbe::Data data( eDataTypeAscii );
data.setSpecData( "atad" );
data.setBigEndianness( false );
char buffer[] = {'d','a','t','a'};
Expand All @@ -146,12 +146,12 @@ BOOST_AUTO_TEST_CASE( basic_element_data_other )
{
LOG_INFO( "\n>>> basic_element_data_other <<<" );
{
dbe::Data data( be::Element::eDataTypeUnknown );
dbe::Data data( eDataTypeUnknown );
data.setSpecData( "anything" );
BOOST_CHECK_EQUAL( data.checkData(), be::Element::eStatusUnknown );
}
{
dbe::Data data( be::Element::eDataTypeRaw );
dbe::Data data( eDataTypeRaw );
data.setSpecData( "lotOfThings" );
BOOST_CHECK_EQUAL( data.checkData(), be::Element::eStatusPassOver );
}
Expand All @@ -161,25 +161,25 @@ BOOST_AUTO_TEST_CASE( basic_element_data_subType )
{
LOG_INFO( "\n>>> basic_element_data_subType <<<" );
{
dbe::Data data( be::Element::eDataTypeUnknown );
BOOST_CHECK_EQUAL( data.getDataSubType(), be::Element::eDataTypeUnknown );
dbe::Data data( eDataTypeUnknown );
BOOST_CHECK_EQUAL( data.getDataSubType(), eDataTypeUnknown );
}
{
dbe::Data data( be::Element::eDataTypeHexa );
BOOST_CHECK_EQUAL( data.getDataSubType(), be::Element::eDataTypeHexa );
dbe::Data data( eDataTypeHexa );
BOOST_CHECK_EQUAL( data.getDataSubType(), eDataTypeHexa );
}
{
dbe::Data data( be::Element::eDataTypeAscii );
BOOST_CHECK_EQUAL( data.getDataSubType(), be::Element::eDataTypeAscii );
dbe::Data data( eDataTypeAscii );
BOOST_CHECK_EQUAL( data.getDataSubType(), eDataTypeAscii );
}
{
dbe::Data data( be::Element::eDataTypeRaw );
BOOST_CHECK_EQUAL( data.getDataSubType(), be::Element::eDataTypeRaw );
dbe::Data data( eDataTypeRaw );
BOOST_CHECK_EQUAL( data.getDataSubType(), eDataTypeRaw );
}

{
dbe::Data data( be::Element::eDataTypeRaw );
BOOST_CHECK_EQUAL( data.getNumberSubType(), be::Element::eNumberTypeUnknown );
dbe::Data data( eDataTypeRaw );
BOOST_CHECK_EQUAL( data.getNumberSubType(), eNumberTypeUnknown );
}
}

Expand Down
Loading

0 comments on commit 2517b19

Please sign in to comment.