| 93 | // Raise an exception if it can't be loaded. |
| 94 | |
| 95 | CachedFileRcPtr LocalFileFormat::read(std::istream & istream, |
| 96 | const std::string & /*fileName*/, |
| 97 | Interpolation interp) const |
| 98 | { |
| 99 | // Parse Header Info. |
| 100 | int lut_size = -1; |
| 101 | float from_min = 0.0; |
| 102 | float from_max = 1.0; |
| 103 | int version = -1; |
| 104 | int components = -1; |
| 105 | |
| 106 | const int MAX_LINE_SIZE = 4096; |
| 107 | char lineBuffer[MAX_LINE_SIZE]; |
| 108 | int currentLine = 0; |
| 109 | |
| 110 | // PARSE HEADER INFO |
| 111 | { |
| 112 | std::string headerLine(""); |
| 113 | do |
| 114 | { |
| 115 | istream.getline(lineBuffer, MAX_LINE_SIZE); |
| 116 | ++currentLine; |
| 117 | headerLine = std::string(lineBuffer); |
| 118 | |
| 119 | if(StringUtils::StartsWith(headerLine, "Version")) |
| 120 | { |
| 121 | // " " in format means any number of spaces (white space, |
| 122 | // new line, tab) including 0 of them. |
| 123 | // "Version1" is valid. |
| 124 | if (sscanf(lineBuffer, "Version %d", &version) != 1) |
| 125 | { |
| 126 | ThrowErrorMessage("Invalid 'Version' Tag", currentLine, headerLine); |
| 127 | } |
| 128 | else if (version != 1) |
| 129 | { |
| 130 | ThrowErrorMessage("Only format version 1 supported", currentLine, headerLine); |
| 131 | } |
| 132 | } |
| 133 | else if(StringUtils::StartsWith(headerLine, "From")) |
| 134 | { |
| 135 | char fromMinS[64] = ""; |
| 136 | char fromMaxS[64] = ""; |
| 137 | #ifdef _WIN32 |
| 138 | if (sscanf_s(lineBuffer, "From %63s %63s", fromMinS, 64, fromMaxS, 64) != 2) |
| 139 | #else |
| 140 | if (sscanf(lineBuffer, "From %63s %63s", fromMinS, fromMaxS) != 2) |
| 141 | #endif |
| 142 | { |
| 143 | ThrowErrorMessage("Invalid 'From' Tag", currentLine, headerLine); |
| 144 | } |
| 145 | else |
| 146 | { |
| 147 | const auto fromMinAnswer = NumberUtils::from_chars(fromMinS, fromMinS + 64, from_min); |
| 148 | const auto fromMaxAnswer = NumberUtils::from_chars(fromMaxS, fromMaxS + 64, from_max); |
| 149 | |
| 150 | if (fromMinAnswer.ec != std::errc() || fromMaxAnswer.ec != std::errc()) |
| 151 | { |
| 152 | ThrowErrorMessage("Invalid 'From' Tag", currentLine, headerLine); |
nothing calls this directly
no test coverage detected