Ejemplo n.º 1
0
/*
 * 在指定的类中,根据描述查找匹配的方法
 *
 */
static Method* findMethodInListByDescriptor(const ClassObject* clazz,
    bool findVirtual, bool isHier, const char* name, const char* descriptor)
{
    const char* returnType;
    size_t argCount = countArgsAndFindReturnType(descriptor, &returnType);

    if (returnType == NULL) {
        ALOGW("Bogus method descriptor: %s", descriptor);
        return NULL;
    }

    /*
     * Make buffer big enough for all the argument type characters and
     * one '\0' per argument. The "- 2" is because "returnType -
     * descriptor" includes two parens.
     */
    char buffer[argCount + (returnType - descriptor) - 2];
    const char* argTypes[argCount];

    copyTypes(buffer, argTypes, argCount, descriptor);

    while (clazz != NULL) {
        Method* methods;
        size_t methodCount;
        size_t i;

        if (findVirtual) {
            methods = clazz->virtualMethods;
            methodCount = clazz->virtualMethodCount;
        } else {
            methods = clazz->directMethods;
            methodCount = clazz->directMethodCount;
        }

        for (i = 0; i < methodCount; i++) {
            Method* method = &methods[i];
            if (compareMethodHelper(method, name, returnType, argCount,
                            argTypes) == 0) {
                return method;
            }
        }

        if (! isHier) {
            break;
        }

        clazz = clazz->super;
    }

    return NULL;
}
int main( int argc, char *argv[] ) {
	int exit_status = 0;
	// Try to process the command line arguments
	if ( !ConfigKeeper::getSingleton().processCommandLineArguments( argc, argv ) ) {
		return 0;
	}
	// Get the input file name
	if (  ConfigKeeper::getSingleton().getCount( "help" )  ) {
		usage( argv[0] );
		return 0;
	}

	if (  !ConfigKeeper::getSingleton().getCount( "inputFile" )  ) {
		usage( argv[0] );
		return 1;
	}
	std::string inputFilename = ConfigKeeper::getSingleton().getStringValue( "inputFile" );
	// CHECK IF INPUT FILE EXISTS
	if (  !boost::filesystem::exists( inputFilename )  ) {
		std::cerr << "ERROR: Could not access file \"" << inputFilename << "\"." << std::endl << std::endl;
		return 2;
	}

	boost::regex absPathTest( "^(?:[A-Za-z]:|[\\/])" );
	boost::match_results< std::string::const_iterator > results;

	if (  !boost::regex_search( inputFilename, results, absPathTest )  ) {
#ifdef _WIN32
		TCHAR currentDirectory[ 1024 ];
		GetCurrentDirectory( 1024, currentDirectory );
		inputFilename = std::string( currentDirectory ) + '\\' + inputFilename;
#else
		char currentDirectory[ 1024 ];
		getcwd( currentDirectory, 1024 );
		inputFilename = std::string( currentDirectory ) + '/' + inputFilename;
#endif
	}

	std::string outputFilename;
	if (  ConfigKeeper::getSingleton().getCount( "outputFile" )  ) {

		outputFilename = ConfigKeeper::getSingleton().getStringValue( "outputFile" );

	} else {

		std::string inputFilenameBase;
		std::string::size_type charPos = inputFilename.rfind( '/' );
		if ( charPos != std::string::npos ) {
			charPos = inputFilenameBase.rfind( '\\' );
			inputFilenameBase = charPos == std::string::npos ? inputFilenameBase : inputFilenameBase.substr( charPos + 1 );
		} else {
			inputFilenameBase = inputFilename.substr( charPos + 1 );
		}
		charPos = inputFilenameBase.rfind( '.' );
		inputFilenameBase = charPos == std::string::npos ? inputFilenameBase : inputFilenameBase.substr( 0, charPos );
		outputFilename = inputFilenameBase + "_flatten.xml";

	}

	// INITIALIZE THE DATA NETWORK
	UdmEngine inputModel;
	UdmEngine outputModel;

	//try {

		inputModel.openExisting( inputFilename );
		outputModel.createNew( outputFilename );

		copyTypes( inputModel, outputModel );

		ESMoL::RootFolder inputRoot = inputModel.getRootFolder();
		ESMoL::RootFolder outputRoot = outputModel.getRootFolder();
		outputRoot.name() = inputRoot.name();

		copyDesignFolders( inputRoot, outputRoot );

		inputModel.closeNoUpdate();
		outputModel.closeWithUpdate();

	//} catch ( udm_exception &err ) {

	//	std::cerr << "The following UDM exception occurred:" << std::endl;
	//	std::cerr << err.what() << std::endl << std::endl;

	//	exit_status = 3;

	//} catch ( std::exception &err ) {

	//	std::cerr << "The following std::exception occurred:" << std::endl;
	//	std::cerr << err.what() << std::endl << std::endl;
	//	exit_status = 4;

	//} catch ( ... ) {

	//	std::cerr << "Unknown exception caught" << std::endl;
	//	exit_status = 5;
	//}

	return exit_status;
}