示例#1
0
//--------------------------------------------------------------------
void
HDF5Table::read_hdf5_property( )
{

  // Won't need H5IO to be passed, instead get it in the constructor at the file level
  H5IO propIO = fileIO_->open_group( tablePropName_ );
  //
  // Read the data describing this property configuration
  //
  propIO.read_attribute( "Name", name_ );
  propIO.read_attribute( "Dimension", dimension_ );
  propIO.read_attribute( "InputNames", inputNames_ );

  // Read the Converters (if any)
  //
  unsigned int nConverters = 0;
  propIO.read_attribute( "NConverters", nConverters );

  for ( unsigned int i = 0; i < nConverters; ++i ) {
    std::ostringstream label;
    label << "Converter_" << i;

    H5IO converterIO = propIO.open_group( label.str() );
    std::string converterType;
    converterIO.read_attribute( "ConverterType", converterType );

    ConverterFactory converterFactory;
    Converter * converter = converterFactory.create( converterType );

    converter->read_hdf5( converterIO );
    converters_.push_back( converter );
  }

  // Read the central Table for the dependent variable
  H5IO tableIO = propIO.open_group( "Table" );
  read_hdf5_table( tableIO );
  //
  // Wire up all of the inputs and outputs between the Table and Converters
  //
  update_input_mapping();

}
int main(int argc, char* argv[]) {
	ConverterFactory* factory = ConverterFactory::getInstance();
	factory->registerClass("dollarToEuro", new dollarToEuroConverter);
	factory->registerClass("euroToDollar", new euroToDollarConverter);
	factory->registerClass("euroToDanishKrone", new euroToDanishKroneConverter);
	factory->registerClass("centimeterToInches", new centimeterToInchesConverter);
	factory->registerClass("kilometerToMiles", new kilometerToMilesConverter);

    std::deque<Command> commandList;

    std::string inputStr;
    try
    {
        for (std::string line; std::getline(std::cin, inputStr, ' ');) 
        {
                std::string input_str;
                std::getline(std::cin, input_str);
                auto convert = factory->create(inputStr);
                double (converter::*convertMethod)(double) = NULL;
                convertMethod = &converter::convert;

                if(typeid(input_str) != typeid(double))
                    throw std::invalid_argument("Please enter a double value next time!");

                commandList.push_back(
                    Command{convertMethod, convert, std::stod(input_str) }
                );
        }
        for (auto&& command : commandList) {
            command.execute();
        }
    }
    catch(std::invalid_argument e)
    {
        std::cout << e.what() << std::endl;
    }
	return 0;
}