Ejemplo n.º 1
0
int main( int argc, char* argv[] )
{
	using namespace std;
	
	try {

		// Second command line argument is the filename
		AxCmdLineArgs args( argc, argv );

		// pair<bool, const char*> fileArg = args.get(1);

		pair<bool, int> fileOpArg = args.get( "-file" );
		if ( !fileOpArg.first ) {
			throwUsage();
		}

		pair<bool, const char*> fileNameArg = args.get( fileOpArg.second + 1 );
		if ( !fileNameArg.first ) {
			throwUsage();
		}


		AxString fileName( AxStringUtil::mbtowc( fileNameArg.second ) );

		// One time init stuff.  Including loading the com api library.
		AxInit initObj;
	
		// Open the file.
		AxFile axFile;
		axFile.OpenExistingRead( fileName );

		
		// Get the header to use as a root object from which to begin iteration.
		// Any object, property, or property value can be used as a root object.
		// Generally, you probably not start with the header - you would start
		// with the ContentStorage object, or the Mobs or EssenceData properties
		// of the ContentStorage object.
		AxHeader axHeader( axFile.getHeader() );
		wcout << axHeader << endl;

		AxDictionary axDictionary( axHeader.GetDictionary() );

		// The header must be wrapped up by a AxBaseSolitaryObjIter instance
		// in order to be used a root for the recursive iterator.
		// If you follow the code, you will see that the header object is, ultimately,
		// cast to AxObject so that the IAAFObject interface of the header can be used
		// to access its properties.
		
		{
			auto_ptr< AxBaseObjIterPrtcl > axHeaderIter(
				new AxBaseSolitaryObjIter<AxHeader>(axHeader) );

			// Create a recursive iterator...
			AxBaseObjRecIter recIter( axHeaderIter );

			// ... and run through all values registering
			// a renamed type for each opaque type.
			wcout << L"Rename Pesky Opaques:" << endl;
			int count = renamePeskyOpaques( axDictionary, recIter );
			wcout << L"\tOpaques reported by dictionary: " << axDictionary.CountOpaqueTypeDefs() << endl;
			wcout << L"\tOpaques found and renamed: " << count << endl;
		}
		
		{
			auto_ptr< AxBaseObjIterPrtcl > axHeaderIter(
			new AxBaseSolitaryObjIter<AxHeader>(axHeader) );

		    // Create a recursive iterator...
			AxBaseObjRecIter recIter( axHeaderIter );

			// ... and dump all objects.
			wcout << endl << L"Recursive Dump:" << endl;
			wcout << endl << L"  Item  Level   Desc.       Detail" << endl;
			dumpBaseObjects( axDictionary, recIter, args );
		}

		// That's all folks.
		axFile.Close();
		wcout << L"That's all folks." << endl;
	}

	catch ( const AxEx& ex ) {
		wcout << ex.what() << endl;
	}

	return 0;
}
Ejemplo n.º 2
0
int main( int argc, char* argv[] )
{
	using namespace std;
	
    try {

		AxCmdLineArgs args( argc, argv );

		pair<bool, int> fileOpArg = args.get( "-file" );
		if ( !fileOpArg.first ) {
			throwUsage();
		}

		pair<bool, const char*> fileNameArg = args.get( fileOpArg.second + 1 );
		if ( !fileNameArg.first ) {
			throwUsage();
		}

		AxInit initObj;
				
		AxString fileName( AxStringUtil::mbtowc( fileNameArg.second ) );

		bool openExisting = false;
		
		// Test if left over file from previous test exists.

		// FIXME - logic implementted using an exception.  Fix AxFile
		// interface, or add separate file io code to determine
		// if a file exists before testing if it is an AAF file.
		try {
			if ( AxFile::isAAFFile( fileName ) ) {
				wostringstream msg;
				msg << L"Existing file will be modified: ";
				msg << fileName << endl;
				openExisting = true;
			}
		}
		catch( const AxExHResult& ex ) {
			//  AAFRESULT_FILE_NOT_FOUND is okay.  The file does
			// not exist.
			if ( ex.getHResult() != AAFRESULT_FILE_NOT_FOUND ) {
				throw;
			}
		}

		AxFile axFile;

		if ( openExisting ) {
			wcout << L"Open existing AAF File: " << fileName << endl;
			axFile.OpenExistingModify( fileName );
		}
		else {
			wcout << L"Create new AAF File: " << fileName << endl;
			axFile.OpenNewModify( fileName );
		}


		// Test each option argument and run the appropriate module.
		// Each example module takes only the file as an argument,
		// hence, these option can be run once at a time or all at
		// once.

		pair<bool,int> metaOpArg = args.get( "-metadata" );
		if ( metaOpArg.first ) {
			wcout << L"Creating metadata..." << endl;
			AxCreateMetaDataExample( axFile, args );
		}

		pair<bool,int> essOpArg = args.get( "-essence" );
		if ( essOpArg.first ) {
			wcout << L"Creating essence..." << endl;
			AxCreateEssenceExample( axFile, args );
		}

		pair<bool,int> compOpArg = args.get( "-composition" );
		if ( compOpArg.first ) {
			wcout << L"Creating composition..." << endl;
			AxCreateCompositionExample( axFile, args );
		}

		wcout << L"Complete." << endl;
		
		axFile.Save();
		axFile.Close();
	}

	catch ( const AxEx& ex ) {
		wcout << ex.what() << endl;
	}

	return 0;
}