StructTest.cpp 1.65 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <VAException.h>
#include <VAStruct.h>
#include <VASamples.h>

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <sstream>

using namespace std;


14 15
int main()
{
Jonas Stienen's avatar
Jonas Stienen committed
16 17
	std::map<std::string, int> map;

18 19 20 21 22 23 24 25 26 27 28 29
	try
	{

		std::vector< char > vcSomeData( 1e7 );
		vcSomeData[ 0 ] = 1;
		vcSomeData[ vcSomeData.size() - 1 ] = -1;
		{
			CVAStruct s;
			CVAStructValue v = CVAStructValue( &vcSomeData[ 0 ], sizeof( char ) * vcSomeData.size() );
			s[ "ch1" ] = v;
		}

Jonas Stienen's avatar
Jonas Stienen committed
30
		CVAStruct s;
31 32 33 34
		s[ "a" ] = CVAStruct();
		s[ string( "a" ) ][ string( "b" ) ] = 24;
		s[ string( "a" ) ][ string( "c" ) ] = CVAStruct();
		s[ string( "a" ) ][ string( "c" ) ][ string( "d" ) ] = "Hui";
Jonas Stienen's avatar
Jonas Stienen committed
35

36
		s.GetValue( "a/c/d", '/' );
Jonas Stienen's avatar
Jonas Stienen committed
37 38
		cout << s << endl;

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
		// Iteration example
		const CVAStruct& t = s[ "a" ];
		auto cit = t.Begin();
		while( cit != t.End() )
		{
			std::string sKey = cit->first;
			const CVAStructValue& oValue = cit->second;
			cout << sKey << ": " << oValue << std::endl;
			++cit;
		}

		for( size_t i = 0; i < 10e2; i++ )
		{
			CVAStruct s;
			CVAStructValue v = CVAStructValue( &vcSomeData[ 0 ], sizeof( char ) * vcSomeData.size() );
			s[ "ch1" ] = v;
		}

Jonas Stienen's avatar
Jonas Stienen committed
57
		CVASampleBuffer oBuf( 1024 );
58 59 60 61
		oBuf.GetData()[ 0 ] = -1.0f;
		oBuf.GetData()[ 1023 ] = 1023.0f;
		CVAStructValue v( ( void* ) oBuf.GetData(), oBuf.GetNumSamples() * sizeof( float ) );
		s[ "BRIR_S0_R0" ] = v;
Jonas Stienen's avatar
Jonas Stienen committed
62 63

		CVASampleBuffer oBuf2( 1024, false );
64
		float* pvData = ( float* ) ( void* ) s[ "BRIR_S0_R0" ];
Jonas Stienen's avatar
Jonas Stienen committed
65

66 67
		for( size_t i = 0; i < oBuf2.GetNumSamples(); i++ )
			oBuf2.GetData()[ i ] = pvData[ i ];
Jonas Stienen's avatar
Jonas Stienen committed
68

69 70
	}
	catch( CVAException& e ) {
Jonas Stienen's avatar
Jonas Stienen committed
71 72 73 74 75 76
		cerr << "Error: " << e << endl;
		return e.GetErrorCode();
	}

	return 0;
}