<commit_before>#ifndef _INTERFACE_MVS_H_
#define _INTERFACE_MVS_H_


// I N C L U D E S /////////////////////////////////////////////////

#include <fstream>

// D E F I N E S ///////////////////////////////////////////////////

// uncomment to enable custom OpenCV data types
// (should be uncommented if OpenCV is not available)
#if !defined(_USE_OPENCV) && !defined(_USE_CUSTOM_CV)
#define _USE_CUSTOM_CV
#endif

#ifndef NO_ID
#define NO_ID std::numeric_limits<uint32_t>::max()
#endif


// S T R U C T S ///////////////////////////////////////////////////

#ifdef _USE_CUSTOM_CV

namespace cv {

// simple cv::Matx
template<typename _Tp, int m, int n>
class Matx
{
public:
	typedef _Tp Type;
	inline Matx() {}
	#ifdef _USE_EIGEN
	EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Type,m*n)
	typedef Eigen::Matrix<Type,m,n,(n>1?Eigen::RowMajor : Eigen::ColMajor)> EMat;
	typedef Eigen::Map<const EMat> CEMatMap;
	typedef Eigen::Map<EMat> EMatMap;
	inline Matx(const EMat& rhs) { operator EMatMap () = rhs; }
	inline Matx& operator = (const EMat& rhs) { operator EMatMap () = rhs; return *this; }
	inline operator CEMatMap() const { return CEMatMap((const Type*)val); }
	inline operator EMatMap () { return EMatMap((Type*)val); }
	#endif
	Type operator()(int r, int c) const { return val[r*n+c]; }
	Type& operator()(int r, int c) { return val[r*n+c]; }
public:
	_Tp val[m*n];
};

// simple cv::Matx
template<typename _Tp>
class Point3_
{
public:
	typedef _Tp Type;
	inline Point3_() {}
	#ifdef _USE_EIGEN
	EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Type,3)
	typedef Eigen::Matrix<Type,3,1> EVec;
	typedef Eigen::Map<EVec> EVecMap;
	inline Point3_(const EVec& rhs) { operator EVecMap () = rhs; }
	inline Point3_& operator = (const EVec& rhs) { operator EVecMap () = rhs; return *this; }
	inline operator const EVecMap () const { return EVecMap((Type*)this); }
	inline operator EVecMap () { return EVecMap((Type*)this); }
	#endif
public:
	_Tp x, y, z;
};

} // namespace cv
#endif
/*----------------------------------------------------------------*/


// custom serialization
namespace ARCHIVE {

struct ArchiveSave;
struct ArchiveLoad;

template<typename _Tp>
bool Save(ArchiveSave& a, const _Tp& obj) {
	const_cast<_Tp&>(obj).serialize(a, 0);
	return true;
}
template<typename _Tp>
bool Load(ArchiveLoad& a, _Tp& obj) {
	obj.serialize(a, 0);
	return true;
}


// Basic serialization types
struct ArchiveSave {
	std::ostream& stream;
	ArchiveSave(std::ostream& _stream) : stream(_stream) {}
	template<typename _Tp>
	ArchiveSave& operator & (const _Tp& obj) {
		Save(*this, obj);
		return *this;
	}
};
struct ArchiveLoad {
	std::istream& stream;
	ArchiveLoad(std::istream& _stream) : stream(_stream) {}
	template<typename _Tp>
	ArchiveLoad& operator & (_Tp& obj) {
		Load(*this, obj);
		return *this;
	}
};


// Main exporter & importer
template<typename _Tp>
bool SerializeSave(const _Tp& obj, const std::string& fileName) {
	std::ofstream stream(fileName, std::ofstream::binary);
	if (!stream.is_open())
		return false;
	ARCHIVE::ArchiveSave serializer(stream);
	serializer & obj;
	return true;
}
template<typename _Tp>
bool SerializeLoad(_Tp& obj, const std::string& fileName) {
	std::ifstream stream(fileName, std::ifstream::binary);
	if (!stream.is_open())
		return false;
	ARCHIVE::ArchiveLoad serializer(stream);
	serializer & obj;
	return true;
}


#define ARCHIVE_DEFINE_TYPE(TYPE) \
template<> \
bool Save<TYPE>(ArchiveSave& a, const TYPE& v) { \
	a.stream.write((const char*)&v, sizeof(TYPE)); \
	return true; \
} \
template<> \
bool Load<TYPE>(ArchiveLoad& a, TYPE& v) { \
	a.stream.read((char*)&v, sizeof(TYPE)); \
	return true; \
}

// Serialization support for basic types
ARCHIVE_DEFINE_TYPE(uint32_t)
ARCHIVE_DEFINE_TYPE(uint64_t)
ARCHIVE_DEFINE_TYPE(float)
ARCHIVE_DEFINE_TYPE(double)
//#ifdef __clang__
//ARCHIVE_DEFINE_TYPE(unsigned long)
//#endif

// Serialization support for cv::Matx<commit_msg>[software/SfM] Fix OSX compiling issue with openMVG2openMVS #713<commit_after>#ifndef _INTERFACE_MVS_H_
#define _INTERFACE_MVS_H_


// I N C L U D E S /////////////////////////////////////////////////

#include <fstream>

// D E F I N E S ///////////////////////////////////////////////////

// uncomment to enable custom OpenCV data types
// (should be uncommented if OpenCV is not available)
#if !defined(_USE_OPENCV) && !defined(_USE_CUSTOM_CV)
#define _USE_CUSTOM_CV
#endif

#ifndef NO_ID
#define NO_ID std::numeric_limits<uint32_t>::max()
#endif


// S T R U C T S ///////////////////////////////////////////////////

#ifdef _USE_CUSTOM_CV

namespace cv {

// simple cv::Matx
template<typename _Tp, int m, int n>
class Matx
{
public:
	typedef _Tp Type;
	inline Matx() {}
	#ifdef _USE_EIGEN
	EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Type,m*n)
	typedef Eigen::Matrix<Type,m,n,(n>1?Eigen::RowMajor : Eigen::ColMajor)> EMat;
	typedef Eigen::Map<const EMat> CEMatMap;
	typedef Eigen::Map<EMat> EMatMap;
	inline Matx(const EMat& rhs) { operator EMatMap () = rhs; }
	inline Matx& operator = (const EMat& rhs) { operator EMatMap () = rhs; return *this; }
	inline operator CEMatMap() const { return CEMatMap((const Type*)val); }
	inline operator EMatMap () { return EMatMap((Type*)val); }
	#endif
	Type operator()(int r, int c) const { return val[r*n+c]; }
	Type& operator()(int r, int c) { return val[r*n+c]; }
public:
	_Tp val[m*n];
};

// simple cv::Matx
template<typename _Tp>
class Point3_
{
public:
	typedef _Tp Type;
	inline Point3_() {}
	#ifdef _USE_EIGEN
	EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Type,3)
	typedef Eigen::Matrix<Type,3,1> EVec;
	typedef Eigen::Map<EVec> EVecMap;
	inline Point3_(const EVec& rhs) { operator EVecMap () = rhs; }
	inline Point3_& operator = (const EVec& rhs) { operator EVecMap () = rhs; return *this; }
	inline operator const EVecMap () const { return EVecMap((Type*)this); }
	inline operator EVecMap () { return EVecMap((Type*)this); }
	#endif
public:
	_Tp x, y, z;
};

} // namespace cv
#endif
/*----------------------------------------------------------------*/


