28#include "serialization/serialize.h"
30#include <vclib/concepts/mesh/elements/element.h>
31#include <vclib/types.h>
39inline std::ofstream openOutputFileStream(
40 const std::string& filename,
41 const std::string& ext =
"")
43 setlocale(LC_ALL,
"C");
44 std::string actualFileName = filename;
47 if (!path.empty() && !std::filesystem::exists(path)) {
48 bool res = std::filesystem::create_directory(path);
50 throw std::runtime_error(
"Cannot create directory: " + path);
59 fp.imbue(std::locale().classic());
62 fp.open(actualFileName, std::ofstream::binary);
64 throw CannotOpenFileException(actualFileName);
76 FileType format = FileType(),
79 if (isColor && !std::is_integral<T>::value)
83 serialize(file, tmp, format.endian);
85 file << (int) p <<
" ";
92 FileType format = FileType(),
95 if (isColor && !std::is_integral<T>::value)
97 unsigned char tmp = p;
99 serialize(file, tmp, format.endian);
101 file << (uint) p <<
" ";
108 FileType format = FileType(),
109 bool isColor =
false)
111 if (isColor && !std::is_integral<T>::value)
115 serialize(file, tmp, format.endian);
124 FileType format = FileType(),
125 bool isColor =
false)
127 if (isColor && !std::is_integral<T>::value)
129 unsigned short tmp = p;
131 serialize(file, tmp, format.endian);
140 FileType format = FileType(),
141 bool isColor =
false)
143 if (isColor && !std::is_integral<T>::value)
147 serialize(file, tmp, format.endian);
156 FileType format = FileType(),
157 bool isColor =
false)
159 if (isColor && !std::is_integral<T>::value)
163 serialize(file, tmp, format.endian);
172 FileType format = FileType(),
173 bool isColor =
false)
176 if (isColor && std::is_integral<T>::value)
179 serialize(file, tmp, format.endian);
188 FileType format = FileType(),
189 bool isColor =
false)
192 if (isColor && std::is_integral<T>::value)
195 serialize(file, tmp, format.endian);
206 FileType format = FileType(),
207 bool isColor =
false)
210 case PrimitiveType::CHAR: writeChar(file, p, format, isColor);
break;
211 case PrimitiveType::UCHAR: writeUChar(file, p, format, isColor);
break;
212 case PrimitiveType::SHORT: writeShort(file, p, format, isColor);
break;
213 case PrimitiveType::USHORT: writeUShort(file, p, format, isColor);
break;
214 case PrimitiveType::INT: writeInt(file, p, format, isColor);
break;
215 case PrimitiveType::UINT: writeUInt(file, p, format, isColor);
break;
216 case PrimitiveType::FLOAT: writeFloat(file, p, format, isColor);
break;
217 case PrimitiveType::DOUBLE: writeDouble(file, p, format, isColor);
break;
223template<ElementConcept El>
224void writeCustomComponent(
227 const std::string& cName,
229 FileType format = FileType())
231 std::type_index ti = elem.customComponentType(cName);
232 if (ti ==
typeid(
char))
234 file, elem.template customComponent<char>(cName), type, format);
235 else if (ti ==
typeid(
unsigned char))
238 elem.template customComponent<unsigned char>(cName),
241 else if (ti ==
typeid(
short))
243 file, elem.template customComponent<short>(cName), type, format);
244 else if (ti ==
typeid(
unsigned short))
247 elem.template customComponent<unsigned short>(cName),
250 else if (ti ==
typeid(
int))
252 file, elem.template customComponent<int>(cName), type, format);
253 else if (ti ==
typeid(
unsigned int))
255 file, elem.template customComponent<uint>(cName), type, format);
256 else if (ti ==
typeid(
float))
258 file, elem.template customComponent<float>(cName), type, format);
259 else if (ti ==
typeid(
double))
261 file, elem.template customComponent<double>(cName), type, format);
static std::string addExtensionIfNeeded(const std::string &filename, const std::string &ext)
Adds an extension to a file name if it doesn't already have it.
Definition file_info.h:271
static std::string pathWithoutFileName(const std::string &fullpath)
Get the path of a file.
Definition file_info.h:197
PrimitiveType
A simple type that enumerates the main primitive types.
Definition base.h:58