void GncTxImport::settings (const CsvTransImpSettings& settings) { /* First apply file format as this may recreate the tokenizer */ file_format (settings.m_file_format); /* Only then apply the other settings */ m_settings = settings; multi_split (m_settings.m_multi_split); base_account (m_settings.m_base_account); encoding (m_settings.m_encoding); if (file_format() == GncImpFileFormat::CSV) separators (m_settings.m_separators); else if (file_format() == GncImpFileFormat::FIXED_WIDTH) { auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get()); fwtok->columns (m_settings.m_column_widths); } try { tokenize(false); } catch (...) { }; /* Tokenizing will clear column types, reset them here * based on the loaded settings. */ std::copy_n (settings.m_column_types.begin(), std::min (m_settings.m_column_types.size(), settings.m_column_types.size()), m_settings.m_column_types.begin()); }
void option_f(t_data_64 *data) { printf("\n"); file_format(data); display_header(data); printf("\n"); }
void option_s(t_data_64 *data) { printf("\n"); file_format(data); printf("\n"); display_all_section(data); }
/** Constructor for GncPriceImport. */ GncPriceImport::GncPriceImport(GncImpFileFormat format) { /* All of the data pointers are initially NULL. This is so that, if * gnc_csv_parse_data_free is called before all of the data is * initialized, only the data that needs to be freed is freed. */ m_skip_errors = false; file_format(m_settings.m_file_format = format); }
void GncTxImport::separators (std::string separators) { if (file_format() != GncImpFileFormat::CSV) return; m_settings.m_separators = separators; auto csvtok = dynamic_cast<GncCsvTokenizer*>(m_tokenizer.get()); csvtok->set_separators (separators); }
/** Sets the file format for the file to import, which * may cause the file to be reloaded as well if the * previously set file format was different and a * filename was already set. * @param format the new format to set * @exception std::ifstream::failure if file reloading fails */ void GncTxImport::file_format(GncImpFileFormat format) { if (m_tokenizer && m_settings.m_file_format == format) return; auto new_encoding = std::string("UTF-8"); auto new_imp_file = std::string(); // Recover common settings from old tokenizer if (m_tokenizer) { new_encoding = m_tokenizer->encoding(); new_imp_file = m_tokenizer->current_file(); if (file_format() == GncImpFileFormat::FIXED_WIDTH) { auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get()); if (!fwtok->get_columns().empty()) m_settings.m_column_widths = fwtok->get_columns(); } } m_settings.m_file_format = format; m_tokenizer = gnc_tokenizer_factory(m_settings.m_file_format); // Set up new tokenizer with common settings // recovered from old tokenizer m_tokenizer->encoding(new_encoding); load_file(new_imp_file); // Restore potentially previously set separators or column_widths if ((file_format() == GncImpFileFormat::CSV) && !m_settings.m_separators.empty()) separators (m_settings.m_separators); else if ((file_format() == GncImpFileFormat::FIXED_WIDTH) && !m_settings.m_column_widths.empty()) { auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get()); fwtok->columns (m_settings.m_column_widths); } }
bool GncPriceImport::save_settings () { if (preset_is_reserved_name (m_settings.m_name)) return true; /* separators are already copied to m_settings in the separators * function above. However this is not the case for the column * widths in fw mode, so do this now. */ if (file_format() == GncImpFileFormat::FIXED_WIDTH) { auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get()); m_settings.m_column_widths = fwtok->get_columns(); } return m_settings.save(); }
void do_file_test( dcmtkpp::DataSet const & dcmtkpp_data_set, std::string transfer_syntax, E_EncodingType item_encoding, E_GrpLenEncoding group_length_encoding) { // Write input data set auto const dcmtk_data_set = dynamic_cast<DcmDataset*>(dcmtkpp::convert(dcmtkpp_data_set)); DcmFileFormat file_format(dcmtk_data_set); file_format.getMetaInfo()->putAndInsertString( DCM_TransferSyntaxUID, transfer_syntax.c_str()); file_format.getMetaInfo()->putAndInsertString( DCM_MediaStorageSOPClassUID, dcmtkpp_data_set.as_string(dcmtkpp::registry::SOPClassUID)[0].c_str()); file_format.getMetaInfo()->putAndInsertString( DCM_MediaStorageSOPInstanceUID, dcmtkpp_data_set.as_string(dcmtkpp::registry::SOPInstanceUID)[0].c_str()); std::string data(1000000, '\0'); DcmOutputBufferStream dcmtk_stream(&data[0], data.size()); file_format.transferInit(); OFCondition const condition = file_format.write( dcmtk_stream, DcmXfer(transfer_syntax.c_str()).getXfer(), item_encoding, NULL, group_length_encoding); BOOST_REQUIRE(condition == EC_Normal); file_format.transferEnd(); // Store data in a stream data = data.substr(0, dcmtk_stream.tell()); std::istringstream stream(data); // Read output data set dcmtkpp::DataSet meta_information, other_dcmtkpp_data_set; std::tie(meta_information, other_dcmtkpp_data_set) = dcmtkpp::Reader::read_file(stream); BOOST_REQUIRE(other_dcmtkpp_data_set == dcmtkpp_data_set); BOOST_REQUIRE( meta_information.as_string(dcmtkpp::registry::TransferSyntaxUID) == dcmtkpp::Value::Strings({transfer_syntax})); BOOST_REQUIRE( meta_information.as_string(dcmtkpp::registry::MediaStorageSOPClassUID) == other_dcmtkpp_data_set.as_string(dcmtkpp::registry::SOPClassUID)); BOOST_REQUIRE( meta_information.as_string(dcmtkpp::registry::MediaStorageSOPInstanceUID) == other_dcmtkpp_data_set.as_string(dcmtkpp::registry::SOPInstanceUID)); }
//-- // // ReadFile // //-- // Read mesh from a file bool Mesh::ReadFile( const std::string& file_name ) { FileFormat file_format(UNKNOWN_FILE); // Find file extension int pos = file_name.find_last_of('.'); if( pos == -1 ) { // File has no extension return false; } // Format extension string std::string extension = UpperCase( file_name.substr( ++pos ) ); // WRL extension if( extension == "WRL" ) { // // Check VRML file version // std::ifstream file(file_name.c_str()); if( file.is_open() == false ) return false; std::string word; file>>word; if( word != "#VRML" ) { file.close(); return false; } file>>word; file.close(); if( word == "V1.0" ) { file_format = VRML_1_FILE; } else if( word == "V2.0" ) { file_format = VRML_2_FILE; } else { return false; } }
static FileFormat file_format_from_name(char *filename) { char ext[4]; strcpy(ext, extension(filename)); downcase(ext); return file_format(ext); }