// custom serialization
namespace ARCHIVE {

struct ArchiveSave;
struct ArchiveLoad;

template<typename _Tp>
bool Save(ArchiveSave& a, const _Tp& obj) {
	const_cast<_Tp&>(obj).serialize(a, 0);
	return true;
}
template<typename _Tp>
bool Load(ArchiveLoad& a, _Tp& obj) {
	obj.serialize(a, 0);
	return true;
}


// Basic serialization types
struct ArchiveSave {
	std::ostream& stream;
	ArchiveSave(std::ostream& _stream) : stream(_stream) {}
	template<typename _Tp>
	ArchiveSave& operator & (const _Tp& obj) {
		Save(*this, obj);
		return *this;
	}
};
struct ArchiveLoad {
	std::istream& stream;
	ArchiveLoad(std::istream& _stream) : stream(_stream) {}
	template<typename _Tp>
	ArchiveLoad& operator & (_Tp& obj) {
		Load(*this, obj);
		return *this;
	}
};


// Main exporter & importer
template<typename _Tp>
bool SerializeSave(const _Tp& obj, const std::string& fileName) {
	std::ofstream stream(fileName, std::ofstream::binary);
	if (!stream.is_open())
		return false;
	ARCHIVE::ArchiveSave serializer(stream);
	serializer & obj;
	return true;
}
template<typename _Tp>
bool SerializeLoad(_Tp& obj, const std::string& fileName) {
	std::ifstream stream(fileName, std::ifstream::binary);
	if (!stream.is_open())
		return false;
	ARCHIVE::ArchiveLoad serializer(stream);
	serializer & obj;
	return true;
}


#define ARCHIVE_DEFINE_TYPE(TYPE) \
template<> \
bool Save<TYPE>(ArchiveSave& a, const TYPE& v) { \
	a.stream.write((const char*)&v, sizeof(TYPE)); \
	return true; \
} \
template<> \
bool Load<TYPE>(ArchiveLoad& a, TYPE& v) { \
	a.stream.read((char*)&v, sizeof(TYPE)); \
	return true; \
}

// Serialization support for basic types
ARCHIVE_DEFINE_TYPE(uint32_t)
ARCHIVE_DEFINE_TYPE(uint64_t)
ARCHIVE_DEFINE_TYPE(float)
ARCHIVE_DEFINE_TYPE(double)
#ifdef __APPLE__
  #ifdef __clang__
    ARCHIVE_DEFINE_TYPE(unsigned long)
  #endif
#endif

// Serialization support for cv::Matx
{'fraction_non_alphanumeric': 0.18465016957668634, 'fraction_numerical': 0.004522044969224971, 'mean_word_length': 3.854878048780488, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2740076', 'n_tokens_mistral': 2934, 'n_tokens_neox': 2774, 'n_words': 719}