MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / stringToStreampos

Function stringToStreampos

src/openms/source/FORMAT/HANDLERS/IndexedMzMLDecoder.cpp:27–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25 namespace IndexedMzMLUtils
26 {
27 std::streampos stringToStreampos(const std::string& s)
28 {
29 // Try to cast the string to a type that can hold the integer value
30 // stored in the std::streampos type (which can vary from 32 to 128 bits
31 // depending on the system).
32 //
33 // long long has a minimal size of 64 bits and can address a range up to
34 // 16 Exbibit (or 2 Exbibyte), we can hopefully expect our files to be
35 // smaller than an Exabyte and should be safe.
36 std::streampos res;
37 try
38 {
39
40 res = boost::lexical_cast< unsigned long long >(s);
41 // TESTING CAST: res = (int) res; // use this only when emulating 32 bit systems
42
43 }
44 catch (boost::bad_lexical_cast&)
45 {
46 std::cerr << "Trying to convert corrupted / unreadable value to std::streampos : " << s << std::endl;
47 std::cerr << "This can also happen if the value exceeds 63 bits, please check your input." << std::endl;
48 throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
49 String("Could not convert string '") + s + "' to a 64 bit integer.");
50 }
51
52 // Check if the value can fit into std::streampos
53 if ( std::abs( boost::lexical_cast< long double >(s) - res) > 0.1)
54 {
55 std::cerr << "Your system may not support addressing a file of this size,"
56 << " only addresses that fit into a " << sizeof(std::streamsize)*8 <<
57 " bit integer are supported on your system." << std::endl;
58 throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
59 String("Could not convert string '") + s + "' to an integer on your system.");
60 }
61
62 return res;
63 }
64 }
65
66 int IndexedMzMLDecoder::parseOffsets(const String& filename, std::streampos indexoffset, OffsetVector& spectra_offsets, OffsetVector& chromatograms_offsets)

Callers 2

findIndexListOffsetMethod · 0.85
domParseIndexedEnd_Method · 0.85

Calls 1

StringClass · 0.50

Tested by

no test coverage detected