bool Stream::writeLittle(const std::string *value, std::size_t size) const { if (value) { if (size) { if (writeLittle(size)) { for (unsigned int i = 0; i < size; ++i) { if (!writeLittle(value[i])) { error = true; return false; } } return true; } else { error = true; return false; } } else { return true; } } else { return false; } }
void SplinePath::write(DataTargetRef target) { auto stream = target->getStream(); stream->writeLittle(size()); for (auto &point : points) { stream->writeLittle(point.x); stream->writeLittle(point.y); } }
bool Stream::writeLittle(const std::string &value) const { if (!value.empty()) { bool returnValue = writeLittle(value.size()) && writeLittle(&value[0], value.size()); error |= !returnValue; return returnValue; } else { return true; } }
void GenSOM::saveFile(std::ostream &os) const { if (!os) { throw std::runtime_error("GenSOM::saveFile(): " "could not write to stream."); } os << "gerbilsom\x20\x20\x20\x20\x20\x20\x20"; // 16 byte "magic" writeLittle<int32_t>(os, 3); // file version writeLittle<int32_t>(os, 1); // data type: 1 = ieee float writeLittle<int32_t>(os, int32_t(config.type)); // SOM type writeLittle<int32_t>(os, int32_t(neurons.size())); // SOM size int nbands; if (neurons.size() > 0) { nbands = neurons[0].size(); } else { nbands = 0; } writeLittle<int32_t>(os, int32_t(nbands)); // num bands if (!os) { throw std::runtime_error("GenSOM::saveFile(): " "could not write to stream."); } // write out neurons for (std::vector<Neuron>::const_iterator vit = neurons.begin(); vit != neurons.end(); ++vit) { for (Neuron::const_iterator nit = vit->begin(); nit != vit->end(); ++nit) { writeLittle(os, *nit); } } if (!os) { throw std::runtime_error("GenSOM::saveFile(): " "could not write to stream."); } }