void ArrayObject::save(const chowstring & filename) { FSFile fp(convert_path(filename).c_str(), "w"); if (!fp.is_open()) return; WriteStream stream; stream.write(CT_ARRAY_MAGIC, sizeof(CT_ARRAY_MAGIC)); stream.write_int16(ARRAY_MAJOR_VERSION); stream.write_int16(ARRAY_MINOR_VERSION); stream.write_int32(data.x_size); stream.write_int32(data.y_size); stream.write_int32(data.z_size); int flags = 0; if (data.is_numeric) flags |= NUMERIC_FLAG; if (data.offset != 0) flags |= BASE1_FLAG; stream.write_int32(flags); for (int i = 0; i < data.x_size * data.y_size * data.z_size; i++) { if (data.is_numeric) { stream.write_int32(int(data.array[i])); } else { stream.write_int32(data.strings[i].size()); stream.write_string(data.strings[i]); } } stream.save(fp); fp.close(); }
void AssociateArray::save(const std::string & path, int method) { FSFile fp(path.c_str(), "w"); if (!fp.is_open()) { std::cout << "Could not save associate array: " << path << std::endl; return; } WriteStream stream; save_assarray(*this, stream, method); stream.save(fp); fp.close(); }