MeshLib
 
Loading...
Searching...
No Matches
MRIOFilters.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <compare>
5#include <optional>
6#include <string>
7#include <vector>
8
9namespace MR
10{
11
15
17{
18 IOFilter() = default;
19 IOFilter( std::string _name, std::string _ext )
20 : name{ std::move( _name ) }
21 , extensions{ std::move( _ext ) }
22 {}
23
24 std::string name;
25 std::string extensions; // "*.ext" or "*.ext1;*.ext2;*.ext3"
26
27 std::partial_ordering operator <=>( const IOFilter& ) const = default;
28
29 [[nodiscard]] inline bool isSupportedExtension( const std::string& ext ) const
30 {
31 return extensions.find( ext ) != std::string::npos;
32 }
33};
34
35using IOFilters = std::vector<IOFilter>;
36
37inline IOFilters operator | ( const IOFilters& a, const IOFilters& b )
38{
39 IOFilters copy = a;
40 for ( const auto& bElem : b )
41 {
42 if ( std::find_if( a.begin(), a.end(), [&] ( const IOFilter& aF )
43 {
44 return aF.extensions == bElem.extensions;
45 } ) == a.end() )
46 copy.push_back( bElem );
47 }
48 return copy;
49}
50
52inline std::optional<IOFilter> findFilter( const IOFilters& filters, const std::string& extension )
53{
54 const auto it = std::find_if( filters.begin(), filters.end(), [&extension] ( auto&& filter )
55 {
56 return filter.isSupportedExtension( extension );
57 } );
58 if ( it != filters.end() )
59 return *it;
60 else
61 return std::nullopt;
62}
63
65
66}
BitSet operator|(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:323
std::vector< IOFilter > IOFilters
Definition MRIOFilters.h:35
std::optional< IOFilter > findFilter(const IOFilters &filters, const std::string &extension)
find a corresponding filter for a given extension
Definition MRIOFilters.h:52
Definition MRCameraOrientationPlugin.h:8
Definition MRIOFilters.h:17
bool isSupportedExtension(const std::string &ext) const
Definition MRIOFilters.h:29
IOFilter(std::string _name, std::string _ext)
Definition MRIOFilters.h:19
IOFilter()=default
std::partial_ordering operator<=>(const IOFilter &) const =default
std::string extensions
Definition MRIOFilters.h:25
std::string name
Definition MRIOFilters.h:24