删除twain重复头文件
This commit is contained in:
parent
d33a26d64b
commit
7fbda30161
File diff suppressed because it is too large
Load Diff
|
@ -1,114 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_TWPP_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_TWPP_HPP
|
|
||||||
|
|
||||||
#include "twpp/env.hpp"
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <initializer_list>
|
|
||||||
#include <memory>
|
|
||||||
#include <utility>
|
|
||||||
#include <iterator>
|
|
||||||
#include <type_traits>
|
|
||||||
#include <limits>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <mutex>
|
|
||||||
#include <condition_variable>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <list>
|
|
||||||
#include <cstring>
|
|
||||||
#include <array>
|
|
||||||
#include <utility>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include "twpp/utils.hpp"
|
|
||||||
|
|
||||||
#include "twpp/types.hpp"
|
|
||||||
#include "twpp/strings.hpp"
|
|
||||||
#include "twpp/fix32.hpp"
|
|
||||||
#include "twpp/frame.hpp"
|
|
||||||
#include "twpp/exception.hpp"
|
|
||||||
#include "twpp/typesops.hpp"
|
|
||||||
|
|
||||||
#include "twpp/memoryops.hpp"
|
|
||||||
#include "twpp/memory.hpp"
|
|
||||||
|
|
||||||
#include "twpp/enums.hpp"
|
|
||||||
#include "twpp/status.hpp"
|
|
||||||
#include "twpp/identity.hpp"
|
|
||||||
#include "twpp/imageinfo.hpp"
|
|
||||||
#include "twpp/imagelayout.hpp"
|
|
||||||
#include "twpp/deviceevent.hpp"
|
|
||||||
#include "twpp/element8.hpp"
|
|
||||||
|
|
||||||
#include "twpp/audio.hpp"
|
|
||||||
#include "twpp/capability.hpp"
|
|
||||||
#include "twpp/customdata.hpp"
|
|
||||||
#include "twpp/cie.hpp"
|
|
||||||
#include "twpp/curveresponse.hpp"
|
|
||||||
#include "twpp/event.hpp"
|
|
||||||
#include "twpp/extimageinfo.hpp"
|
|
||||||
#include "twpp/filesystem.hpp"
|
|
||||||
#include "twpp/imagememxfer.hpp"
|
|
||||||
#include "twpp/imagenativexfer.hpp"
|
|
||||||
#include "twpp/internal.hpp"
|
|
||||||
#include "twpp/jpegcompression.hpp"
|
|
||||||
#include "twpp/palette8.hpp"
|
|
||||||
#include "twpp/passthrough.hpp"
|
|
||||||
#include "twpp/pendingxfers.hpp"
|
|
||||||
#include "twpp/setupfilexfer.hpp"
|
|
||||||
#include "twpp/setupmemxfer.hpp"
|
|
||||||
#include "twpp/userinterface.hpp"
|
|
||||||
|
|
||||||
#if !defined(TWPP_IS_DS)
|
|
||||||
# include "twpp/application.hpp"
|
|
||||||
#else
|
|
||||||
# include "twpp/datasource.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(TWPP_NO_NOTES)
|
|
||||||
# if !defined(TWPP_IS_DS)
|
|
||||||
# pragma message ("note: using APPLICATION version of TWPP library, define TWPP_IS_DS before including twpp.hpp if you want DATA SOURCE version")
|
|
||||||
# if defined(TWPP_DETAIL_OS_WIN32)
|
|
||||||
# pragma message ("note: place the following into your module-definition (.def) file: EXPORTS DS_Entry @1")
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
# pragma message ("note: using DATA SOURCE version of TWPP library, undefine TWPP_IS_DS if you want APPLICATION version")
|
|
||||||
# pragma message ("note: make sure to place TWPP_ENTRY(<your-source-class-type>) macro in exactly one source file")
|
|
||||||
# endif
|
|
||||||
# if defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
# pragma message "warning: Str32, Str64, Str128 and Str255 are not null-terminated"
|
|
||||||
# endif
|
|
||||||
# pragma message ("note: to disable notes and warnings, define TWPP_NO_NOTES before including TWPP header")
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_TWPP_HPP
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,119 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_AUDIO_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_AUDIO_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Information about current audio transfer.
|
|
||||||
/// ArgType::AudioInfo
|
|
||||||
class AudioInfo {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates empty audio info.
|
|
||||||
constexpr AudioInfo() noexcept :
|
|
||||||
m_name(), m_reserved(){}
|
|
||||||
|
|
||||||
/// Creates audio info with set name of audio data.
|
|
||||||
explicit constexpr AudioInfo(const Str255& name, UInt32 reserved = 0) noexcept :
|
|
||||||
m_name(name), m_reserved(reserved){}
|
|
||||||
|
|
||||||
/// Name of audio data.
|
|
||||||
constexpr const Str255& name() const noexcept{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Name of audio data.
|
|
||||||
Str255& name() noexcept{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr UInt32 reserved() const noexcept{
|
|
||||||
return m_reserved;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setReserved(UInt32 reserved) noexcept{
|
|
||||||
m_reserved = reserved;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Str255 m_name;
|
|
||||||
UInt32 m_reserved;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Owner of audio transfer handle.
|
|
||||||
class AudioNativeXfer {
|
|
||||||
|
|
||||||
public:
|
|
||||||
template<typename T>
|
|
||||||
using Data = Detail::Lock<typename std::decay<T>::type>;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
using ConstData = Detail::Lock<const typename std::decay<T>::type>;
|
|
||||||
|
|
||||||
|
|
||||||
/// Creates an empty handle owner.
|
|
||||||
AudioNativeXfer() noexcept :
|
|
||||||
m_handle(){}
|
|
||||||
|
|
||||||
/// Creates a memory area of desired size for audio native transfer.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
explicit AudioNativeXfer(UInt32 size) :
|
|
||||||
m_handle(Detail::alloc(size)){}
|
|
||||||
|
|
||||||
/// Audio data.
|
|
||||||
template<typename T = void>
|
|
||||||
Data<T> data() noexcept{
|
|
||||||
return m_handle.lock<typename std::decay<T>::type>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Audio data.
|
|
||||||
template<typename T = void>
|
|
||||||
ConstData<T> data() const noexcept{
|
|
||||||
return m_handle.lock<const typename std::decay<T>::type>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Releases the owned handle.
|
|
||||||
/// The user becomes responsible for freeing the handle.
|
|
||||||
Handle release() noexcept{
|
|
||||||
return m_handle.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Detail::UniqueHandle m_handle;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_AUDIO_HPP
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,269 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_CIE_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_CIE_HPP
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Part of CieColor structure.
|
|
||||||
class CiePoint {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates zero-initialized cie point.
|
|
||||||
constexpr CiePoint() noexcept :
|
|
||||||
m_x(), m_y(), m_z(){}
|
|
||||||
|
|
||||||
/// Creates cie point with desired values.
|
|
||||||
constexpr CiePoint(Fix32 x, Fix32 y, Fix32 z) noexcept :
|
|
||||||
m_x(x), m_y(y), m_z(z){}
|
|
||||||
|
|
||||||
/// X value of CIE space.
|
|
||||||
constexpr Fix32 x() const noexcept{
|
|
||||||
return m_x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Y value of CIE space.
|
|
||||||
constexpr Fix32 y() const noexcept{
|
|
||||||
return m_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Z value of CIE space.
|
|
||||||
constexpr Fix32 z() const noexcept{
|
|
||||||
return m_z;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets x value of CIE space.
|
|
||||||
void setX(Fix32 x) noexcept{
|
|
||||||
m_x = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets y value of CIE space.
|
|
||||||
void setY(Fix32 y) noexcept{
|
|
||||||
m_y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets z value of CIE space.
|
|
||||||
void setZ(Fix32 z) noexcept{
|
|
||||||
m_z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Fix32 m_x;
|
|
||||||
Fix32 m_y;
|
|
||||||
Fix32 m_z;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Defines parameters for channel transformations.
|
|
||||||
/// Part of TransformStage.
|
|
||||||
class DecodeFunction {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates zero-initialized decode function.
|
|
||||||
constexpr DecodeFunction() noexcept{}
|
|
||||||
|
|
||||||
/// Creates initialized decode function.
|
|
||||||
constexpr DecodeFunction(
|
|
||||||
Fix32 startIn,
|
|
||||||
Fix32 breakIn,
|
|
||||||
Fix32 endIn,
|
|
||||||
Fix32 startOut,
|
|
||||||
Fix32 breakOut,
|
|
||||||
Fix32 endOut,
|
|
||||||
Fix32 gamma,
|
|
||||||
Fix32 sampleCount
|
|
||||||
) noexcept :
|
|
||||||
m_startIn(startIn), m_breakIn(breakIn), m_endIn(endIn),
|
|
||||||
m_startOut(startOut), m_breakOut(breakOut), m_endOut(endOut),
|
|
||||||
m_gamma(gamma), m_sampleCount(sampleCount){}
|
|
||||||
|
|
||||||
/// Starting input value.
|
|
||||||
constexpr Fix32 startIn() const noexcept{
|
|
||||||
return m_startIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets starting input value.
|
|
||||||
void setStartIn(Fix32 startIn) noexcept{
|
|
||||||
m_startIn = startIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ending input value.
|
|
||||||
constexpr Fix32 breakIn() const noexcept{
|
|
||||||
return m_breakIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets ending input value.
|
|
||||||
void setBreakIn(Fix32 breakIn) noexcept{
|
|
||||||
m_breakIn = breakIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Input value when to switch from linear to gamma transformation.
|
|
||||||
constexpr Fix32 endIn() const noexcept{
|
|
||||||
return m_endIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets input value when to switch from linear to gamma transformation.
|
|
||||||
void setEndIn(Fix32 endIn) noexcept{
|
|
||||||
m_endIn = endIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Starting output value.
|
|
||||||
constexpr Fix32 startOut() const noexcept{
|
|
||||||
return m_startOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets starting output value.
|
|
||||||
void setStartOut(Fix32 startOut) noexcept{
|
|
||||||
m_startOut = startOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ending output value.
|
|
||||||
constexpr Fix32 breakOut() const noexcept{
|
|
||||||
return m_breakOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets ending output value.
|
|
||||||
void setBreakOut(Fix32 breakOut) noexcept{
|
|
||||||
m_breakOut = breakOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Output value when to switch from linear to gamma transformation.
|
|
||||||
constexpr Fix32 endOut() const noexcept{
|
|
||||||
return m_endOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets output value when to switch from linear to gamma transformation.
|
|
||||||
void setEndOut(Fix32 endOut) noexcept{
|
|
||||||
m_endOut = endOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Constant, exponential used in gamma funciton.
|
|
||||||
constexpr Fix32 gamma() const noexcept{
|
|
||||||
return m_gamma;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets constant, exponential used in gamma funciton.
|
|
||||||
void setGamma(Fix32 gamma) noexcept{
|
|
||||||
m_gamma = gamma;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of samples in lookup table.
|
|
||||||
constexpr Fix32 sampleCount() const noexcept{
|
|
||||||
return m_sampleCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of samples in lookup table.
|
|
||||||
void setSampleCount(Fix32 sampleCount) noexcept{
|
|
||||||
m_sampleCount = sampleCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Fix32 m_startIn;
|
|
||||||
Fix32 m_breakIn;
|
|
||||||
Fix32 m_endIn;
|
|
||||||
Fix32 m_startOut;
|
|
||||||
Fix32 m_breakOut;
|
|
||||||
Fix32 m_endOut;
|
|
||||||
Fix32 m_gamma;
|
|
||||||
Fix32 m_sampleCount;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Parameters of ABC or LMN transformations.
|
|
||||||
/// Refer to manual for more information about members.
|
|
||||||
class TransformStage {
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef std::array<DecodeFunction, 3> Decode;
|
|
||||||
typedef std::array<std::array<Fix32, 3>, 3> Mix;
|
|
||||||
|
|
||||||
constexpr TransformStage() noexcept :
|
|
||||||
m_decode(), m_mix(){}
|
|
||||||
|
|
||||||
constexpr TransformStage(const Decode& decode) noexcept :
|
|
||||||
m_decode(decode), m_mix(){}
|
|
||||||
|
|
||||||
constexpr TransformStage(const Mix& mix) noexcept :
|
|
||||||
m_decode(), m_mix(mix){}
|
|
||||||
|
|
||||||
constexpr TransformStage(const Decode& decode, const Mix& mix) noexcept :
|
|
||||||
m_decode(decode), m_mix(mix){}
|
|
||||||
|
|
||||||
constexpr const Decode& decode() const noexcept{
|
|
||||||
return m_decode;
|
|
||||||
}
|
|
||||||
|
|
||||||
Decode& decode() noexcept{
|
|
||||||
return m_decode;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr const Mix& mix() const noexcept{
|
|
||||||
return m_mix;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mix& mix() noexcept{
|
|
||||||
return m_mix;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Decode m_decode;
|
|
||||||
Mix m_mix;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Unsupported {
|
|
||||||
|
|
||||||
// TODO CieColor
|
|
||||||
/// Cie color
|
|
||||||
/// Currently stub, more info required.
|
|
||||||
struct CieColor {
|
|
||||||
UInt16 m_colorSpace;
|
|
||||||
Bool m_lowEndian;
|
|
||||||
Bool m_deviceDependent;
|
|
||||||
Int32 m_versionNumber;
|
|
||||||
TransformStage m_stageAbc;
|
|
||||||
TransformStage m_stageLmn;
|
|
||||||
CiePoint m_whitePoint;
|
|
||||||
CiePoint m_blackPoint;
|
|
||||||
CiePoint m_whitePaper;
|
|
||||||
CiePoint m_blackInk;
|
|
||||||
Fix32 m_samples[1]; // <- how many elements? how to use?
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_CIE_HPP
|
|
||||||
|
|
|
@ -1,116 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_CURVERESPONSE_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_CURVERESPONSE_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
/// Base response class.
|
|
||||||
class CurveResponse {
|
|
||||||
|
|
||||||
public:
|
|
||||||
CurveResponse() noexcept{}
|
|
||||||
|
|
||||||
/// Creates a new (Rgb|Gray)Response with default elements, make sure that info.bitsPerPixel() is <= 8.
|
|
||||||
/// \throw RangeException When info.bitsPerPixel() is negative or greater than 8.
|
|
||||||
explicit CurveResponse(const ImageInfo& info) : CurveResponse(info.bitsPerPixel()){}
|
|
||||||
|
|
||||||
/// Creates a new (Rgb|Gray)Response with default elements, make sure that bitsPerPixel is <= 8.
|
|
||||||
/// \throw RangeException When bitsPerPixel is negative or greater than 8.
|
|
||||||
explicit CurveResponse(Int16 bitsPerPixel){
|
|
||||||
if (bitsPerPixel <= 0 || bitsPerPixel > 8){
|
|
||||||
throw RangeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt16 size = 1 << static_cast<UInt16>(bitsPerPixel);
|
|
||||||
m_data.reset(new Element8[size]);
|
|
||||||
for (UInt16 i = 0; i < size; i++){
|
|
||||||
m_data[i] = Element8(static_cast<UInt8>(i)); // 0..255 max
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Array of size `2^ImageInfo.bitesPerPixel()`, up to 256 elements (2^8)
|
|
||||||
Element8* data() noexcept{
|
|
||||||
return m_data.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Array of size `2^ImageInfo.bitesPerPixel()`, up to 256 elements (2^8)
|
|
||||||
const Element8* data() const noexcept{
|
|
||||||
return m_data.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<Element8[]> m_data;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Rgb response class.
|
|
||||||
class RgbResponse : public Detail::CurveResponse {
|
|
||||||
|
|
||||||
public:
|
|
||||||
RgbResponse() noexcept{}
|
|
||||||
|
|
||||||
/// Creates a new RgbResponse with default elements, make sure that info.bitesPerPixel() is <= 8.
|
|
||||||
/// \throw RangeException When info.bitsPerPixel() is negative or greater than 8.
|
|
||||||
explicit RgbResponse(const ImageInfo& info) :
|
|
||||||
Detail::CurveResponse(info) {}
|
|
||||||
|
|
||||||
/// Creates a new RgbResponse with default elements, make sure that bitsPerPixel is <= 8.
|
|
||||||
/// \throw RangeException When bitsPerPixel is negative or greater than 8.
|
|
||||||
explicit RgbResponse(Int16 bitsPerPixel) :
|
|
||||||
Detail::CurveResponse(bitsPerPixel) {}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Gray response class.
|
|
||||||
class GrayResponse : public Detail::CurveResponse {
|
|
||||||
|
|
||||||
public:
|
|
||||||
GrayResponse() noexcept{}
|
|
||||||
|
|
||||||
/// Creates a new GrayResponse with default elements, make sure that info.bitesPerPixel() is <= 8.
|
|
||||||
/// \throw RangeException When info.bitsPerPixel() is negative or greater than 8.
|
|
||||||
explicit GrayResponse(const ImageInfo& info) :
|
|
||||||
Detail::CurveResponse(info) {}
|
|
||||||
|
|
||||||
/// Creates a new GrayResponse with default elements, make sure that bitsPerPixel is <= 8.
|
|
||||||
/// \throw RangeException When bitsPerPixel is negative or greater than 8.
|
|
||||||
explicit GrayResponse(Int16 bitsPerPixel) :
|
|
||||||
Detail::CurveResponse(bitsPerPixel) {}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_CURVERESPONSE_HPP
|
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_CUSTOMDATA_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_CUSTOMDATA_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Structure for sending custom data to source or application.
|
|
||||||
class CustomData {
|
|
||||||
|
|
||||||
public:
|
|
||||||
template <typename T>
|
|
||||||
using Data = typename Detail::Lock<T>;
|
|
||||||
|
|
||||||
/// Creates empty custom data.
|
|
||||||
CustomData() noexcept :
|
|
||||||
m_size(0), m_handle(){}
|
|
||||||
|
|
||||||
/// Creates custom data with allocated memory.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
explicit CustomData(UInt32 size) :
|
|
||||||
m_size(size), m_handle(Detail::alloc(size)){}
|
|
||||||
|
|
||||||
/// Locks and returns pointer to custom data memory.
|
|
||||||
template<typename T = void>
|
|
||||||
Data<T> lock() const noexcept{
|
|
||||||
return Data<T>(m_handle.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The size of contained memory block.
|
|
||||||
UInt32 size() const noexcept{
|
|
||||||
return m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
UInt32 m_size;
|
|
||||||
Detail::UniqueHandle m_handle;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_CUSTOMDATA_HPP
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,251 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_DEVICEEVENT_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_DEVICEEVENT_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Information about event sent by source.
|
|
||||||
class DeviceEvent {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Event type.
|
|
||||||
enum class Type : UInt16 { // Capability->UInt16, DeviceEvent->UInt32
|
|
||||||
CheckAutomaticCapture = 0,
|
|
||||||
CheckBattery = 1,
|
|
||||||
CheckDeviceOnline = 2,
|
|
||||||
CheckFlash = 3,
|
|
||||||
CheckPowerSupply = 4,
|
|
||||||
CheckResolution = 5,
|
|
||||||
DeviceAdded = 6,
|
|
||||||
DeviceOffline = 7,
|
|
||||||
DeviceReady = 8,
|
|
||||||
DeviceRemoved = 9,
|
|
||||||
ImageCaptured = 10,
|
|
||||||
ImageDeleted = 11,
|
|
||||||
PaperDoubleFeed = 12,
|
|
||||||
PaperJam = 13,
|
|
||||||
LampFailure = 14,
|
|
||||||
PowerSave = 15,
|
|
||||||
PowerSaveNotify = 16,
|
|
||||||
CustomEvents = 0x8000
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Creates event with only type and device name set.
|
|
||||||
static constexpr DeviceEvent simple(Type type, const Str255& deviceName) noexcept;
|
|
||||||
|
|
||||||
/// Creates event for checking battery.
|
|
||||||
static constexpr DeviceEvent checkBattery(
|
|
||||||
const Str255& deviceName,
|
|
||||||
UInt32 batteryMinutes,
|
|
||||||
Int16 batteryPercentage
|
|
||||||
) noexcept;
|
|
||||||
|
|
||||||
/// Creates event for checking power supply.
|
|
||||||
static constexpr DeviceEvent checkPowerSupply(
|
|
||||||
const Str255& deviceName,
|
|
||||||
PowerSupply powerSupply
|
|
||||||
) noexcept;
|
|
||||||
|
|
||||||
/// Creates event for checking resolution.
|
|
||||||
static constexpr DeviceEvent checkResolution(
|
|
||||||
const Str255& deviceName,
|
|
||||||
Fix32 xres,
|
|
||||||
Fix32 yres
|
|
||||||
) noexcept;
|
|
||||||
|
|
||||||
/// Creates event for checking flash settings.
|
|
||||||
static constexpr DeviceEvent checkFlash(
|
|
||||||
const Str255& deviceName,
|
|
||||||
Flash flash
|
|
||||||
) noexcept;
|
|
||||||
|
|
||||||
/// Creates event for checking number of images camera is going to capture.
|
|
||||||
static constexpr DeviceEvent checkAutomaticCapture(
|
|
||||||
const Str255& deviceName,
|
|
||||||
UInt32 autoCapture,
|
|
||||||
UInt32 timeBeforeFirstCapture,
|
|
||||||
UInt32 timeBetweenCaptures
|
|
||||||
) noexcept;
|
|
||||||
|
|
||||||
/// Creates uninitialized deice event.
|
|
||||||
constexpr DeviceEvent() noexcept :
|
|
||||||
m_type(static_cast<UInt32>(Type::CheckAutomaticCapture)), m_batteryMinutes(0),
|
|
||||||
m_batteryPercent(0), m_powerSupply(static_cast<Int32>(PowerSupply::External)),
|
|
||||||
m_flashUsed(static_cast<UInt32>(Flash::None)), m_autoCapture(0),
|
|
||||||
m_timeBeforeFirstCapture(0), m_timeBetweenCaptures(0){}
|
|
||||||
|
|
||||||
/// Event type.
|
|
||||||
constexpr Type type() const noexcept{
|
|
||||||
return static_cast<Type>(m_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Name of the device that sent the event.
|
|
||||||
constexpr const Str255& deviceName() const noexcept{
|
|
||||||
return m_deviceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Minutes of battery power remaining.
|
|
||||||
/// Valid only for Type::CheckBattery.
|
|
||||||
constexpr UInt32 batteryMinutes() const noexcept{
|
|
||||||
return m_batteryMinutes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Percentage of battery power remaining.
|
|
||||||
/// Valid only for Type::CheckBattery.
|
|
||||||
constexpr Int16 batteryPercentage() const noexcept{
|
|
||||||
return m_batteryPercent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Power supply in use.
|
|
||||||
/// Valid only for Type::CheckPowerSupply.
|
|
||||||
constexpr PowerSupply powerSupply() const noexcept{
|
|
||||||
return static_cast<PowerSupply>(m_powerSupply);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// X resolution.
|
|
||||||
/// Valif only for Type::CheckResolution.
|
|
||||||
constexpr Fix32 xResolution() const noexcept{
|
|
||||||
return m_xres;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Y resolution.
|
|
||||||
/// Valid only for Type::CheckResolution.
|
|
||||||
constexpr Fix32 yResolution() const noexcept{
|
|
||||||
return m_yres;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Flash settings.
|
|
||||||
/// Valid only for Type::CheckFlash.
|
|
||||||
constexpr Flash flash() const noexcept{
|
|
||||||
return static_cast<Flash>(m_flashUsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of images camera will capture.
|
|
||||||
/// Valid only for Type::CheckAutomaticCapture.
|
|
||||||
constexpr UInt32 automaticCapture() const noexcept{
|
|
||||||
return m_autoCapture;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of seconds before first capture.
|
|
||||||
/// Valid only for Type::CheckAutomaticCapture.
|
|
||||||
constexpr UInt32 timeBeforeFirstCapture() const noexcept{
|
|
||||||
return m_timeBeforeFirstCapture;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of 1/100-seconds between captures.
|
|
||||||
/// Valid only for Type::CheckAutomaticCapture.
|
|
||||||
constexpr UInt32 timeBetweenCaptures() const noexcept{
|
|
||||||
return m_timeBetweenCaptures;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
constexpr DeviceEvent(
|
|
||||||
Type type,
|
|
||||||
const Str255& deviceName,
|
|
||||||
UInt32 batteryMinutes,
|
|
||||||
Int16 batteryPercentage,
|
|
||||||
PowerSupply powerSupply,
|
|
||||||
Fix32 xres,
|
|
||||||
Fix32 yres,
|
|
||||||
Flash flash,
|
|
||||||
UInt32 autoCapture,
|
|
||||||
UInt32 tbfc,
|
|
||||||
UInt32 tbc
|
|
||||||
) noexcept :
|
|
||||||
m_type(static_cast<UInt32>(type)), m_deviceName(deviceName),
|
|
||||||
m_batteryMinutes(batteryMinutes), m_batteryPercent(batteryPercentage),
|
|
||||||
m_powerSupply(static_cast<Int32>(powerSupply)), m_xres(xres), m_yres(yres),
|
|
||||||
m_flashUsed(static_cast<UInt32>(flash)), m_autoCapture(autoCapture),
|
|
||||||
m_timeBeforeFirstCapture(tbfc), m_timeBetweenCaptures(tbc){}
|
|
||||||
|
|
||||||
UInt32 m_type;
|
|
||||||
Str255 m_deviceName;
|
|
||||||
UInt32 m_batteryMinutes;
|
|
||||||
Int16 m_batteryPercent;
|
|
||||||
Int32 m_powerSupply;
|
|
||||||
Fix32 m_xres;
|
|
||||||
Fix32 m_yres;
|
|
||||||
UInt32 m_flashUsed;
|
|
||||||
UInt32 m_autoCapture;
|
|
||||||
UInt32 m_timeBeforeFirstCapture;
|
|
||||||
UInt32 m_timeBetweenCaptures;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
// must be defined outside the class because of msvc2015
|
|
||||||
constexpr inline DeviceEvent DeviceEvent::simple(Type type, const Str255& deviceName) noexcept{
|
|
||||||
return DeviceEvent(type, deviceName, 0, 0, PowerSupply::External, Fix32(), Fix32(), Flash::None, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr inline DeviceEvent DeviceEvent::checkBattery(
|
|
||||||
const Str255& deviceName,
|
|
||||||
UInt32 batteryMinutes,
|
|
||||||
Int16 batteryPercentage
|
|
||||||
) noexcept{
|
|
||||||
return DeviceEvent(Type::CheckBattery, deviceName, batteryMinutes, batteryPercentage, PowerSupply::External, Fix32(), Fix32(), Flash::None, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr inline DeviceEvent DeviceEvent::checkPowerSupply(
|
|
||||||
const Str255& deviceName,
|
|
||||||
PowerSupply powerSupply
|
|
||||||
) noexcept{
|
|
||||||
return DeviceEvent(Type::CheckPowerSupply, deviceName, 0, 0, powerSupply, Fix32(), Fix32(), Flash::None, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr inline DeviceEvent DeviceEvent::checkResolution(
|
|
||||||
const Str255& deviceName,
|
|
||||||
Fix32 xres,
|
|
||||||
Fix32 yres
|
|
||||||
) noexcept{
|
|
||||||
return DeviceEvent(Type::CheckResolution, deviceName, 0, 0, PowerSupply::External, xres, yres, Flash::None, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr inline DeviceEvent DeviceEvent::checkFlash(
|
|
||||||
const Str255& deviceName,
|
|
||||||
Flash flash
|
|
||||||
) noexcept{
|
|
||||||
return DeviceEvent(Type::CheckFlash, deviceName, 0, 0, PowerSupply::External, Fix32(), Fix32(), flash, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr inline DeviceEvent DeviceEvent::checkAutomaticCapture(
|
|
||||||
const Str255& deviceName,
|
|
||||||
UInt32 autoCapture,
|
|
||||||
UInt32 timeBeforeFirstCapture,
|
|
||||||
UInt32 timeBetweenCaptures
|
|
||||||
) noexcept{
|
|
||||||
return DeviceEvent(Type::CheckAutomaticCapture, deviceName, 0, 0, PowerSupply::External,
|
|
||||||
Fix32(), Fix32(), Flash::None, autoCapture, timeBeforeFirstCapture, timeBetweenCaptures);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_DEVICEEVENT_HPP
|
|
|
@ -1,118 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_ELEMENT8_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_ELEMENT8_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Element in a palette consisting of 3 parts (RGB, CMY, ...)
|
|
||||||
/// in the order of the type alphabetic representation.
|
|
||||||
class Element8 {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates zero-initialized element.
|
|
||||||
constexpr Element8() noexcept :
|
|
||||||
m_index(0), m_channel1(0), m_channel2(0), m_channel3(0){}
|
|
||||||
|
|
||||||
/// Creates zero-initialized element with specified index.
|
|
||||||
explicit constexpr Element8(UInt8 index) noexcept :
|
|
||||||
m_index(index), m_channel1(0), m_channel2(0), m_channel3(0){}
|
|
||||||
|
|
||||||
/// Creates element with set channels.
|
|
||||||
constexpr Element8(
|
|
||||||
UInt8 channel1,
|
|
||||||
UInt8 channel2,
|
|
||||||
UInt8 channel3
|
|
||||||
) noexcept :
|
|
||||||
m_index(0), m_channel1(channel1), m_channel2(channel2),
|
|
||||||
m_channel3(channel3){}
|
|
||||||
|
|
||||||
/// Creates element with set channels at index.
|
|
||||||
constexpr Element8(
|
|
||||||
UInt8 index,
|
|
||||||
UInt8 channel1,
|
|
||||||
UInt8 channel2,
|
|
||||||
UInt8 channel3
|
|
||||||
) noexcept :
|
|
||||||
m_index(index), m_channel1(channel1), m_channel2(channel2),
|
|
||||||
m_channel3(channel3){}
|
|
||||||
|
|
||||||
/// Index of the element in palette.
|
|
||||||
constexpr UInt8 index() const noexcept{
|
|
||||||
return m_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets index of the element in palette.
|
|
||||||
void setIndex(UInt8 index) noexcept{
|
|
||||||
m_index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Channel 1 information.
|
|
||||||
constexpr UInt8 channel1() const noexcept{
|
|
||||||
return m_channel1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets channel 1 information.
|
|
||||||
void setChannel1(UInt8 channel1) noexcept{
|
|
||||||
m_channel1 = channel1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Channel 2 information.
|
|
||||||
constexpr UInt8 channel2() const noexcept{
|
|
||||||
return m_channel2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets channel 2 information.
|
|
||||||
void setChannel2(UInt8 channel2) noexcept{
|
|
||||||
m_channel2 = channel2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Channel 3 information.
|
|
||||||
constexpr UInt8 channel3() const noexcept{
|
|
||||||
return m_channel3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets channel 3 information.
|
|
||||||
void setChannel3(UInt8 channel3) noexcept{
|
|
||||||
m_channel3 = channel3;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
UInt8 m_index;
|
|
||||||
UInt8 m_channel1;
|
|
||||||
UInt8 m_channel2;
|
|
||||||
UInt8 m_channel3;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_ELEMENT8_HPP
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,356 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015-2017 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_ENV_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_ENV_HPP
|
|
||||||
|
|
||||||
// =============
|
|
||||||
// Twpp specific
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
enum {
|
|
||||||
ProtoMajor = 2,
|
|
||||||
ProtoMinor = 3,
|
|
||||||
Dsm2 = 0x10000000L,
|
|
||||||
App2 = 0x20000000L,
|
|
||||||
Ds2 = 0x40000000L
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(TWPP_IS_DS)
|
|
||||||
# define TWPP_DETAIL_IS_DS 1
|
|
||||||
#else
|
|
||||||
# define TWPP_DETAIL_IS_DS 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// ===========
|
|
||||||
// OS specific
|
|
||||||
|
|
||||||
// Windows
|
|
||||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
|
||||||
# define TWPP_DETAIL_OS_WIN 1
|
|
||||||
# if defined(WIN64) || defined(_WIN64)
|
|
||||||
# define TWPP_DETAIL_OS_WIN64 1
|
|
||||||
# else
|
|
||||||
# define TWPP_DETAIL_OS_WIN32 1
|
|
||||||
# endif
|
|
||||||
# if !defined(WIN32_LEAN_AND_MEAN)
|
|
||||||
# define WIN32_LEAN_AND_MEAN
|
|
||||||
# endif
|
|
||||||
# if !defined(NOMINMAX)
|
|
||||||
# define NOMINMAX
|
|
||||||
# endif
|
|
||||||
extern "C" {
|
|
||||||
# include <windows.h>
|
|
||||||
}
|
|
||||||
# define TWPP_DETAIL_CALLSTYLE PASCAL
|
|
||||||
# define TWPP_DETAIL_EXPORT __declspec(dllexport)
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
typedef HANDLE RawHandle;
|
|
||||||
|
|
||||||
|
|
||||||
namespace DsmLibOs {
|
|
||||||
|
|
||||||
typedef HMODULE Handle;
|
|
||||||
static constexpr const Handle nullHandle = nullptr;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static inline T resolve(Handle h) noexcept{
|
|
||||||
return reinterpret_cast<T>(::GetProcAddress(h, "DSM_Entry"));
|
|
||||||
}
|
|
||||||
|
|
||||||
# if defined(TWPP_DETAIL_OS_WIN32)
|
|
||||||
static inline Handle load(bool old) noexcept{
|
|
||||||
if (old){
|
|
||||||
auto h = ::LoadLibraryA("TWAIN_32.dll");
|
|
||||||
if (!h){
|
|
||||||
h = ::LoadLibraryA("TWAINDSM.dll");
|
|
||||||
}
|
|
||||||
|
|
||||||
return h;
|
|
||||||
} else {
|
|
||||||
auto h = ::LoadLibraryA("TWAINDSM.dll");
|
|
||||||
if (!h){
|
|
||||||
h = ::LoadLibraryA("TWAIN_32.dll");
|
|
||||||
}
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
# else
|
|
||||||
static inline Handle load(bool) noexcept{
|
|
||||||
return ::LoadLibraryA("TWAINDSM.dll");
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
static inline void unload(Handle h) noexcept{
|
|
||||||
::FreeLibrary(h);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace DsmLibOs
|
|
||||||
|
|
||||||
} // namespace Detail
|
|
||||||
|
|
||||||
} // namespace Twpp
|
|
||||||
|
|
||||||
|
|
||||||
// Mac OS
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
# pragma message "No testing has been done on this platform, this framework might not work correctly."
|
|
||||||
# define TWPP_DETAIL_OS_MAC 1
|
|
||||||
# include <limits>
|
|
||||||
extern "C" {
|
|
||||||
# include <objc/objc.h>
|
|
||||||
# include <objc/objc-runtime.h>
|
|
||||||
# include <objc/NSObjCRuntime.h>
|
|
||||||
# include <CoreServices/CoreServices.h>
|
|
||||||
# include <dlfcn.h>
|
|
||||||
}
|
|
||||||
# define TWPP_DETAIL_CALLSTYLE pascal
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
typedef Handle RawHandle;
|
|
||||||
|
|
||||||
|
|
||||||
namespace DsmLibOs {
|
|
||||||
|
|
||||||
typedef void* Handle;
|
|
||||||
static constexpr const Handle nullHandle = nullptr;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static inline T resolve(Handle h) noexcept{
|
|
||||||
return reinterpret_cast<T>(::dlsym(h, "DSM_Entry"));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Handle load(bool) noexcept{
|
|
||||||
return ::dlopen("/System/Library/Frameworks/TWAIN.framework/TWAIN", RTLD_LAZY);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void unload(Handle h) noexcept{
|
|
||||||
::dlclose(h);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace DsmLibOs
|
|
||||||
|
|
||||||
template<typename>
|
|
||||||
struct MacStatic {
|
|
||||||
|
|
||||||
static const ::Class g_autoreleasePool;
|
|
||||||
static const ::SEL g_release;
|
|
||||||
static const ::SEL g_alloc;
|
|
||||||
static const ::SEL g_init;
|
|
||||||
|
|
||||||
static const ::SEL g_nextEvent;
|
|
||||||
static const ::SEL g_postEvent;
|
|
||||||
static const ::SEL g_sendEvent;
|
|
||||||
static const ::id g_app;
|
|
||||||
static const ::id g_distantFuture;
|
|
||||||
|
|
||||||
static const ::Class g_event;
|
|
||||||
static const ::SEL g_otherEventWithType;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Dummy> const ::Class MacStatic<Dummy>::g_autoreleasePool = objc_getClass("NSAutoreleasePool");
|
|
||||||
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_release = sel_registerName("release");
|
|
||||||
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_alloc = sel_registerName("alloc");
|
|
||||||
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_init = sel_registerName("init");
|
|
||||||
|
|
||||||
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_nextEvent = sel_registerName("nextEventMatchingMask:untilDate:inMode:dequeue:");
|
|
||||||
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_postEvent = sel_registerName("postEvent:atStart:");
|
|
||||||
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_sendEvent = sel_registerName("sendEvent:");
|
|
||||||
template<typename Dummy> const ::id MacStatic<Dummy>::g_app = objc_msgSend(reinterpret_cast<::id>(objc_getClass("NSApplication")), sel_registerName("sharedApplication"));
|
|
||||||
template<typename Dummy> const ::id MacStatic<Dummy>::g_distantFuture = objc_msgSend(reinterpret_cast<::id>(objc_getClass("NSDate")), sel_registerName("distantFuture"));
|
|
||||||
|
|
||||||
template<typename Dummy> const ::Class MacStatic<Dummy>::g_event = objc_getClass("NSEvent");
|
|
||||||
template<typename Dummy> const ::SEL MacStatic<Dummy>::g_otherEventWithType = sel_registerName("otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:");
|
|
||||||
|
|
||||||
class NSAutoreleasePool {
|
|
||||||
|
|
||||||
public:
|
|
||||||
NSAutoreleasePool() noexcept :
|
|
||||||
m_id(createPool()) {}
|
|
||||||
|
|
||||||
~NSAutoreleasePool(){
|
|
||||||
release();
|
|
||||||
}
|
|
||||||
|
|
||||||
NSAutoreleasePool(const NSAutoreleasePool&) = delete;
|
|
||||||
NSAutoreleasePool& operator=(const NSAutoreleasePool&) = delete;
|
|
||||||
|
|
||||||
NSAutoreleasePool(NSAutoreleasePool&& o) noexcept :
|
|
||||||
m_id(o.m_id){
|
|
||||||
|
|
||||||
o.m_id = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSAutoreleasePool& operator=(NSAutoreleasePool&& o) noexcept{
|
|
||||||
if (this != &o){
|
|
||||||
release();
|
|
||||||
std::swap(m_id, o.m_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void release() noexcept{
|
|
||||||
if (m_id != nullptr){
|
|
||||||
objc_msgSend(m_id, MacStatic<void>::g_release);
|
|
||||||
m_id = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static ::id createPool() noexcept{
|
|
||||||
auto poolId = objc_msgSend(reinterpret_cast<::id>(MacStatic<void>::g_autoreleasePool), MacStatic<void>::g_alloc);
|
|
||||||
return objc_msgSend(poolId, MacStatic<void>::g_init);
|
|
||||||
}
|
|
||||||
|
|
||||||
::id m_id;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace NSLoop {
|
|
||||||
|
|
||||||
static constexpr ::NSUInteger NSAnyEventMask = std::numeric_limits<::NSUInteger>::max();
|
|
||||||
static constexpr ::NSUInteger NSApplicationDefined = 15;
|
|
||||||
|
|
||||||
static void processEvent() noexcept{
|
|
||||||
auto event = objc_msgSend(MacStatic<void>::g_app, MacStatic<void>::g_nextEvent, NSAnyEventMask, MacStatic<void>::g_distantFuture, kCFRunLoopDefaultMode, YES);
|
|
||||||
objc_msgSend(MacStatic<void>::g_app, MacStatic<void>::g_sendEvent, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void postDummy() noexcept{
|
|
||||||
auto event = objc_msgSend(reinterpret_cast<::id>(MacStatic<void>::g_event), MacStatic<void>::g_otherEventWithType, NSApplicationDefined, nullptr, 1, 0.0, 0, nullptr, static_cast<short>(0), 0, 0);
|
|
||||||
objc_msgSend(MacStatic<void>::g_app, MacStatic<void>::g_postEvent, event, NO);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace NSLoop
|
|
||||||
|
|
||||||
} // namespace Detail
|
|
||||||
|
|
||||||
} // namespace Twpp
|
|
||||||
|
|
||||||
// Linux
|
|
||||||
#elif defined(__linux__)
|
|
||||||
# warning "No testing has been done on this platform, this framework might not work correctly."
|
|
||||||
# define TWPP_DETAIL_OS_LINUX 1
|
|
||||||
extern "C" {
|
|
||||||
# include <dlfcn.h>
|
|
||||||
}
|
|
||||||
# define TWPP_DETAIL_CALLSTYLE
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
typedef void* RawHandle;
|
|
||||||
|
|
||||||
|
|
||||||
namespace DsmLibOs {
|
|
||||||
|
|
||||||
typedef void* Handle;
|
|
||||||
static constexpr const Handle nullHandle = nullptr;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static inline T resolve(Handle h) noexcept{
|
|
||||||
return reinterpret_cast<T>(::dlsym(h, "DSM_Entry"));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Handle load(bool) noexcept{
|
|
||||||
return ::dlopen("libtwaindsm.so", RTLD_LAZY);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void unload(Handle h) noexcept{
|
|
||||||
::dlclose(h);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace DsmLibOs
|
|
||||||
|
|
||||||
} // namespace Detail
|
|
||||||
|
|
||||||
} // namespace Twpp
|
|
||||||
|
|
||||||
// fail everything else
|
|
||||||
#else
|
|
||||||
# error "unsupported platform, supports only Windows, Mac OS and Linux"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// =================
|
|
||||||
// compiler specific
|
|
||||||
|
|
||||||
// MSVC
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
# define TWPP_DETAIL_PACK_BEGIN \
|
|
||||||
__pragma(pack (push, beforeTwpp)) \
|
|
||||||
__pragma(pack (2))
|
|
||||||
# define TWPP_DETAIL_PACK_END __pragma(pack (pop, beforeTwpp));
|
|
||||||
|
|
||||||
// GNU or CLang
|
|
||||||
#elif defined(__GNUC__) || defined(__clang__)
|
|
||||||
# if defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
# define TWPP_DETAIL_PACK_BEGIN _Pragma("options align = power")
|
|
||||||
# define TWPP_DETAIL_PACK_END _Pragma("options align = reset")
|
|
||||||
# else
|
|
||||||
# define TWPP_DETAIL_PACK_BEGIN \
|
|
||||||
_Pragma("pack (push, beforeTwpp)") \
|
|
||||||
_Pragma("pack (2)")
|
|
||||||
# define TWPP_DETAIL_PACK_END _Pragma("pack (pop, beforeTwpp)")
|
|
||||||
# endif
|
|
||||||
# if !defined(TWPP_DETAIL_EXPORT)
|
|
||||||
# define TWPP_DETAIL_EXPORT __attribute__((__visibility__("default")))
|
|
||||||
# endif
|
|
||||||
|
|
||||||
// Borland
|
|
||||||
#elif defined(__BORLAND__) || defined(__BORLANDC__) || defined(__CODEGEARC__)
|
|
||||||
# define TWPP_DETAIL_PACK_BEGIN _Pragma("option -a2")
|
|
||||||
# define TWPP_DETAIL_PACK_END _Pragma("option -a")
|
|
||||||
|
|
||||||
// fail everything else
|
|
||||||
#else
|
|
||||||
# error "unsupported compiler, please define your own TWPP_DETAIL_PACK_BEGIN and TWPP_DETAIL_PACK_END and possibly TWPP_DETAIL_EXPORT in twpp/env.hpp and send me your patch"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1900) // msvc2015
|
|
||||||
# error "C++11 or later is required"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_ENV_HPP
|
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_EVENT_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_EVENT_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Loop event on Windows.
|
|
||||||
/// Used while waiting for transfer.
|
|
||||||
/// See manual for more info.
|
|
||||||
class Event {
|
|
||||||
|
|
||||||
public:
|
|
||||||
constexpr Event() noexcept :
|
|
||||||
m_event(nullptr), m_msg(Msg::Null){}
|
|
||||||
|
|
||||||
constexpr Event(void* event, Msg msg) noexcept :
|
|
||||||
m_event(event), m_msg(msg){}
|
|
||||||
|
|
||||||
constexpr void* event() const noexcept{
|
|
||||||
return m_event;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setEvent(void* event) noexcept{
|
|
||||||
m_event = event;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr Msg message() const noexcept{
|
|
||||||
return m_msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMessage(Msg msg) noexcept{
|
|
||||||
m_msg = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void* m_event;
|
|
||||||
Msg m_msg;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_EVENT_HPP
|
|
|
@ -1,42 +0,0 @@
|
||||||
#ifndef TWPP_DETAIL_FILE_EXCEPTION_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_EXCEPTION_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
/// Base class of TWPP exceptions.
|
|
||||||
class Exception : public std::exception {
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual const char* what() const noexcept override{
|
|
||||||
return "General TWPP error.";
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Invalid type exception.
|
|
||||||
/// Used when an invalid or unsupported type identifier is used.
|
|
||||||
class TypeException : public Exception {
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual const char* what() const noexcept override{
|
|
||||||
return "Invalid type.";
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Value out of valid range exception.
|
|
||||||
class RangeException : Exception {
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual const char* what() const noexcept override{
|
|
||||||
return "Value out of allowed range.";
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_EXCEPTION_HPP
|
|
||||||
|
|
|
@ -1,547 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_EXTIMAGEINFO_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_EXTIMAGEINFO_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
/// Mapping of info type to type identifier and data type.
|
|
||||||
template<InfoId id> struct Ext {};
|
|
||||||
template<> struct Ext<InfoId::BarCodeCount> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::BarCodeConfidence> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::BarCodeRotation> {static constexpr const Type twty = Type::UInt32; typedef BarCodeRotation DataType;};
|
|
||||||
template<> struct Ext<InfoId::BarCodeTextLength> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::BarCodeText> {static constexpr const Type twty = Type::Handle; typedef char DataType;};
|
|
||||||
template<> struct Ext<InfoId::BarCodeX> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::BarCodeY> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::BarCodeType> {static constexpr const Type twty = Type::UInt32; typedef BarCodeType DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::DeShadeCount> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeTop> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeLeft> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeHeight> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeWidth> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeSize> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeBlackCountOld> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeBlackCountNew> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeBlackRlMin> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeBlackRlMax> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeWhiteCountOld> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeWhiteCountNew> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeWhiteRlMin> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadeWhiteRlMax> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DeShadEWhiteRlAve> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::SpecklesRemoved> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::BlackSpecklesRemoved> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::WhiteSpecklesRemoved> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::HorzLineCount> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::HorzLineXCoord> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::HorzLineYCoord> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::HorzLineLength> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::HorzLineThickness> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::VertLineCount> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::VertLineXCoord> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::VertLineYCoord> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::VertLineLength> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::VertLineThickness> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::PatchCode> {static constexpr const Type twty = Type::UInt32; typedef PatchCode DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::DeskewStatus> {static constexpr const Type twty = Type::UInt32; typedef DeskewStatus DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewOriginalAngle> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewFinalAngle> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewConfidence> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewWindowX1> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewWindowY1> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewWindowX2> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewWindowY2> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewWindowX3> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewWindowY3> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewWindowX4> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::SkewWindowY4> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::EndorsedText> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::FormConfidence> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::FormTemplateMatch> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
|
|
||||||
template<> struct Ext<InfoId::FormTemplatePageMatch> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::FormHorzDocOffset> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::FormVertDocOffset> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::BookName> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
|
|
||||||
template<> struct Ext<InfoId::ChapterNumber> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::DocumentNumber> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::PageNumber> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::Camera> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
|
|
||||||
template<> struct Ext<InfoId::FrameNumber> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::Frame> {static constexpr const Type twty = Type::Frame; typedef Frame DataType;};
|
|
||||||
template<> struct Ext<InfoId::PixelFlavor> {static constexpr const Type twty = Type::UInt16; typedef PixelFlavor DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::IccProfile> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
|
|
||||||
template<> struct Ext<InfoId::LastSegment> {static constexpr const Type twty = Type::Bool; typedef Bool DataType;};
|
|
||||||
template<> struct Ext<InfoId::SegmentNumber> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::MagType> {static constexpr const Type twty = Type::UInt16; typedef MagType DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::FileSystemSource> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
|
|
||||||
template<> struct Ext<InfoId::ImageMerged> {static constexpr const Type twty = Type::Bool; typedef Bool DataType;};
|
|
||||||
template<> struct Ext<InfoId::MagData> {static constexpr const Type twty = Type::Str255; typedef char DataType;}; // NOTE: InfoId::MagData may also contain Handle
|
|
||||||
template<> struct Ext<InfoId::MagDataLength> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
template<> struct Ext<InfoId::PageSide> {static constexpr const Type twty = Type::UInt16; typedef PageSide DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::PaperCount> {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;};
|
|
||||||
|
|
||||||
template<> struct Ext<InfoId::PrinterText> {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class Info;
|
|
||||||
class ExtImageInfo;
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
static Handle handleItem(Info& info) noexcept;
|
|
||||||
|
|
||||||
static void deleteInfo(Info& info) noexcept;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Extended image information entry.
|
|
||||||
class Info {
|
|
||||||
|
|
||||||
friend class ExtImageInfo;
|
|
||||||
friend Handle Detail::handleItem(Info& info) noexcept;
|
|
||||||
friend void Detail::deleteInfo(Info& info) noexcept;
|
|
||||||
static constexpr const UInt32 DATA_HANDLE_THRESHOLD = sizeof(UIntPtr); // NOTE: specification says 4 bytes, yet pointer size makes more sense
|
|
||||||
|
|
||||||
public:
|
|
||||||
template<typename DataType>
|
|
||||||
class Items {
|
|
||||||
|
|
||||||
friend class Info;
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef Detail::MaybeLock<DataType> Data;
|
|
||||||
|
|
||||||
constexpr Items() noexcept :
|
|
||||||
m_parent(nullptr){}
|
|
||||||
|
|
||||||
Items(const Items&) = default;
|
|
||||||
Items& operator=(const Items&) = default;
|
|
||||||
|
|
||||||
Items(Items&&) = default;
|
|
||||||
Items& operator=(Items&&) = default;
|
|
||||||
|
|
||||||
operator bool() const noexcept{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
Data at(UInt32 i) const{
|
|
||||||
if (m_parent->hasDataHandle() && m_parent->type() == Type::Handle){
|
|
||||||
return reinterpret_cast<Handle*>(m_data.data())[i];
|
|
||||||
} else {
|
|
||||||
return reinterpret_cast<DataType*>(m_data.data() + i * typeSize(m_parent->type()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Data operator[](UInt32 i) const{
|
|
||||||
return at(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Items(Info& parent, Detail::MaybeLock<char> data) noexcept :
|
|
||||||
m_parent(&parent), m_data(data){}
|
|
||||||
|
|
||||||
Info* m_parent;
|
|
||||||
Detail::MaybeLock<char> m_data;
|
|
||||||
// [items] <=> !(big and handle)
|
|
||||||
// [handles]->handles*[items] <=> big and handle (this should teoretically not happen)
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Info(const Info&) = delete;
|
|
||||||
Info& operator=(const Info&) = delete;
|
|
||||||
|
|
||||||
Info(Info&&) = delete;
|
|
||||||
Info& operator=(Info&&) = delete;
|
|
||||||
|
|
||||||
/// Information type ID.
|
|
||||||
InfoId id() const noexcept{
|
|
||||||
return m_infoId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Information data type ID.
|
|
||||||
Type type() const noexcept{
|
|
||||||
return m_itemType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of items in this entry.
|
|
||||||
UInt16 size() const noexcept{
|
|
||||||
return m_numItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates space for the supplied number of items.
|
|
||||||
/// Allocating handles is not supported.
|
|
||||||
/// \tparam id Information type ID. Data types are set accordingly.
|
|
||||||
/// \param count Number of items to allocate.
|
|
||||||
/// \throw TypeException When `type` is handle or invalid.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
template<InfoId id>
|
|
||||||
void allocSimple(UInt16 count = 1){
|
|
||||||
allocSimple(Detail::Ext<id>::twty, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates space for the supplied number of items.
|
|
||||||
/// Allocating handles is not supported.
|
|
||||||
/// \param type Data type ID.
|
|
||||||
/// \param count Number of items to allocate.
|
|
||||||
/// \throw TypeException When `type` is handle or invalid.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
void allocSimple(Type type, UInt16 count = 1){
|
|
||||||
if (type == Type::Handle){
|
|
||||||
throw TypeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == m_itemType && count == m_numItems){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto itemSize = typeSize(type);
|
|
||||||
|
|
||||||
bool big = hasDataHandle(type, count);
|
|
||||||
// [items] <=> !big
|
|
||||||
// handle->[items] <=> big
|
|
||||||
|
|
||||||
Detail::UniqueHandle newItem;
|
|
||||||
if (big){
|
|
||||||
newItem = Detail::alloc(itemSize * count);
|
|
||||||
}
|
|
||||||
|
|
||||||
Detail::deleteInfo(*this);
|
|
||||||
|
|
||||||
if (big){
|
|
||||||
*Detail::alias_cast<Handle*>(&m_item) = newItem.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_itemType = type;
|
|
||||||
m_numItems = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocates a single memory area owned by a handle.
|
|
||||||
/// Info type changes to handle.
|
|
||||||
/// \param itemSize Number of bytes to allocate.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
void allocHandle(UInt32 itemSize){
|
|
||||||
// handle->[chars]
|
|
||||||
auto newItem = Detail::UniqueHandle(Detail::alloc(itemSize));
|
|
||||||
|
|
||||||
Detail::deleteInfo(*this);
|
|
||||||
*Detail::alias_cast<Handle*>(&m_item) = newItem.release();
|
|
||||||
|
|
||||||
m_itemType = Type::Handle;
|
|
||||||
m_numItems = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Status of this entry.
|
|
||||||
ReturnCode returnCode() const noexcept{
|
|
||||||
return m_returnCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets status of this entry.
|
|
||||||
void setReturnCode(ReturnCode rc) noexcept{
|
|
||||||
m_returnCode = rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns items contained in this entry.
|
|
||||||
/// \tparam type ID of the internal data type.
|
|
||||||
/// \tparam DataType Exported data type.
|
|
||||||
/// \throw TypeException When types don't match.
|
|
||||||
template<Type type, typename DataType>
|
|
||||||
Items<DataType> items(){
|
|
||||||
if (type != m_itemType || (type != Type::Handle && typeSize(type) != sizeof(DataType))){
|
|
||||||
throw TypeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemsPriv<DataType>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns items contained in this entry.
|
|
||||||
/// \tparam type ID of the internal data type.
|
|
||||||
/// \throw TypeException When types don't match.
|
|
||||||
template<Type type>
|
|
||||||
Items<typename Detail::Twty<type>::Type> items(){
|
|
||||||
if (type != m_itemType){
|
|
||||||
throw TypeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemsPriv<typename Detail::Twty<type>::Type>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns items contained in this entry.
|
|
||||||
/// \tparam id Information type ID. Data types are set accordingly.
|
|
||||||
/// \throw TypeException When types don't match.
|
|
||||||
template<InfoId id>
|
|
||||||
Items<typename Detail::Ext<id>::DataType> items(){
|
|
||||||
if (Detail::Ext<id>::twty != m_itemType){
|
|
||||||
throw TypeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemsPriv<typename Detail::Ext<id>::DataType>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool hasDataHandle() const{
|
|
||||||
return hasDataHandle(type(), size());
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hasDataHandle(Type type, UInt16 size){
|
|
||||||
return type != Type::DontCare && size * typeSize(type) > DATA_HANDLE_THRESHOLD;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename DataType>
|
|
||||||
Items<DataType> itemsPriv(){
|
|
||||||
bool big = hasDataHandle();
|
|
||||||
bool handle = m_itemType == Type::Handle;
|
|
||||||
|
|
||||||
Detail::MaybeLock<char> lock;
|
|
||||||
if (!big && !handle){
|
|
||||||
lock = Detail::alias_cast<char*>(&m_item);
|
|
||||||
} else {
|
|
||||||
lock = *Detail::alias_cast<Handle*>(&m_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {*this, std::move(lock)};
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, std::size_t len>
|
|
||||||
static bool arrContains(const T(& arr)[len], const T& val) noexcept{
|
|
||||||
for (std::size_t i = 0; i < len; i++){
|
|
||||||
if (arr[i] == val){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
InfoId m_infoId;
|
|
||||||
Type m_itemType;
|
|
||||||
UInt16 m_numItems;
|
|
||||||
ReturnCode m_returnCode;
|
|
||||||
UIntPtr m_item;
|
|
||||||
// [items] <=> !big and !handle
|
|
||||||
// handle->[items] <=> big xor handle
|
|
||||||
// handle->[handles]->handles*[items] <=> big and handle (this should teoretically not happen)
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
static inline Handle handleItem(Info& info) noexcept{
|
|
||||||
return Handle(*Detail::alias_cast<Handle::Raw*>(&info.m_item));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void deleteInfo(Info& info) noexcept{
|
|
||||||
bool big = isType(info.type()) && info.hasDataHandle();
|
|
||||||
bool handle = info.type() == Type::Handle;
|
|
||||||
|
|
||||||
// [items] <=> !big and !handle
|
|
||||||
// handle->[items] <=> big xor handle
|
|
||||||
// handle->[handles]->handles*[items] <=> big and handle (this should teoretically not happen)
|
|
||||||
|
|
||||||
if (big && handle){
|
|
||||||
Detail::Lock<Handle> lock(handleItem(info));
|
|
||||||
for (UInt16 i = 0; i < info.size(); i++){
|
|
||||||
Detail::free(lock.data()[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (big || handle){
|
|
||||||
Detail::free(handleItem(info));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ExtImageInfoData {
|
|
||||||
UInt32 m_numInfos;
|
|
||||||
Info m_infos[1];
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
/// Extended image information.
|
|
||||||
/// Application sends list of info IDs,
|
|
||||||
/// source sets their data.
|
|
||||||
class ExtImageInfo {
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef Info* iterator;
|
|
||||||
typedef const Info* const_iterator;
|
|
||||||
|
|
||||||
/// Creates an invalid object.
|
|
||||||
ExtImageInfo() noexcept {}
|
|
||||||
|
|
||||||
/// Creates a new structure for all supplied info IDs.
|
|
||||||
/// Sources must not call this constructor, they
|
|
||||||
/// are required to fill data in existing instance.
|
|
||||||
/// \param ids List of requested info IDs to be filled in by the source.
|
|
||||||
ExtImageInfo(std::initializer_list<InfoId> ids) :
|
|
||||||
m_data(new char[sizeof(Detail::ExtImageInfoData) - sizeof(Info) + ids.size() * sizeof(Info)]()) {
|
|
||||||
|
|
||||||
d()->m_numInfos = static_cast<UInt32>(ids.size());
|
|
||||||
|
|
||||||
Info* infos = d()->m_infos;
|
|
||||||
|
|
||||||
UInt32 i = 0;
|
|
||||||
for (auto id : ids) {
|
|
||||||
auto& info = infos[i];
|
|
||||||
i++;
|
|
||||||
|
|
||||||
info.m_infoId = id;
|
|
||||||
info.m_itemType = Type::DontCare;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void set_data(const std::list<InfoId>& ids) noexcept {
|
|
||||||
m_data.reset(new char[sizeof(Detail::ExtImageInfoData) - sizeof(Info) + ids.size() * sizeof(Info)]);
|
|
||||||
|
|
||||||
d()->m_numInfos = static_cast<UInt32>(ids.size());
|
|
||||||
|
|
||||||
Info* infos = d()->m_infos;
|
|
||||||
UInt32 i = 0;
|
|
||||||
for (const auto id : ids) {
|
|
||||||
auto& info = infos[i];
|
|
||||||
i++;
|
|
||||||
|
|
||||||
info.m_infoId = id;
|
|
||||||
info.m_itemType = Type::DontCare;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ExtImageInfo(ExtImageInfo&&) = default;
|
|
||||||
ExtImageInfo& operator=(ExtImageInfo&&) = default;
|
|
||||||
|
|
||||||
operator bool() const noexcept{
|
|
||||||
return isValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isValid() const noexcept{
|
|
||||||
return static_cast<bool>(m_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of requested entries.
|
|
||||||
UInt32 size() const noexcept{
|
|
||||||
assert(isValid());
|
|
||||||
return d()->m_numInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Information entry.
|
|
||||||
Info& at(UInt32 i) noexcept{
|
|
||||||
assert(isValid());
|
|
||||||
return d()->m_infos[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Information entry.
|
|
||||||
const Info& at(UInt32 i) const noexcept{
|
|
||||||
assert(isValid());
|
|
||||||
return d()->m_infos[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
Info& operator[](UInt32 i) noexcept{
|
|
||||||
return at(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Info& operator[](UInt32 i) const noexcept{
|
|
||||||
return at(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
iterator begin() noexcept{
|
|
||||||
assert(isValid());
|
|
||||||
return d()->m_infos;
|
|
||||||
}
|
|
||||||
|
|
||||||
const_iterator begin() const noexcept{
|
|
||||||
return cbegin();
|
|
||||||
}
|
|
||||||
|
|
||||||
const_iterator cbegin() const noexcept{
|
|
||||||
assert(isValid());
|
|
||||||
return d()->m_infos;
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator end() noexcept{
|
|
||||||
assert(isValid());
|
|
||||||
return d()->m_infos + d()->m_numInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
const_iterator end() const noexcept{
|
|
||||||
return cend();
|
|
||||||
}
|
|
||||||
|
|
||||||
const_iterator cend() const noexcept{
|
|
||||||
assert(isValid());
|
|
||||||
return d()->m_infos + d()->m_numInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Detail::ExtImageInfoData* d() noexcept{
|
|
||||||
return reinterpret_cast<Detail::ExtImageInfoData*>(m_data.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
Detail::ExtImageInfoData* d() const noexcept{
|
|
||||||
return reinterpret_cast<Detail::ExtImageInfoData*>(m_data.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Deleter {
|
|
||||||
void operator()(char* ptr) noexcept{
|
|
||||||
Detail::ExtImageInfoData* data = reinterpret_cast<Detail::ExtImageInfoData*>(ptr);
|
|
||||||
if (data){
|
|
||||||
for (UInt32 i = 0; i < data->m_numInfos; i++){
|
|
||||||
Detail::deleteInfo(data->m_infos[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete [] ptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unique_ptr<char[], Deleter> m_data;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_EXTIMAGEINFO_HPP
|
|
||||||
|
|
|
@ -1,248 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_FILESYSTEM_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_FILESYSTEM_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Structure representing device filesystem and operations on it.
|
|
||||||
class FileSystem {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Type of file.
|
|
||||||
enum class Type : Int32 {
|
|
||||||
Camera = 0,
|
|
||||||
CameraTop = 1,
|
|
||||||
CameraBottom = 2,
|
|
||||||
CameraPreview = 3,
|
|
||||||
Domain = 4,
|
|
||||||
Host = 5,
|
|
||||||
Directory = 6,
|
|
||||||
Image = 7,
|
|
||||||
Unknown = 8
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Creates uninitialized file system.
|
|
||||||
constexpr FileSystem() noexcept :
|
|
||||||
m_context(nullptr), m_recursiveBool(), m_fileType(Type::Camera), m_size(),
|
|
||||||
m_freeSpace(), m_newImageSize(), m_numberOfFiles(), m_numberOfSnippets(),
|
|
||||||
m_deviceGroupMask(), m_reserved(){}
|
|
||||||
|
|
||||||
/// Creates file system with input and output paths and optional context.
|
|
||||||
constexpr FileSystem(const Str255& inputPath, const Str255& outputPath, void* context = nullptr) noexcept :
|
|
||||||
m_inputPath(inputPath), m_outputPath(outputPath), m_context(context),
|
|
||||||
m_recursiveBool(), m_fileType(Type::Camera), m_size(), m_freeSpace(), m_newImageSize(),
|
|
||||||
m_numberOfFiles(), m_numberOfSnippets(), m_deviceGroupMask(), m_reserved(){}
|
|
||||||
|
|
||||||
/// Input or source file.
|
|
||||||
constexpr const Str255& inputPath() const noexcept{
|
|
||||||
return m_inputPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets input or source file.
|
|
||||||
void setInputPath(const Str255& path) noexcept{
|
|
||||||
m_inputPath = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Operation result, or destination file.
|
|
||||||
constexpr const Str255& outputPath() const noexcept{
|
|
||||||
return m_outputPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets operation result, or destination file.
|
|
||||||
void setOutputPath(const Str255& path) noexcept{
|
|
||||||
m_outputPath = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Source specific context.
|
|
||||||
constexpr void* context() const noexcept{
|
|
||||||
return m_context;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets source specific context.
|
|
||||||
void setContext(void* context) noexcept{
|
|
||||||
m_context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the operation is recursive.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::Delete.
|
|
||||||
constexpr Bool recursive() const noexcept{
|
|
||||||
return m_recursiveBool;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets whether the operation is recursive.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::Delete.
|
|
||||||
void setRecursive(Bool recursive) noexcept{
|
|
||||||
m_recursiveBool = recursive;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// File type.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
constexpr Type type() const noexcept{
|
|
||||||
return m_fileType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets file type.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
void setType(Type type) noexcept{
|
|
||||||
m_fileType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of bytes of the entry.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
constexpr UInt32 size() const noexcept{
|
|
||||||
return m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of bytes of the entry.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
void setSize(UInt32 size) noexcept{
|
|
||||||
m_size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creation date of the file.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
/// YYYY/MM/DD HH:mm:SS:sss
|
|
||||||
constexpr const Str32& createdTimeDate() const noexcept{
|
|
||||||
return m_createdTimeDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets creation date of the file.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
/// YYYY/MM/DD HH:mm:SS:sss
|
|
||||||
void setCreatedTimeDate(const Str32& val) noexcept{
|
|
||||||
m_createdTimeDate = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Modification date of the file.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
/// YYYY/MM/DD HH:mm:SS:sss
|
|
||||||
constexpr const Str32& modifiedTimeDate() const noexcept{
|
|
||||||
return m_modifiedTimeDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets modification date of the file.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
/// YYYY/MM/DD HH:mm:SS:sss
|
|
||||||
void setModifiedTimeDate(const Str32& val) noexcept{
|
|
||||||
m_modifiedTimeDate = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of bytes left on the device.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
constexpr UInt32 freeSpace() const noexcept{
|
|
||||||
return m_freeSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of bytes left on the device.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
void setFreeSpace(UInt32 freeSpace) noexcept{
|
|
||||||
m_freeSpace = freeSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Estimated image size in bytes.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
constexpr Int32 newImageSize() const noexcept{
|
|
||||||
return m_newImageSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets estimated image size in bytes.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
void setNewImageSize(Int32 newImageSize) noexcept{
|
|
||||||
m_newImageSize = newImageSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Total number of files including subdirectories.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
constexpr UInt32 files() const noexcept{
|
|
||||||
return m_numberOfFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets total number of files including subdirectories.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
void setFiles(UInt32 files) noexcept{
|
|
||||||
m_numberOfFiles = files;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of audio snippets.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
constexpr UInt32 snippets() const noexcept{
|
|
||||||
return m_numberOfSnippets;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of audio snippets.
|
|
||||||
/// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext.
|
|
||||||
void snippets(UInt32 snippets) noexcept{
|
|
||||||
m_numberOfSnippets = snippets;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// See manual for explanation of this field, `DeviceGroupMask`.
|
|
||||||
constexpr UInt32 groupMask() const noexcept{
|
|
||||||
return m_deviceGroupMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// See manual for explanation of this field, `DeviceGroupMask`.
|
|
||||||
void groupMask(UInt32 groupMask) noexcept{
|
|
||||||
m_deviceGroupMask = groupMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void unused() const{
|
|
||||||
Detail::unused(m_reserved);
|
|
||||||
}
|
|
||||||
|
|
||||||
Str255 m_inputPath;
|
|
||||||
Str255 m_outputPath;
|
|
||||||
void* m_context;
|
|
||||||
|
|
||||||
// Copy, Delete
|
|
||||||
union {
|
|
||||||
int m_recursive;
|
|
||||||
Bool m_recursiveBool;
|
|
||||||
};
|
|
||||||
|
|
||||||
// GetInfo
|
|
||||||
Type m_fileType;
|
|
||||||
UInt32 m_size;
|
|
||||||
Str32 m_createdTimeDate;
|
|
||||||
Str32 m_modifiedTimeDate;
|
|
||||||
UInt32 m_freeSpace;
|
|
||||||
Int32 m_newImageSize;
|
|
||||||
UInt32 m_numberOfFiles;
|
|
||||||
UInt32 m_numberOfSnippets;
|
|
||||||
UInt32 m_deviceGroupMask;
|
|
||||||
Int8 m_reserved[508];
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_FILESYSTEM_HPP
|
|
|
@ -1,198 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_FIX32_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_FIX32_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
static constexpr inline Int32 floatToValue(float val){
|
|
||||||
return static_cast<Int32>(
|
|
||||||
(val >= 0.0f) ?
|
|
||||||
(val * 65536.0f + 0.5f) :
|
|
||||||
(val * 65536.0f - 0.5f)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr inline Int16 floatToWhole(float val){
|
|
||||||
return static_cast<Int16>(floatToValue(val) >> 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr inline UInt16 floatToFrac(float val){
|
|
||||||
return static_cast<UInt16>(floatToValue(val) & 0xFFFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// TWAIN fixed point fractional type.
|
|
||||||
/// The fractional part has resolution of 1/65536.
|
|
||||||
class Fix32 {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates zero-initialized fixed type.
|
|
||||||
constexpr Fix32() noexcept :
|
|
||||||
m_whole(0), m_frac(0){}
|
|
||||||
|
|
||||||
/// Creates fixed type from float at compile time if possible.
|
|
||||||
constexpr Fix32(float value) noexcept :
|
|
||||||
m_whole(Detail::floatToWhole(value)), m_frac(Detail::floatToFrac(value)){}
|
|
||||||
|
|
||||||
/// Creates fixed type from whole and fractional parts.
|
|
||||||
/// The fractional part has resolution of 1/65536.
|
|
||||||
constexpr Fix32(Int16 whole, UInt16 frac) noexcept :
|
|
||||||
m_whole(whole), m_frac(frac){}
|
|
||||||
|
|
||||||
|
|
||||||
/// Whole part of this fixed type.
|
|
||||||
constexpr Int16 whole() const noexcept{
|
|
||||||
return m_whole;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets whole part of this fixed type.
|
|
||||||
void setWhole(Int16 whole) noexcept{
|
|
||||||
m_whole = whole;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fractional part of this fixed type.
|
|
||||||
/// Resolution of 1/65536.
|
|
||||||
constexpr UInt16 frac() const noexcept{
|
|
||||||
return m_frac;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets fractional part of this fixed type.
|
|
||||||
/// Resolution of 1/65536.
|
|
||||||
void setFrac(UInt16 frac) noexcept{
|
|
||||||
m_frac = frac;
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit constexpr operator float() const noexcept{
|
|
||||||
return m_whole + m_frac / 65536.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr float toFloat() const noexcept{
|
|
||||||
return m_whole + m_frac / 65536.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr Fix32 operator-() const noexcept{
|
|
||||||
return -toFloat();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Int16 m_whole;
|
|
||||||
UInt16 m_frac;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
static inline constexpr Fix32 fix32AddHelper(Int32 frac, Int16 whole){
|
|
||||||
return frac < 65536 ? Fix32(whole, frac) : Fix32(whole + 1, frac - 65536);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr Fix32 fix32SubHelper(Int32 frac, Int16 whole){
|
|
||||||
return frac >= 0 ? Fix32(whole, frac) : Fix32(whole - 1, frac + 65536);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr bool operator>(Fix32 a, Fix32 b) noexcept{
|
|
||||||
return a.whole() > b.whole() || (a.whole() == b.whole() && a.frac() > b.frac());
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr bool operator<(Fix32 a, Fix32 b) noexcept{
|
|
||||||
return a.whole() < b.whole() || (a.whole() == b.whole() && a.frac() < b.frac());
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr bool operator>=(Fix32 a, Fix32 b) noexcept{
|
|
||||||
return !(a < b);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr bool operator<=(Fix32 a, Fix32 b) noexcept{
|
|
||||||
return !(a > b);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr bool operator==(Fix32 a, Fix32 b) noexcept{
|
|
||||||
return a.whole() == b.whole() && a.frac() == b.frac();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr bool operator!=(Fix32 a, Fix32 b) noexcept{
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr Fix32 operator+(Fix32 a, Fix32 b) noexcept{
|
|
||||||
return Detail::fix32AddHelper(static_cast<Int32>(a.frac()) + b.frac(), a.whole() + b.whole());
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr Fix32 operator-(Fix32 a, Fix32 b) noexcept{
|
|
||||||
return Detail::fix32SubHelper(static_cast<Int32>(a.frac()) - b.frac(), a.whole() - b.whole());
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr Fix32 operator*(Fix32 a, Fix32 b) noexcept{
|
|
||||||
return Fix32(static_cast<float>(a) * static_cast<float>(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr Fix32 operator/(Fix32 a, Fix32 b) noexcept{ // wonder about zero b
|
|
||||||
return Fix32(static_cast<float>(a) / static_cast<float>(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Fix32& operator+=(Fix32& a, Fix32 b) noexcept{
|
|
||||||
return a = a + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Fix32& operator-=(Fix32& a, Fix32 b) noexcept{
|
|
||||||
return a = a - b;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Fix32& operator*=(Fix32& a, Fix32 b) noexcept{
|
|
||||||
return a = a * b;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Fix32& operator/=(Fix32& a, Fix32 b) noexcept{ // wonder about zero b
|
|
||||||
return a = a / b;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Literals {
|
|
||||||
|
|
||||||
static inline constexpr Fix32 operator "" _fix(long double val) noexcept{
|
|
||||||
return Fix32(static_cast<float>(val));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline constexpr Fix32 operator "" _fix(unsigned long long val) noexcept{
|
|
||||||
return Fix32(static_cast<float>(val));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_FIX32_HPP
|
|
||||||
|
|
|
@ -1,106 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_FRAME_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_FRAME_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Section of an image to retrieve.
|
|
||||||
class Frame {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates zero-initialized frame.
|
|
||||||
constexpr Frame() noexcept{}
|
|
||||||
|
|
||||||
/// Creates frame with set top-left and bottom-right corners.
|
|
||||||
constexpr Frame(Fix32 left, Fix32 top, Fix32 right, Fix32 bottom) noexcept :
|
|
||||||
m_left(left), m_top(top), m_right(right), m_bottom(bottom){}
|
|
||||||
|
|
||||||
/// Left position of the image frame.
|
|
||||||
constexpr Fix32 left() const noexcept{
|
|
||||||
return m_left;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets left position of the image frame.
|
|
||||||
void setLeft(Fix32 left) noexcept{
|
|
||||||
m_left = left;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Top position of the image frame.
|
|
||||||
constexpr Fix32 top() const noexcept{
|
|
||||||
return m_top;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets top position of the image frame.
|
|
||||||
void setTop(Fix32 top) noexcept{
|
|
||||||
m_top = top;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Right position of the image frame.
|
|
||||||
constexpr Fix32 right() const noexcept{
|
|
||||||
return m_right;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets right position of the image frame.
|
|
||||||
void setRight(Fix32 right) noexcept{
|
|
||||||
m_right = right;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Bottom position of the image frame.
|
|
||||||
constexpr Fix32 bottom() const noexcept{
|
|
||||||
return m_bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets bottom position of the image frame.
|
|
||||||
void setBottom(Fix32 bottom) noexcept{
|
|
||||||
m_bottom = bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Fix32 m_left;
|
|
||||||
Fix32 m_top;
|
|
||||||
Fix32 m_right;
|
|
||||||
Fix32 m_bottom;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
static constexpr inline bool operator==(const Frame& a, const Frame& b) noexcept{
|
|
||||||
return a.left() == b.left() && a.top() == b.top() && a.right() == b.right() && a.bottom() == b.bottom();
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr inline bool operator!=(const Frame& a, const Frame& b) noexcept{
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_FRAME_HPP
|
|
||||||
|
|
|
@ -1,247 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015-2017 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_IDENTITY_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_IDENTITY_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
static constexpr const UInt32 identV2 = TWPP_DETAIL_IS_DS ? Detail::Ds2 : Detail::App2;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Source or application version information.
|
|
||||||
class Version {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates default-initialized version.
|
|
||||||
constexpr Version() noexcept :
|
|
||||||
m_majorNum(0), m_minorNum(0), m_language(Language::English),
|
|
||||||
m_country(Country::UnitedKingdom){}
|
|
||||||
|
|
||||||
/// Creates version initialized with supplied values.
|
|
||||||
constexpr Version(
|
|
||||||
UInt16 majorNumber,
|
|
||||||
UInt16 minorNumber,
|
|
||||||
Language language,
|
|
||||||
Country country,
|
|
||||||
const Str32& info = Str32()) noexcept :
|
|
||||||
m_majorNum(majorNumber), m_minorNum(minorNumber), m_language(language),
|
|
||||||
m_country(country), m_info(info){}
|
|
||||||
|
|
||||||
/// Major version number of the source or application.
|
|
||||||
constexpr UInt16 majorNumber() const noexcept{
|
|
||||||
return m_majorNum;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets major version number of the source or application.
|
|
||||||
void setMajorNumber(UInt16 major) noexcept{
|
|
||||||
m_majorNum = major;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Minor version number of the source or application.
|
|
||||||
constexpr UInt16 minorNumber() const noexcept{
|
|
||||||
return m_minorNum;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets minor version number of the source or application.
|
|
||||||
void setMinorNumber(UInt16 minor) noexcept{
|
|
||||||
m_minorNum = minor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Language of the source or application.
|
|
||||||
constexpr Language language() const noexcept{
|
|
||||||
return m_language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets language of the source or application.
|
|
||||||
void setLanguage(Language language) noexcept{
|
|
||||||
m_language = language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Original country of the source or application.
|
|
||||||
constexpr Country country() const noexcept{
|
|
||||||
return m_country;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set original country of the source or application.
|
|
||||||
void setCountry(Country country) noexcept{
|
|
||||||
m_country = country;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional version information of the source or application.
|
|
||||||
constexpr const Str32& info() const noexcept{
|
|
||||||
return m_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets additional version information of the source or application.
|
|
||||||
void setInfo(const Str32& info) noexcept{
|
|
||||||
m_info = info;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
UInt16 m_majorNum;
|
|
||||||
UInt16 m_minorNum;
|
|
||||||
Language m_language;
|
|
||||||
Country m_country;
|
|
||||||
Str32 m_info;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Source or application identity.
|
|
||||||
/// Uniquely identifies an endpoint.
|
|
||||||
class Identity {
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef
|
|
||||||
#if defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
void*
|
|
||||||
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
UInt32
|
|
||||||
#else
|
|
||||||
# error "Identity::Id for your platform here"
|
|
||||||
#endif
|
|
||||||
Id;
|
|
||||||
|
|
||||||
/// Creates default-initialized identity.
|
|
||||||
/// ID is set to zero.
|
|
||||||
/// TWAIN protocol is always Detail::ProtoMajor and Detail::ProtoMinor.
|
|
||||||
/// Supported group always contains DG::Control and V2.
|
|
||||||
constexpr Identity() noexcept :
|
|
||||||
m_id(), m_protoMaj(Detail::ProtoMajor), m_protoMin(Detail::ProtoMinor),
|
|
||||||
m_groups(DataGroup::Control | Detail::identV2){}
|
|
||||||
|
|
||||||
/// Creates identity initialized with supplied values.
|
|
||||||
/// ID is set to zero.
|
|
||||||
/// TWAIN protocol is always Detail::ProtoMajor and Detail::ProtoMinor.
|
|
||||||
/// Supported group always contains DG::Control and V2.
|
|
||||||
constexpr Identity(
|
|
||||||
const Version& version,
|
|
||||||
DataGroup group,
|
|
||||||
const Str32& manufacturer,
|
|
||||||
const Str32& productFamily,
|
|
||||||
const Str32& productName) noexcept :
|
|
||||||
m_id(), m_version(version), m_protoMaj(Detail::ProtoMajor),
|
|
||||||
m_protoMin(Detail::ProtoMinor), m_groups(DataGroup::Control | group | Detail::identV2),
|
|
||||||
m_manuf(manufacturer), m_prodFamily(productFamily), m_prodName(productName){}
|
|
||||||
|
|
||||||
/// Creates identity initialized with supplied values.
|
|
||||||
constexpr Identity(
|
|
||||||
Id id,
|
|
||||||
const Version& version,
|
|
||||||
UInt16 protoMajor,
|
|
||||||
UInt16 protoMinor,
|
|
||||||
UInt32 groups,
|
|
||||||
const Str32& manufacturer,
|
|
||||||
const Str32& productFamily,
|
|
||||||
const Str32& productName) noexcept :
|
|
||||||
m_id(id), m_version(version), m_protoMaj(protoMajor), m_protoMin(protoMinor),
|
|
||||||
m_groups(groups), m_manuf(manufacturer), m_prodFamily(productFamily),
|
|
||||||
m_prodName(productName){}
|
|
||||||
|
|
||||||
/// DSM-supplied ID of this identity.
|
|
||||||
constexpr Id id() const{
|
|
||||||
return m_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Version information.
|
|
||||||
constexpr const Version& version() const noexcept{
|
|
||||||
return m_version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether a data group is supported.
|
|
||||||
constexpr bool supports(DataGroup group) const noexcept{
|
|
||||||
return (m_groups & group) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether this is V2 application.
|
|
||||||
constexpr bool isAppV2() const noexcept{
|
|
||||||
return (m_groups & Detail::App2) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether this is V2 DSM.
|
|
||||||
constexpr bool isDsmV2() const noexcept{
|
|
||||||
return (m_groups & Detail::Dsm2) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether this is V2 source.
|
|
||||||
constexpr bool isDsV2() const noexcept{
|
|
||||||
return (m_groups & Detail::Ds2) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The manufacturer.
|
|
||||||
/// Manufacturer and product name uniquely identify a source.
|
|
||||||
constexpr const Str32& manufacturer() const noexcept{
|
|
||||||
return m_manuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The product name.
|
|
||||||
/// Manufacturer and product name uniquely identify a source.
|
|
||||||
constexpr const Str32& productName() const noexcept{
|
|
||||||
return m_prodName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The product family.
|
|
||||||
constexpr const Str32& productFamily() const noexcept{
|
|
||||||
return m_prodFamily;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Raw data group flags.
|
|
||||||
constexpr UInt32 dataGroupsRaw() const noexcept{
|
|
||||||
return m_groups;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// TWAIN protocol major version.
|
|
||||||
constexpr UInt16 protocolMajor() const noexcept{
|
|
||||||
return m_protoMaj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// TWAIN protocol minor version.
|
|
||||||
constexpr UInt16 protocolMinor() const noexcept{
|
|
||||||
return m_protoMin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Id m_id;
|
|
||||||
Version m_version;
|
|
||||||
UInt16 m_protoMaj;
|
|
||||||
UInt16 m_protoMin;
|
|
||||||
UInt32 m_groups;
|
|
||||||
Str32 m_manuf;
|
|
||||||
Str32 m_prodFamily;
|
|
||||||
Str32 m_prodName;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_IDENTITY_HPP
|
|
|
@ -1,190 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_IMAGEINFO_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_IMAGEINFO_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Contains information about transfered image.
|
|
||||||
class ImageInfo {
|
|
||||||
|
|
||||||
typedef Detail::FixedArray<Int16, 8> BitsPerSampleImpl;
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef Int16 BitsPerSample[8];
|
|
||||||
|
|
||||||
/// Creates zero-initialized info.
|
|
||||||
constexpr ImageInfo() noexcept :
|
|
||||||
m_imgWidth(0), m_imgHeight(0), m_spp(0), m_bps(), m_bpp(0),
|
|
||||||
m_planar(0), m_pixelType(PixelType::BlackWhite), m_compression(Compression::None){}
|
|
||||||
|
|
||||||
/// Creates info with supplied values.
|
|
||||||
template<std::size_t inputSize>
|
|
||||||
constexpr ImageInfo(
|
|
||||||
Fix32 xResolution,
|
|
||||||
Fix32 yResolution,
|
|
||||||
Int32 width,
|
|
||||||
Int32 height,
|
|
||||||
Int16 samplesPerPixel,
|
|
||||||
const Int16(& bitsPerSample)[inputSize],
|
|
||||||
Int16 bitsPerPixel,
|
|
||||||
Bool planar,
|
|
||||||
PixelType pixelType,
|
|
||||||
Compression compression
|
|
||||||
) noexcept :
|
|
||||||
m_xres(xResolution), m_yres(yResolution), m_imgWidth(width), m_imgHeight(height),
|
|
||||||
m_spp(samplesPerPixel), m_bps(bitsPerSample), m_bpp(bitsPerPixel), m_planar(planar),
|
|
||||||
m_pixelType(pixelType), m_compression(compression){}
|
|
||||||
|
|
||||||
/// X-axis resolution of the image.
|
|
||||||
constexpr Fix32 xResolution() const noexcept{
|
|
||||||
return m_xres;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets x-axis resolution of the image.
|
|
||||||
void setXResolution(Fix32 xres) noexcept{
|
|
||||||
m_xres = xres;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Y-axis resolution of the image.
|
|
||||||
constexpr Fix32 yResolution() const noexcept{
|
|
||||||
return m_yres;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets y-axis resolution of the image.
|
|
||||||
void setYResolution(Fix32 yres) noexcept{
|
|
||||||
m_yres = yres;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Image width in pixels.
|
|
||||||
constexpr Int32 width() const noexcept{
|
|
||||||
return m_imgWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets image width in pixels.
|
|
||||||
void setWidth(Int32 width) noexcept{
|
|
||||||
m_imgWidth = width;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Image height in pixels.
|
|
||||||
constexpr Int32 height() const noexcept{
|
|
||||||
return m_imgHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets image height in pixels.
|
|
||||||
void setHeight(Int32 height) noexcept{
|
|
||||||
m_imgHeight = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Samples per single pixel.
|
|
||||||
constexpr Int16 samplesPerPixel() const noexcept{
|
|
||||||
return m_spp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets samples per single pixel.
|
|
||||||
void setSamplesPerPixel(Int16 spp) noexcept{
|
|
||||||
m_spp = spp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Array of bits per sample.
|
|
||||||
/// Contains `samplesPerPixel` entries.
|
|
||||||
constexpr const BitsPerSample& bitsPerSample() const noexcept{
|
|
||||||
return m_bps.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Array of bits per sample.
|
|
||||||
/// Contains `samplesPerPixel` entries.
|
|
||||||
BitsPerSample& bitsPerSample() noexcept{
|
|
||||||
return m_bps.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Total number of bits per pixel.
|
|
||||||
/// This should be true: bitsPerPixel = SUM[i=0..samplesPerPixel-1](bitsPerSample[i])
|
|
||||||
constexpr Int16 bitsPerPixel() const noexcept{
|
|
||||||
return m_bpp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets total number of bits per pixel.
|
|
||||||
/// This should be true: bitsPerPixel = SUM[i=0..samplesPerPixel-1](bitsPerSample[i])
|
|
||||||
void setBitsPerPixel(Int16 bpp) noexcept{
|
|
||||||
m_bpp = bpp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the image is planar (consists of several sample planes) or is chunky
|
|
||||||
/// (samples are transferes in one plane and are interlaced).
|
|
||||||
constexpr Bool planar() const noexcept{
|
|
||||||
return m_planar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets whether the image is planar (consists of several sample planes) or is chunky
|
|
||||||
/// (samples are transferes in one plane and are interlaced).
|
|
||||||
void setPlanar(Bool planar) noexcept{
|
|
||||||
m_planar = planar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The type of image.
|
|
||||||
constexpr PixelType pixelType() const noexcept{
|
|
||||||
return m_pixelType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the type of image.
|
|
||||||
void setPixelType(PixelType pixelType) noexcept{
|
|
||||||
m_pixelType = pixelType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Image compression.
|
|
||||||
constexpr Compression compression() const noexcept{
|
|
||||||
return m_compression;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets image compression.
|
|
||||||
void compression(Compression compression) noexcept{
|
|
||||||
m_compression = compression;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Fix32 m_xres;
|
|
||||||
Fix32 m_yres;
|
|
||||||
Int32 m_imgWidth;
|
|
||||||
Int32 m_imgHeight;
|
|
||||||
Int16 m_spp;
|
|
||||||
BitsPerSampleImpl m_bps;
|
|
||||||
Int16 m_bpp;
|
|
||||||
Bool m_planar;
|
|
||||||
PixelType m_pixelType;
|
|
||||||
Compression m_compression;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_IMAGEINFO_HPP
|
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_IMAGELAYOUT_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_IMAGELAYOUT_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Provides image size and its position on the scanner and information about order of the image.
|
|
||||||
class ImageLayout {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates layout.
|
|
||||||
constexpr ImageLayout(
|
|
||||||
const Frame& frame = Frame(),
|
|
||||||
UInt32 documentNumber = 1,
|
|
||||||
UInt32 pageNumber = 1,
|
|
||||||
UInt32 frameNumber = 1
|
|
||||||
) noexcept :
|
|
||||||
m_frame(frame), m_docNumber(documentNumber),
|
|
||||||
m_pageNumber(pageNumber), m_frameNumber(frameNumber){}
|
|
||||||
|
|
||||||
/// The image frame.
|
|
||||||
constexpr const Frame& frame() const noexcept{
|
|
||||||
return m_frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the image frame.
|
|
||||||
void setFrame(const Frame& frame) noexcept{
|
|
||||||
m_frame = frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of the document, set by source.
|
|
||||||
constexpr UInt32 documentNumber() const noexcept{
|
|
||||||
return m_docNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of the document.
|
|
||||||
void setDocumentNumber(UInt32 documentNumber) noexcept{
|
|
||||||
m_docNumber = documentNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of the page, set by source.
|
|
||||||
constexpr UInt32 pageNumber() const noexcept{
|
|
||||||
return m_pageNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of the page.
|
|
||||||
void setPageNumber(UInt32 pageNumber) noexcept{
|
|
||||||
m_pageNumber = pageNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of the frame, set by source.
|
|
||||||
constexpr UInt32 frameNumber() const noexcept{
|
|
||||||
return m_frameNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of the frame.
|
|
||||||
void setFrameNumber(UInt32 frameNumber) noexcept{
|
|
||||||
m_frameNumber = frameNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Frame m_frame;
|
|
||||||
UInt32 m_docNumber;
|
|
||||||
UInt32 m_pageNumber;
|
|
||||||
UInt32 m_frameNumber;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_IMAGELAYOUT_HPP
|
|
|
@ -1,207 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_IMAGEMEMXFER_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_IMAGEMEMXFER_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
/// Structure holding the information and data of memory and memory file transfers.
|
|
||||||
class ImageMemXferImpl {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates a zero-initialized structure without any memory.
|
|
||||||
ImageMemXferImpl() noexcept :
|
|
||||||
m_compression(Compression::None), m_bytesPerRow(0), m_columns(0), m_rows(0),
|
|
||||||
m_xoff(0), m_yoff(0), m_bytesWritten(0){}
|
|
||||||
|
|
||||||
/// Creates an initialized structure from the supplied values and memory.
|
|
||||||
/// The ownership of the memory is taken over.
|
|
||||||
ImageMemXferImpl(
|
|
||||||
Compression compression,
|
|
||||||
UInt32 bytesPerRow,
|
|
||||||
UInt32 columns,
|
|
||||||
UInt32 rows,
|
|
||||||
UInt32 xOffset,
|
|
||||||
UInt32 yOffset,
|
|
||||||
UInt32 bytesWritten,
|
|
||||||
Memory memory
|
|
||||||
) noexcept :
|
|
||||||
m_compression(compression), m_bytesPerRow(bytesPerRow),
|
|
||||||
m_columns(columns), m_rows(rows), m_xoff(xOffset), m_yoff(yOffset),
|
|
||||||
m_bytesWritten(bytesWritten), m_memory(std::move(memory)){}
|
|
||||||
|
|
||||||
/// Compression used in the transfer.
|
|
||||||
Compression compression() const noexcept{
|
|
||||||
return m_compression;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets compression used in the transfer.
|
|
||||||
void setCompression(Compression compression) noexcept{
|
|
||||||
m_compression = compression;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of bytes per single row.
|
|
||||||
UInt32 bytesPerRow() const noexcept{
|
|
||||||
return m_bytesPerRow;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of bytes per single row.
|
|
||||||
void setBytesPerRow(UInt32 bytesPerRow) noexcept{
|
|
||||||
m_bytesPerRow = bytesPerRow;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of columns in the transfer.
|
|
||||||
UInt32 columns() const noexcept{
|
|
||||||
return m_columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of columns in the transfer.
|
|
||||||
void setColumns(UInt32 columns) noexcept{
|
|
||||||
m_columns = columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of rows in the transfer.
|
|
||||||
UInt32 rows() const noexcept{
|
|
||||||
return m_rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of rows in the transfer.
|
|
||||||
void setRows(UInt32 rows) noexcept{
|
|
||||||
m_rows = rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// X offset from top-left corner in pixels of the image data in the transfer.
|
|
||||||
UInt32 xOffset() const noexcept{
|
|
||||||
return m_xoff;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets X offset from top-left corner in pixels of the image data in the transfer.
|
|
||||||
void setXOffset(UInt32 xOffset) noexcept{
|
|
||||||
m_xoff = xOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Y offset from top-left corner in pixels of the image data in the transfer.
|
|
||||||
UInt32 yOffset() const noexcept{
|
|
||||||
return m_yoff;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets Y offset from top-left corner in pixels of the image data in the transfer.
|
|
||||||
void setYOffset(UInt32 yOffset) noexcept{
|
|
||||||
m_yoff = yOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of bytes in this transfer, always contains whole rows or tiles.
|
|
||||||
UInt32 bytesWritten() const noexcept{
|
|
||||||
return m_bytesWritten;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of bytes in this transfer.
|
|
||||||
void setBytesWritten(UInt32 bytesWritten) noexcept{
|
|
||||||
m_bytesWritten = bytesWritten;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Contained memory structure.
|
|
||||||
const Memory& memory() const noexcept{
|
|
||||||
return m_memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Contained memory structure.
|
|
||||||
Memory& memory() noexcept{
|
|
||||||
return m_memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Compression m_compression;
|
|
||||||
UInt32 m_bytesPerRow;
|
|
||||||
UInt32 m_columns;
|
|
||||||
UInt32 m_rows;
|
|
||||||
UInt32 m_xoff;
|
|
||||||
UInt32 m_yoff;
|
|
||||||
UInt32 m_bytesWritten;
|
|
||||||
Memory m_memory;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Structure holding the information and data of memory transfer.
|
|
||||||
class ImageMemXfer : public Detail::ImageMemXferImpl {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates a zero-initialized structure without any memory.
|
|
||||||
ImageMemXfer() noexcept : Detail::ImageMemXferImpl(){}
|
|
||||||
|
|
||||||
/// Creates an initialized structure from the supplied values and memory.
|
|
||||||
/// The ownership of the memory is taken over.
|
|
||||||
ImageMemXfer(
|
|
||||||
Compression compression,
|
|
||||||
UInt32 bytesPerRow,
|
|
||||||
UInt32 columns,
|
|
||||||
UInt32 rows,
|
|
||||||
UInt32 xOffset,
|
|
||||||
UInt32 yOffset,
|
|
||||||
UInt32 bytesWritten,
|
|
||||||
Memory memory
|
|
||||||
) noexcept : Detail::ImageMemXferImpl(
|
|
||||||
compression, bytesPerRow, columns, rows, xOffset,
|
|
||||||
yOffset, bytesWritten, std::move(memory)){}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Structure holding the information and data of memory file transfer.
|
|
||||||
class ImageMemFileXfer : public Detail::ImageMemXferImpl {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates a zero-initialized structure without any memory.
|
|
||||||
ImageMemFileXfer() noexcept : Detail::ImageMemXferImpl(){}
|
|
||||||
|
|
||||||
/// Creates an initialized structure from the supplied values and memory.
|
|
||||||
/// The ownership of the memory is taken over.
|
|
||||||
ImageMemFileXfer(
|
|
||||||
Compression compression,
|
|
||||||
UInt32 bytesPerRow,
|
|
||||||
UInt32 columns,
|
|
||||||
UInt32 rows,
|
|
||||||
UInt32 xOffset,
|
|
||||||
UInt32 yOffset,
|
|
||||||
UInt32 bytesWritten,
|
|
||||||
Memory memory
|
|
||||||
) noexcept : Detail::ImageMemXferImpl(
|
|
||||||
compression, bytesPerRow, columns, rows, xOffset,
|
|
||||||
yOffset, bytesWritten, std::move(memory)){}
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_IMAGEMEMXFER_HPP
|
|
|
@ -1,98 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_IMAGENATIVEXFER_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_IMAGENATIVEXFER_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Structure holding native transfer image handle.
|
|
||||||
class ImageNativeXfer {
|
|
||||||
|
|
||||||
public:
|
|
||||||
template<typename T>
|
|
||||||
using Data = Detail::Lock<typename std::decay<T>::type>;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
using ConstData = Detail::Lock<const typename std::decay<T>::type>;
|
|
||||||
|
|
||||||
|
|
||||||
/// Creates empty, invalid native transfer.
|
|
||||||
ImageNativeXfer() noexcept :
|
|
||||||
m_handle(){}
|
|
||||||
|
|
||||||
/// Creates a new ImageNativeXfer object from a handle.
|
|
||||||
/// The ownership of the handle is taken over.
|
|
||||||
explicit ImageNativeXfer(Handle h) :
|
|
||||||
m_handle(h){}
|
|
||||||
|
|
||||||
/// Creates uninitialized native image with defines size in bytes.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
explicit ImageNativeXfer(UInt32 size) :
|
|
||||||
m_handle(Detail::alloc(size)){}
|
|
||||||
|
|
||||||
/// Data of this native transfer.
|
|
||||||
/// Actual type depends on system and source.
|
|
||||||
/// Windows sources use BMP format without file header, version varies.
|
|
||||||
/// Linux uses TIFF, version varies.
|
|
||||||
/// Mac uses QuickDraw Picture.
|
|
||||||
template<typename T = void>
|
|
||||||
Data<T> data() noexcept{
|
|
||||||
return m_handle.lock<typename std::decay<T>::type>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Data of this native transfer.
|
|
||||||
/// Actual type depends on system and source.
|
|
||||||
/// Windows sources use BMP format without file header, version varies.
|
|
||||||
/// Linux uses TIFF, version varies.
|
|
||||||
/// Mac uses QuickDraw Picture.
|
|
||||||
template<typename T = void>
|
|
||||||
ConstData<T> data() const noexcept{
|
|
||||||
return m_handle.lock<const typename std::decay<T>::type>();
|
|
||||||
}
|
|
||||||
|
|
||||||
operator bool() const noexcept{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Releases the contained handle, making user responsible for freeing it.
|
|
||||||
Handle release() noexcept{
|
|
||||||
return m_handle.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Detail::UniqueHandle m_handle;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_IMAGENATIVEXFER_HPP
|
|
||||||
|
|
|
@ -1,158 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015-2017 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_INTERNAL_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_INTERNAL_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
struct AudioFileXfer {};
|
|
||||||
struct ImageFileXfer {};
|
|
||||||
typedef Memory IccProfileMemory;
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
typedef ReturnCode (TWPP_DETAIL_CALLSTYLE* DsmEntry)(
|
|
||||||
Identity* origin,
|
|
||||||
Identity* dest,
|
|
||||||
DataGroup dg,
|
|
||||||
Dat dat,
|
|
||||||
Msg msg,
|
|
||||||
void* data
|
|
||||||
);
|
|
||||||
|
|
||||||
typedef DsmEntry CallBackFunc;
|
|
||||||
|
|
||||||
typedef
|
|
||||||
#if defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
void*
|
|
||||||
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
UInt32
|
|
||||||
#else
|
|
||||||
# error "CallBackConstant for your platform here"
|
|
||||||
#endif
|
|
||||||
CallBackConstant;
|
|
||||||
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
struct EntryPoint {
|
|
||||||
constexpr EntryPoint() noexcept :
|
|
||||||
m_size(sizeof(EntryPoint)), m_entry(nullptr), m_alloc(nullptr),
|
|
||||||
m_free(nullptr), m_lock(nullptr), m_unlock(nullptr){}
|
|
||||||
|
|
||||||
UInt32 m_size;
|
|
||||||
DsmEntry m_entry;
|
|
||||||
MemAlloc m_alloc;
|
|
||||||
MemFree m_free;
|
|
||||||
MemLock m_lock;
|
|
||||||
MemUnlock m_unlock;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CallBack {
|
|
||||||
|
|
||||||
constexpr CallBack(CallBackFunc func, CallBackConstant constant, Msg msg) noexcept :
|
|
||||||
m_func(func), m_constant(constant), m_msg(msg){}
|
|
||||||
|
|
||||||
CallBackFunc m_func;
|
|
||||||
CallBackConstant m_constant;
|
|
||||||
Msg m_msg;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CallBack2 {
|
|
||||||
|
|
||||||
constexpr CallBack2(CallBackFunc func, UIntPtr constant, Msg msg) noexcept :
|
|
||||||
m_func(func), m_constant(constant), m_msg(msg){}
|
|
||||||
|
|
||||||
CallBackFunc m_func;
|
|
||||||
UIntPtr m_constant;
|
|
||||||
Msg m_msg;
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
/// Manages DSM dll/so/framework connection.
|
|
||||||
class DsmLib {
|
|
||||||
|
|
||||||
public:
|
|
||||||
constexpr DsmLib() noexcept :
|
|
||||||
m_handle(DsmLibOs::nullHandle){}
|
|
||||||
|
|
||||||
~DsmLib(){
|
|
||||||
unload();
|
|
||||||
}
|
|
||||||
|
|
||||||
DsmLib(const DsmLib&) = delete;
|
|
||||||
DsmLib& operator=(const DsmLib&) = delete;
|
|
||||||
|
|
||||||
DsmLib(DsmLib&& o) noexcept :
|
|
||||||
m_handle(o.m_handle){
|
|
||||||
|
|
||||||
o.m_handle = DsmLibOs::nullHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
DsmLib& operator=(DsmLib&& o) noexcept{
|
|
||||||
if (&o != this){
|
|
||||||
unload();
|
|
||||||
|
|
||||||
m_handle = o.m_handle;
|
|
||||||
o.m_handle = DsmLibOs::nullHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator bool() const noexcept{
|
|
||||||
return m_handle != DsmLibOs::nullHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool load(bool preferOld = false) noexcept{
|
|
||||||
m_handle = DsmLibOs::load(preferOld);
|
|
||||||
return m_handle != DsmLibOs::nullHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
void unload() noexcept{
|
|
||||||
if (m_handle != DsmLibOs::nullHandle){
|
|
||||||
DsmLibOs::unload(m_handle);
|
|
||||||
m_handle = DsmLibOs::nullHandle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DsmEntry resolve() const noexcept{
|
|
||||||
return DsmLibOs::resolve<DsmEntry>(m_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
DsmLibOs::Handle m_handle;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_INTERNAL_HPP
|
|
|
@ -1,173 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_JPEGCOMPRESSION_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_JPEGCOMPRESSION_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// See manual for more info.
|
|
||||||
class JpegCompression {
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef UInt16 UInt16Arr4[4];
|
|
||||||
typedef Memory MemoryArr2[2];
|
|
||||||
typedef Memory MemoryArr4[4];
|
|
||||||
|
|
||||||
JpegCompression() noexcept :
|
|
||||||
m_colorSpace(PixelType::BlackWhite), m_subSampling(0x10001000), m_components(0),
|
|
||||||
m_restartFrequency(0), m_quantMap(), m_huffmanMap(){}
|
|
||||||
|
|
||||||
template<
|
|
||||||
std::size_t quantTableMapSize,
|
|
||||||
std::size_t quantTableSize,
|
|
||||||
std::size_t huffmanTableMapSize,
|
|
||||||
std::size_t huffmanDcSize,
|
|
||||||
std::size_t huffmanAcSize
|
|
||||||
>
|
|
||||||
JpegCompression(
|
|
||||||
PixelType colorSpace,
|
|
||||||
UInt32 subSampling,
|
|
||||||
UInt16 components,
|
|
||||||
UInt16 restartFrequency,
|
|
||||||
const UInt16(& quantTableMap)[quantTableMapSize],
|
|
||||||
Memory(& quantTable)[quantTableSize],
|
|
||||||
const UInt16(& huffmanTableMap)[huffmanTableMapSize],
|
|
||||||
Memory(& huffmanDc)[huffmanDcSize],
|
|
||||||
Memory(& huffmanAc)[huffmanAcSize]
|
|
||||||
) noexcept :
|
|
||||||
m_colorSpace(colorSpace),
|
|
||||||
m_subSampling(subSampling),
|
|
||||||
m_components(components),
|
|
||||||
m_restartFrequency(restartFrequency),
|
|
||||||
m_quantMap(quantTableMap),
|
|
||||||
m_huffmanMap(huffmanTableMap){
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < quantTableSize; i++){
|
|
||||||
m_quantTable[i] = std::move(quantTable[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < huffmanDcSize; i++){
|
|
||||||
m_huffmanDc[i] = std::move(huffmanDc[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < huffmanAcSize; i++){
|
|
||||||
m_huffmanAc[i] = std::move(huffmanAc[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PixelType pixelType() const noexcept{
|
|
||||||
return m_colorSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPixelType(PixelType pixelType) noexcept{
|
|
||||||
m_colorSpace = pixelType;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 subSampling() const noexcept{
|
|
||||||
return m_subSampling;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSubSampling(UInt32 subSampling) noexcept{
|
|
||||||
m_subSampling = subSampling;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt16 components() const noexcept{
|
|
||||||
return m_components;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setComponents(UInt16 components) noexcept{
|
|
||||||
m_components = components;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt16 restartFrequency() const noexcept{
|
|
||||||
return m_restartFrequency;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRestartFrequency(UInt16 restartFrequency) noexcept{
|
|
||||||
m_restartFrequency = restartFrequency;
|
|
||||||
}
|
|
||||||
|
|
||||||
const UInt16Arr4& quantTableMap() const noexcept{
|
|
||||||
return m_quantMap.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt16Arr4& quantTableMap() noexcept{
|
|
||||||
return m_quantMap.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
const MemoryArr4& quantTable() const noexcept{
|
|
||||||
return m_quantTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryArr4& quantTable() noexcept{
|
|
||||||
return m_quantTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
const UInt16Arr4& huffmanTableMap() const noexcept{
|
|
||||||
return m_huffmanMap.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt16Arr4& huffmanTableMap() noexcept{
|
|
||||||
return m_huffmanMap.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
const MemoryArr2& huffmanDc() const noexcept{
|
|
||||||
return m_huffmanDc;
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryArr2& huffmanDc() noexcept{
|
|
||||||
return m_huffmanDc;
|
|
||||||
}
|
|
||||||
|
|
||||||
const MemoryArr2& huffmanAc() const noexcept{
|
|
||||||
return m_huffmanAc;
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryArr2& huffmanAc() noexcept{
|
|
||||||
return m_huffmanAc;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
PixelType m_colorSpace;
|
|
||||||
UInt32 m_subSampling;
|
|
||||||
UInt16 m_components;
|
|
||||||
UInt16 m_restartFrequency;
|
|
||||||
Detail::FixedArray<UInt16, 4> m_quantMap;
|
|
||||||
MemoryArr4 m_quantTable;
|
|
||||||
Detail::FixedArray<UInt16, 4> m_huffmanMap;
|
|
||||||
MemoryArr2 m_huffmanDc;
|
|
||||||
MemoryArr2 m_huffmanAc;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_JPEGCOMPRESSION_HPP
|
|
|
@ -1,194 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_MEMORY_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_MEMORY_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
namespace Flags {
|
|
||||||
|
|
||||||
enum {
|
|
||||||
AppOwns = 0x0001,
|
|
||||||
DsmOwns = 0x0002,
|
|
||||||
DsOwns = 0x0004,
|
|
||||||
Pointer = 0x0008,
|
|
||||||
Handle = 0x0010
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(TWPP_IS_DS)
|
|
||||||
static constexpr const UInt32 thisOwns = AppOwns;
|
|
||||||
static constexpr const UInt32 otherOwns = DsOwns;
|
|
||||||
#else
|
|
||||||
static constexpr const UInt32 thisOwns = DsOwns;
|
|
||||||
static constexpr const UInt32 otherOwns = AppOwns;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Holds and potentially owns a block of memory using either pointer or handle.
|
|
||||||
class Memory {
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef Detail::MaybeLock<char> Data;
|
|
||||||
typedef Detail::MaybeLock<const char> ConstData;
|
|
||||||
|
|
||||||
/// Creates an empty memory.
|
|
||||||
constexpr Memory() noexcept :
|
|
||||||
m_flags(0), m_size(0), m_data(nullptr){}
|
|
||||||
|
|
||||||
/// Creates a memory block of supplied size.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
explicit Memory(UInt32 size) :
|
|
||||||
m_flags(Detail::Flags::thisOwns | Detail::Flags::Handle), m_size(size),
|
|
||||||
m_data(Detail::alloc(size).raw()){}
|
|
||||||
|
|
||||||
/// Creates a new memory object from Handle.
|
|
||||||
/// The memory ownership is taken over.
|
|
||||||
/// \param h The handle, see thisOwns for more information about memory ownership.
|
|
||||||
/// \param size Size of the memory in bytes, that handle h manages.
|
|
||||||
/// \param thisOwns {
|
|
||||||
/// If true, this object frees the memory once it goes out of scope.
|
|
||||||
///
|
|
||||||
/// If false the memory is not freed, and MUST be passed to the other side
|
|
||||||
/// (APP->DS or DS->APP) of the connection, that will free it.
|
|
||||||
/// }
|
|
||||||
Memory(Handle h, UInt32 size, bool thisOwns = true) noexcept :
|
|
||||||
m_flags((thisOwns ? Detail::Flags::thisOwns : Detail::Flags::otherOwns) | Detail::Flags::Handle),
|
|
||||||
m_size(size),
|
|
||||||
m_data(h.raw()){}
|
|
||||||
|
|
||||||
/// Creates a memory object from container.
|
|
||||||
/// The memory object does NOT take over the ownership of the data.
|
|
||||||
/// Make sure the container is destroyed after the memory object is.
|
|
||||||
template<typename Container>
|
|
||||||
explicit Memory(const Container& container) noexcept :
|
|
||||||
m_flags(Detail::Flags::thisOwns | Detail::Flags::Pointer),
|
|
||||||
m_size(sizeof(Container::value_type) * container.size()),
|
|
||||||
m_data(container.data()){}
|
|
||||||
|
|
||||||
/// Creates a memory object from pointer.
|
|
||||||
/// The memory object does NOT take over the ownership of the data.
|
|
||||||
/// Make sure the data is destroyed after the memory object is.
|
|
||||||
constexpr Memory(void* data, UInt32 size) noexcept :
|
|
||||||
m_flags(Detail::Flags::thisOwns | Detail::Flags::Pointer), m_size(size),
|
|
||||||
m_data(data){}
|
|
||||||
|
|
||||||
~Memory(){
|
|
||||||
freePriv();
|
|
||||||
}
|
|
||||||
|
|
||||||
Memory(const Memory& o) = delete;
|
|
||||||
Memory& operator=(const Memory& o) = delete;
|
|
||||||
|
|
||||||
Memory(Memory&& o) noexcept :
|
|
||||||
m_flags(o.m_flags), m_size(o.m_size), m_data(o.m_data)
|
|
||||||
{
|
|
||||||
o.m_flags = 0;
|
|
||||||
o.m_size = 0;
|
|
||||||
o.m_data = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Memory& operator=(Memory&& o) noexcept{
|
|
||||||
if (&o != this){
|
|
||||||
freePriv();
|
|
||||||
|
|
||||||
m_flags = o.m_flags;
|
|
||||||
m_size = o.m_size;
|
|
||||||
m_data = o.m_data;
|
|
||||||
|
|
||||||
o.m_flags = 0;
|
|
||||||
o.m_size = 0;
|
|
||||||
o.m_data = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The data in this memory block.
|
|
||||||
ConstData data() const noexcept{
|
|
||||||
return m_flags & Detail::Flags::Handle ?
|
|
||||||
ConstData(Handle(static_cast<Handle::Raw>(m_data))) :
|
|
||||||
ConstData(static_cast<const char*>(m_data));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The data in this memory block.
|
|
||||||
Data data() noexcept{
|
|
||||||
return m_flags & Detail::Flags::Handle ?
|
|
||||||
Data(Handle(static_cast<Handle::Raw>(m_data))) :
|
|
||||||
Data(static_cast<char*>(m_data));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of bytes in the memory block.
|
|
||||||
UInt32 size() const noexcept{
|
|
||||||
return m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// In case of handle, frees memory regardless its owner; does nothing otherwise (pointer).
|
|
||||||
/// Potentially unsafe operation.
|
|
||||||
void free(){
|
|
||||||
if (m_flags & Detail::Flags::Handle){
|
|
||||||
Handle h(static_cast<Handle::Raw>(m_data));
|
|
||||||
if (h){
|
|
||||||
Detail::free(h);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_size = 0;
|
|
||||||
m_data = nullptr;
|
|
||||||
m_flags = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void freePriv(){
|
|
||||||
if (m_flags & Detail::Flags::thisOwns){
|
|
||||||
if (m_flags & Detail::Flags::Handle){
|
|
||||||
Detail::free(Handle(static_cast<Handle::Raw>(m_data)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 m_flags;
|
|
||||||
UInt32 m_size;
|
|
||||||
void* m_data;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_MEMORY_HPP
|
|
||||||
|
|
|
@ -1,439 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015-2017 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_MEMORYOPS_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_MEMORYOPS_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
typedef Handle::Raw (TWPP_DETAIL_CALLSTYLE* MemAlloc)(UInt32 size);
|
|
||||||
typedef void (TWPP_DETAIL_CALLSTYLE* MemFree)(Handle::Raw handle);
|
|
||||||
typedef void* (TWPP_DETAIL_CALLSTYLE* MemLock)(Handle::Raw handle);
|
|
||||||
typedef void (TWPP_DETAIL_CALLSTYLE* MemUnlock)(Handle::Raw handle);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// templates behave as if they were defined in at most one module
|
|
||||||
// ideal for storing static data
|
|
||||||
template<typename Dummy>
|
|
||||||
struct GlobalMemFuncs {
|
|
||||||
|
|
||||||
#if defined(TWPP_DETAIL_OS_WIN)
|
|
||||||
static Handle::Raw TWPP_DETAIL_CALLSTYLE defAlloc(UInt32 size){
|
|
||||||
return ::GlobalAlloc(GHND, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TWPP_DETAIL_CALLSTYLE defFree(Handle::Raw handle){
|
|
||||||
::GlobalFree(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void* TWPP_DETAIL_CALLSTYLE defLock(Handle::Raw handle){
|
|
||||||
return ::GlobalLock(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TWPP_DETAIL_CALLSTYLE defUnlock(Handle::Raw handle){
|
|
||||||
::GlobalUnlock(handle);
|
|
||||||
}
|
|
||||||
#elif defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
static Handle::Raw TWPP_DETAIL_CALLSTYLE defAlloc(UInt32 size){
|
|
||||||
return ::NewHandle(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TWPP_DETAIL_CALLSTYLE defFree(Handle::Raw handle){
|
|
||||||
::DisposeHandle(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void* TWPP_DETAIL_CALLSTYLE defLock(Handle::Raw handle){
|
|
||||||
return *handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TWPP_DETAIL_CALLSTYLE defUnlock(Handle::Raw){
|
|
||||||
// noop
|
|
||||||
}
|
|
||||||
#elif !defined(TWPP_DETAIL_OS_LINUX) // Linux doesnt need default functions
|
|
||||||
# error "default memory functions for your platform here"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static MemAlloc alloc;
|
|
||||||
static MemFree free;
|
|
||||||
static MemLock lock;
|
|
||||||
static MemUnlock unlock;
|
|
||||||
|
|
||||||
#if defined(TWPP_IS_DS)
|
|
||||||
static Handle doNotFreeHandle;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
template<typename Dummy>
|
|
||||||
MemAlloc GlobalMemFuncs<Dummy>::alloc = GlobalMemFuncs<Dummy>::defAlloc;
|
|
||||||
|
|
||||||
template<typename Dummy>
|
|
||||||
MemFree GlobalMemFuncs<Dummy>::free = GlobalMemFuncs<Dummy>::defFree;
|
|
||||||
|
|
||||||
template<typename Dummy>
|
|
||||||
MemLock GlobalMemFuncs<Dummy>::lock = GlobalMemFuncs<Dummy>::defLock;
|
|
||||||
|
|
||||||
template<typename Dummy>
|
|
||||||
MemUnlock GlobalMemFuncs<Dummy>::unlock = GlobalMemFuncs<Dummy>::defUnlock;
|
|
||||||
#elif defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
template<typename Dummy>
|
|
||||||
MemAlloc GlobalMemFuncs<Dummy>::alloc = nullptr;
|
|
||||||
|
|
||||||
template<typename Dummy>
|
|
||||||
MemFree GlobalMemFuncs<Dummy>::free = nullptr;
|
|
||||||
|
|
||||||
template<typename Dummy>
|
|
||||||
MemLock GlobalMemFuncs<Dummy>::lock = nullptr;
|
|
||||||
|
|
||||||
template<typename Dummy>
|
|
||||||
MemUnlock GlobalMemFuncs<Dummy>::unlock = nullptr;
|
|
||||||
#else
|
|
||||||
# error "default memory functions setup for your platform here"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(TWPP_IS_DS)
|
|
||||||
template<typename Dummy>
|
|
||||||
Handle GlobalMemFuncs<Dummy>::doNotFreeHandle;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
inline static void setMemFuncs(MemAlloc alloc, MemFree free, MemLock lock, MemUnlock unlock) noexcept{
|
|
||||||
GlobalMemFuncs<void>::alloc = alloc;
|
|
||||||
GlobalMemFuncs<void>::free = free;
|
|
||||||
GlobalMemFuncs<void>::lock = lock;
|
|
||||||
GlobalMemFuncs<void>::unlock = unlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void resetMemFuncs() noexcept{
|
|
||||||
#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
GlobalMemFuncs<void>::alloc = GlobalMemFuncs<void>::defAlloc;
|
|
||||||
GlobalMemFuncs<void>::free = GlobalMemFuncs<void>::defFree;
|
|
||||||
GlobalMemFuncs<void>::lock = GlobalMemFuncs<void>::defLock;
|
|
||||||
GlobalMemFuncs<void>::unlock = GlobalMemFuncs<void>::defUnlock;
|
|
||||||
#elif defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
GlobalMemFuncs<void>::alloc = nullptr;
|
|
||||||
GlobalMemFuncs<void>::free = nullptr;
|
|
||||||
GlobalMemFuncs<void>::lock = nullptr;
|
|
||||||
GlobalMemFuncs<void>::unlock = nullptr;
|
|
||||||
#else
|
|
||||||
# error "resetMemFuncs for your platform here"
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static Handle alloc(UInt32 size){
|
|
||||||
auto h = GlobalMemFuncs<void>::alloc(size);
|
|
||||||
if (!h){
|
|
||||||
throw std::bad_alloc();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Handle(h);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void* lock(Handle handle) noexcept{
|
|
||||||
return GlobalMemFuncs<void>::lock(handle.raw());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void unlock(Handle handle) noexcept{
|
|
||||||
GlobalMemFuncs<void>::unlock(handle.raw());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void free(Handle handle) noexcept{
|
|
||||||
GlobalMemFuncs<void>::free(handle.raw());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static inline T* typeLock(Handle handle) noexcept{
|
|
||||||
return static_cast<T*>(lock(handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A lock that can contain either handle or raw pointer.
|
|
||||||
/// Locks and unlocks handle, noop for pointer.
|
|
||||||
template<typename T>
|
|
||||||
class MaybeLock {
|
|
||||||
|
|
||||||
public:
|
|
||||||
constexpr MaybeLock() noexcept :
|
|
||||||
m_handle(), m_pointer(nullptr){}
|
|
||||||
|
|
||||||
MaybeLock(Handle h) noexcept :
|
|
||||||
m_handle(h), m_pointer(typeLock<T>(h)){}
|
|
||||||
|
|
||||||
constexpr MaybeLock(T* ptr) noexcept :
|
|
||||||
m_handle(), m_pointer(ptr){}
|
|
||||||
|
|
||||||
~MaybeLock(){
|
|
||||||
unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
MaybeLock(const MaybeLock& o) noexcept :
|
|
||||||
m_handle(o.m_handle), m_pointer(o.m_handle ? typeLock<T>(o.m_handle) : o.m_pointer){}
|
|
||||||
|
|
||||||
MaybeLock& operator=(const MaybeLock& o) noexcept{
|
|
||||||
if (&o != this){
|
|
||||||
unlock();
|
|
||||||
|
|
||||||
m_handle = o.m_handle;
|
|
||||||
m_pointer = m_handle ? typeLock<T>(m_handle) : o.m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MaybeLock(MaybeLock&& o) noexcept :
|
|
||||||
m_handle(o.m_handle), m_pointer(o.m_pointer){
|
|
||||||
|
|
||||||
o.m_handle = Handle();
|
|
||||||
o.m_pointer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
MaybeLock& operator=(MaybeLock&& o) noexcept{
|
|
||||||
if (&o != this){
|
|
||||||
unlock();
|
|
||||||
|
|
||||||
m_handle = o.m_handle;
|
|
||||||
m_pointer = o.m_pointer;
|
|
||||||
|
|
||||||
o.m_handle = Handle();
|
|
||||||
o.m_pointer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* data() const noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T*() const noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* operator->() noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* operator->() const noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasData() const noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator bool() const noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void unlock() noexcept{
|
|
||||||
if (m_handle){
|
|
||||||
Detail::unlock(m_handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Handle m_handle;
|
|
||||||
T* m_pointer;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Simple handle lock.
|
|
||||||
/// Locks on creation and unlocks on destruction.
|
|
||||||
template<typename T>
|
|
||||||
class Lock {
|
|
||||||
|
|
||||||
public:
|
|
||||||
constexpr Lock() noexcept :
|
|
||||||
m_handle(), m_pointer(nullptr){}
|
|
||||||
|
|
||||||
Lock(Handle h) noexcept :
|
|
||||||
m_handle(h), m_pointer(typeLock<T>(h)){}
|
|
||||||
|
|
||||||
~Lock(){
|
|
||||||
unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Lock(const Lock& o) noexcept :
|
|
||||||
m_handle(o.m_handle), m_pointer(typeLock<T>(o.m_handle)){}
|
|
||||||
|
|
||||||
Lock& operator=(const Lock& o) noexcept{
|
|
||||||
if (&o != this){
|
|
||||||
unlock();
|
|
||||||
|
|
||||||
m_handle = o.m_handle;
|
|
||||||
m_pointer = typeLock<T>(m_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Lock(Lock&& o) noexcept :
|
|
||||||
m_handle(o.m_handle), m_pointer(o.m_pointer){
|
|
||||||
|
|
||||||
o.m_handle = Handle();
|
|
||||||
o.m_pointer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Lock& operator=(Lock&& o) noexcept{
|
|
||||||
if (&o != this){
|
|
||||||
unlock();
|
|
||||||
|
|
||||||
m_handle = o.m_handle;
|
|
||||||
m_pointer = o.m_pointer;
|
|
||||||
|
|
||||||
o.m_handle = Handle();
|
|
||||||
o.m_pointer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
T* data() const noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T*() const noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* operator->() noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* operator->() const noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasData() const noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator bool() const noexcept{
|
|
||||||
return m_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void unlock() noexcept{
|
|
||||||
if (m_handle){
|
|
||||||
Detail::unlock(m_handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Handle m_handle;
|
|
||||||
T* m_pointer;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Owns a handle and frees it upon destruction,
|
|
||||||
/// unless `release` is called beforehand.
|
|
||||||
class UniqueHandle {
|
|
||||||
|
|
||||||
public:
|
|
||||||
constexpr UniqueHandle(Handle h = Handle()) noexcept :
|
|
||||||
m_handle(h){}
|
|
||||||
|
|
||||||
~UniqueHandle(){
|
|
||||||
free();
|
|
||||||
}
|
|
||||||
|
|
||||||
UniqueHandle(const UniqueHandle&) = delete;
|
|
||||||
UniqueHandle& operator=(const UniqueHandle&) = delete;
|
|
||||||
|
|
||||||
UniqueHandle(UniqueHandle&& o) noexcept :
|
|
||||||
m_handle(o.m_handle){
|
|
||||||
|
|
||||||
o.m_handle = Handle();
|
|
||||||
}
|
|
||||||
|
|
||||||
UniqueHandle& operator=(UniqueHandle&& o) noexcept{
|
|
||||||
if (&o != this){
|
|
||||||
free();
|
|
||||||
|
|
||||||
m_handle = o.m_handle;
|
|
||||||
|
|
||||||
o.m_handle = Handle();
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator bool() const noexcept{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The contained handle.
|
|
||||||
Handle get() noexcept{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The contained handle.
|
|
||||||
Handle get() const noexcept{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Releases the contained handle, making the user responsible for freeing it.
|
|
||||||
Handle release() noexcept{
|
|
||||||
Handle ret = m_handle;
|
|
||||||
m_handle = Handle();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
Lock<T> lock() const{
|
|
||||||
return m_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void free() noexcept{
|
|
||||||
#if defined(TWPP_IS_DS)
|
|
||||||
if (m_handle && m_handle != GlobalMemFuncs<void>::doNotFreeHandle){
|
|
||||||
#else
|
|
||||||
if (m_handle){
|
|
||||||
#endif
|
|
||||||
Detail::free(m_handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Handle m_handle;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_MEMORYOPS_HPP
|
|
||||||
|
|
|
@ -1,145 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_PALETTE8_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_PALETTE8_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
// specialization for Element8
|
|
||||||
// we also want to set index of the element when placing it inside array
|
|
||||||
template<std::size_t arraySize, UInt8... i>
|
|
||||||
struct FixedArrayData<Element8, arraySize, IndexList<i...> > {
|
|
||||||
|
|
||||||
static constexpr Element8 updateIndex(UInt8 index, const Element8& e) noexcept{
|
|
||||||
return Element8(index, e.channel1(), e.channel2(), e.channel3());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t inputSize>
|
|
||||||
constexpr FixedArrayData(const Element8(& arr)[inputSize]) noexcept :
|
|
||||||
m_arr{updateIndex(i, FixedArrayFlat<Element8, arraySize>(arr)[i])...}{}
|
|
||||||
|
|
||||||
constexpr FixedArrayData() noexcept :
|
|
||||||
m_arr{Element8(i)...}{}
|
|
||||||
|
|
||||||
Element8 m_arr[arraySize];
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Palette information for memory transfers
|
|
||||||
class Palette8 {
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum class Type : UInt16 {
|
|
||||||
Rgb = 0,
|
|
||||||
Gray = 1,
|
|
||||||
Cmy = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef Element8 Element8Arr256[256];
|
|
||||||
|
|
||||||
/// Creates an uninitialized palette.
|
|
||||||
constexpr Palette8() noexcept :
|
|
||||||
m_size(0), m_type(Type::Rgb), m_colors(){}
|
|
||||||
|
|
||||||
/// Creates a palette with the supplied type and elements.
|
|
||||||
template<std::size_t inputSize>
|
|
||||||
constexpr Palette8(Type type, const Element8(& colors)[inputSize]) noexcept :
|
|
||||||
m_size(inputSize), m_type(type),
|
|
||||||
m_colors(colors){
|
|
||||||
|
|
||||||
static_assert(inputSize <= 256, "too many colors");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a palette with the supplied type and elements from container.
|
|
||||||
/// \throw RangeException When there are more than 256 colors.
|
|
||||||
template<typename Container>
|
|
||||||
Palette8(Type type, const Container& colors) :
|
|
||||||
m_size(static_cast<UInt16>(colors.size())), m_type(type){
|
|
||||||
|
|
||||||
if (colors.size() > 256){
|
|
||||||
throw RangeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& array = m_colors.array();
|
|
||||||
for (UInt16 i = 0; i < m_size; i++){
|
|
||||||
array[i] = colors[i];
|
|
||||||
array[i].setIndex(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a palette with the supplied type and elements.
|
|
||||||
/// \throw RangeException When there are more than 256 colors.
|
|
||||||
Palette8(Type type, const Element8* colors, UInt16 size) :
|
|
||||||
m_size(size), m_type(type){
|
|
||||||
|
|
||||||
if (m_size > 256){
|
|
||||||
throw RangeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& array = m_colors.array();
|
|
||||||
for (UInt16 i = 0; i < m_size; i++){
|
|
||||||
array[i] = colors[i];
|
|
||||||
array[i].setIndex(static_cast<UInt8>(i)); // 0..255 max
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of elements in the palette.
|
|
||||||
constexpr UInt16 size() const noexcept{
|
|
||||||
return m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Type of palette data.
|
|
||||||
constexpr Type type() const noexcept{
|
|
||||||
return m_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Array of palette elements.
|
|
||||||
constexpr const Element8Arr256& colors() const noexcept{
|
|
||||||
return m_colors.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
UInt16 m_size;
|
|
||||||
Type m_type;
|
|
||||||
Detail::FixedArray<Element8, 256> m_colors;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_PALETTE8_HPP
|
|
||||||
|
|
|
@ -1,126 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_PASSTHROUGH_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_PASSTHROUGH_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Structure for raw comminication with device in source.
|
|
||||||
/// See manual for more information, DAT_PASSTHRU, MSG_PASSTHRU.
|
|
||||||
class PassThrough {
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum class Direction : Int32 {
|
|
||||||
Get = 1,
|
|
||||||
Set = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr PassThrough(
|
|
||||||
void* command,
|
|
||||||
UInt32 commandSize,
|
|
||||||
Direction direction,
|
|
||||||
void* data,
|
|
||||||
UInt32 dataSize,
|
|
||||||
UInt32 dataXfered
|
|
||||||
) noexcept :
|
|
||||||
m_cmd(command), m_cmdSize(commandSize),
|
|
||||||
m_direction(direction),
|
|
||||||
m_data(data), m_dataSize(dataSize), m_dataXfered(dataXfered){}
|
|
||||||
|
|
||||||
constexpr void* command() const noexcept{
|
|
||||||
return m_cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr UInt32 commandSize() const noexcept{
|
|
||||||
return m_cmdSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Container>
|
|
||||||
void setCommand(const Container& command) noexcept{
|
|
||||||
m_cmd = command.data();
|
|
||||||
m_cmdSize = sizeof(Container::value_type) * command.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCommand(void* command, UInt32 size) noexcept{
|
|
||||||
m_cmd = command;
|
|
||||||
m_cmdSize = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr Direction direction() const noexcept{
|
|
||||||
return m_direction;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDirection(Direction direction) noexcept{
|
|
||||||
m_direction = direction;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr void* data() const noexcept{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr UInt32 dataSize() const noexcept{
|
|
||||||
return m_dataSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Container>
|
|
||||||
void setData(const Container& data) noexcept{
|
|
||||||
m_data = data.data();
|
|
||||||
m_dataSize = sizeof(Container::value_type) * data.size();
|
|
||||||
m_dataXfered = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setData(void* data, UInt32 dataSize) noexcept{
|
|
||||||
m_data = data;
|
|
||||||
m_dataSize = dataSize;
|
|
||||||
m_dataXfered = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr UInt32 dataXfered() const noexcept{
|
|
||||||
return m_dataXfered;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDataXfered(Int32 dataXfered) noexcept{
|
|
||||||
m_dataXfered = dataXfered;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void* m_cmd;
|
|
||||||
UInt32 m_cmdSize;
|
|
||||||
Direction m_direction;
|
|
||||||
void* m_data;
|
|
||||||
UInt32 m_dataSize;
|
|
||||||
UInt32 m_dataXfered;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_PASSTHROUGH_HPP
|
|
|
@ -1,86 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_PENDINGXFERS_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_PENDINGXFERS_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Reports number of pending images, transfers.
|
|
||||||
class PendingXfers {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Job control settings.
|
|
||||||
enum class JobPatch : UInt32 {
|
|
||||||
None = 0x0000,
|
|
||||||
MidSeparator = 0x0001,
|
|
||||||
P1 = 0x0002,
|
|
||||||
P2 = 0x0003,
|
|
||||||
P3 = 0x0004,
|
|
||||||
P4 = 0x0005,
|
|
||||||
P6 = 0x0006,
|
|
||||||
PT = 0x0007
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Creates object to report number of pending transfers.
|
|
||||||
/// \param count Number of pending transfers.
|
|
||||||
/// \param patch Job control settings.
|
|
||||||
constexpr PendingXfers(UInt16 count = 0, JobPatch patch = JobPatch::None) noexcept :
|
|
||||||
m_count(count), m_eoj(patch){}
|
|
||||||
|
|
||||||
/// Number of pending images/transfers.
|
|
||||||
constexpr UInt16 count() const noexcept{
|
|
||||||
return m_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets number of pending images/transfers.
|
|
||||||
void setCount(UInt16 count) noexcept{
|
|
||||||
m_count = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Job control settings.
|
|
||||||
constexpr JobPatch jobPatch() const noexcept{
|
|
||||||
return m_eoj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets job control settings.
|
|
||||||
void setJobPatch(JobPatch eoj) noexcept{
|
|
||||||
m_eoj = eoj;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
UInt16 m_count;
|
|
||||||
JobPatch m_eoj;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_PENDINGXFERS_HPP
|
|
|
@ -1,103 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015-2017 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_SETUPFILEXFER_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_SETUPFILEXFER_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Structure for setting up file transfer.
|
|
||||||
class SetupFileXfer {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates zero-initialized instance.
|
|
||||||
constexpr SetupFileXfer() noexcept :
|
|
||||||
m_format(ImageFileFormat::Tiff), m_volRefNum(0){}
|
|
||||||
|
|
||||||
/// Creates instance with set file path and format.
|
|
||||||
/// And volume reference number on Mac OS.
|
|
||||||
/// \param filePath Path to transfered file.
|
|
||||||
/// \param format File format.
|
|
||||||
/// \param vrn Volume reference number. Mac OS only.
|
|
||||||
constexpr SetupFileXfer(
|
|
||||||
const Str255& filePath,
|
|
||||||
ImageFileFormat format,
|
|
||||||
Int16 vrn
|
|
||||||
#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
= -1
|
|
||||||
#elif !defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
# error "Volume reference number for your platform here"
|
|
||||||
#endif
|
|
||||||
) noexcept :
|
|
||||||
m_filePath(filePath), m_format(format),
|
|
||||||
m_volRefNum(vrn){}
|
|
||||||
|
|
||||||
/// Path to transfered file.
|
|
||||||
constexpr const Str255& filePath() const noexcept{
|
|
||||||
return m_filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets path to transfered file.
|
|
||||||
void setFilePath(const Str255& filePath) noexcept{
|
|
||||||
m_filePath = filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Format of the transfered file.
|
|
||||||
constexpr ImageFileFormat format() const noexcept{
|
|
||||||
return m_format;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets format of the transfered file.
|
|
||||||
void setFormat(ImageFileFormat format) noexcept{
|
|
||||||
m_format = format;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Volume reference number.
|
|
||||||
/// Mac OS only.
|
|
||||||
constexpr Int16 volumeReferenceNumber() const noexcept{
|
|
||||||
return m_volRefNum;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets volume reference number.
|
|
||||||
/// Mac OS only.
|
|
||||||
void setVolumeReferenceNumber(Int16 volumeReferenceNumber) noexcept{
|
|
||||||
m_volRefNum = volumeReferenceNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Str255 m_filePath;
|
|
||||||
ImageFileFormat m_format;
|
|
||||||
Int16 m_volRefNum;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_SETUPFILEXFER_HPP
|
|
|
@ -1,92 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_SETUPMEMXFER_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_SETUPMEMXFER_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Structure for setting up memory transfer.
|
|
||||||
class SetupMemXfer {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates zero-initialized instance.
|
|
||||||
constexpr SetupMemXfer() noexcept :
|
|
||||||
m_minSize(0), m_maxSize(0), m_prefSize(0){}
|
|
||||||
|
|
||||||
/// Creates an initialized instance with set minimal, maximal and preferred sizes.
|
|
||||||
/// Must be true, or the behaviour is undefined: minSize <= preferredSize <= maxSize
|
|
||||||
constexpr SetupMemXfer(
|
|
||||||
UInt32 minSize,
|
|
||||||
UInt32 maxSize,
|
|
||||||
UInt32 preferredSize
|
|
||||||
) noexcept :
|
|
||||||
m_minSize(minSize), m_maxSize(maxSize), m_prefSize(preferredSize){}
|
|
||||||
|
|
||||||
/// Minimal supported buffer size in bytes.
|
|
||||||
constexpr UInt32 minSize() const noexcept{
|
|
||||||
return m_minSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets minimal supported buffer size in bytes.
|
|
||||||
void setMinSize(UInt32 minSize) noexcept{
|
|
||||||
m_minSize = minSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Maximal supported buffer size in bytes.
|
|
||||||
constexpr UInt32 maxSize() const noexcept{
|
|
||||||
return m_maxSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets maximal supported buffer size in bytes.
|
|
||||||
void setMaxSize(UInt32 maxSize) noexcept{
|
|
||||||
m_maxSize = maxSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Preferred buffer size in bytes.
|
|
||||||
constexpr UInt32 preferredSize() const noexcept{
|
|
||||||
return m_prefSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets preferred buffer size in bytes.
|
|
||||||
void setPreferredSize(UInt32 prefSize) noexcept{
|
|
||||||
m_prefSize = prefSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
UInt32 m_minSize;
|
|
||||||
UInt32 m_maxSize;
|
|
||||||
UInt32 m_prefSize;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_SETUPMEMXFER_HPP
|
|
|
@ -1,230 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_STATUS_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_STATUS_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Additional status information about a performed TWAIN operation.
|
|
||||||
class Status {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates operation status.
|
|
||||||
/// \param cond Status condition code.
|
|
||||||
/// \param data Additional status data, source-specific.
|
|
||||||
constexpr Status(CC cond = CC::Success, UInt16 data = 0) noexcept :
|
|
||||||
m_cond(cond), m_data(data){}
|
|
||||||
|
|
||||||
/// Status condition code.
|
|
||||||
constexpr CC condition() const noexcept{
|
|
||||||
return m_cond;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets status condition code.
|
|
||||||
void setCondition(CC cc) noexcept{
|
|
||||||
m_cond = cc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Aditional status data, source-specific.
|
|
||||||
constexpr UInt16 data() const noexcept{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets aditional status data, source-specific.
|
|
||||||
void setData(UInt16 data) noexcept{
|
|
||||||
m_data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr operator CC() const noexcept{
|
|
||||||
return m_cond;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr operator bool() const noexcept{
|
|
||||||
return success(m_cond);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool operator==(CC o) const noexcept{return m_cond == o;}
|
|
||||||
constexpr bool operator!=(CC o) const noexcept{return m_cond != o;}
|
|
||||||
|
|
||||||
constexpr bool operator==(Status o) const noexcept{return m_cond == o.m_cond && m_data == o.m_data;}
|
|
||||||
constexpr bool operator!=(Status o) const noexcept{return m_cond != o.m_cond || m_data != o.m_data;}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
CC m_cond;
|
|
||||||
UInt16 m_data;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline constexpr bool success(Status stat) noexcept{
|
|
||||||
return stat;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Structure for translating status to UTF8 text.
|
|
||||||
class StatusUtf8 {
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef Detail::Lock<const char> ConstString;
|
|
||||||
|
|
||||||
|
|
||||||
/// Creates a status utf8 without string data.
|
|
||||||
StatusUtf8(Status status = Status()) noexcept :
|
|
||||||
m_status(status), m_size(0), m_string(){}
|
|
||||||
|
|
||||||
/// Creates a status utf8 containing copy of string data.
|
|
||||||
/// The string must be null-terminated.
|
|
||||||
/// \tparam inputSize Size of the string including null terminator.
|
|
||||||
/// \param str The string, must be null-terminated.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
template<UInt32 inputSize>
|
|
||||||
StatusUtf8(Status status, const char(& str)[inputSize]) :
|
|
||||||
m_status(status), m_size(inputSize), m_string(Detail::alloc(inputSize)){
|
|
||||||
|
|
||||||
std::copy(str, str + inputSize, string().data());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new status utf8 containing a copy of the supplied string.
|
|
||||||
/// \param status
|
|
||||||
/// \param str Utf-8 string to copy, must be null-terminated.
|
|
||||||
/// \throw RangeException When string is too long, could not insert null terminator.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
StatusUtf8(Status status, const char* str) :
|
|
||||||
m_status(status), m_size(0), m_string(){
|
|
||||||
|
|
||||||
auto len = strlen(str);
|
|
||||||
if (len >= std::numeric_limits<UInt32>::max()){
|
|
||||||
throw RangeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_size = static_cast<UInt32>(len) + 1;
|
|
||||||
m_string = Detail::alloc(m_size);
|
|
||||||
std::copy(str, str + len + 1, m_string.lock<char>().data());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new status utf8 containing a copy of the supplied string.
|
|
||||||
/// \param status
|
|
||||||
/// \param str Utf-8 string to copy.
|
|
||||||
/// \throw RangeException When string is too long, could not insert null terminator.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
StatusUtf8(Status status, const std::string& str) :
|
|
||||||
m_status(status), m_size(0), m_string(){
|
|
||||||
|
|
||||||
auto len = str.length();
|
|
||||||
if (len >= std::numeric_limits<UInt32>::max()){
|
|
||||||
throw RangeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_size = static_cast<UInt32>(len) + 1;
|
|
||||||
m_string = Detail::alloc(m_size);
|
|
||||||
|
|
||||||
auto lock = m_string.lock<char>();
|
|
||||||
std::copy(str.cbegin(), str.cend(), lock.data());
|
|
||||||
lock[len] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new StatusUtf8 containing a copy of the supplied string.
|
|
||||||
/// \param status
|
|
||||||
/// \param str Utf-8 string to copy, null terminator is not required.
|
|
||||||
/// \param strSize {Number of bytes to copy including null terminator.
|
|
||||||
/// Null terminator is inserted automatically.}
|
|
||||||
/// \throw RangeException When string is too short to satisfy the requested size.
|
|
||||||
/// \throw std::bad_alloc
|
|
||||||
StatusUtf8(Status status, const char* str, UInt32 strSize) :
|
|
||||||
m_status(status), m_size(0), m_string(){
|
|
||||||
|
|
||||||
auto len = strlen(str);
|
|
||||||
if (len < strSize){
|
|
||||||
throw RangeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_size = static_cast<UInt32>(strSize) + 1;
|
|
||||||
m_string = Detail::alloc(m_size);
|
|
||||||
|
|
||||||
auto lock = m_string.lock<char>();
|
|
||||||
std::copy(str, str + strSize, lock.data());
|
|
||||||
lock[strSize] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
StatusUtf8(const StatusUtf8&) = delete;
|
|
||||||
StatusUtf8& operator=(const StatusUtf8&) = delete;
|
|
||||||
|
|
||||||
StatusUtf8(StatusUtf8&& o) noexcept :
|
|
||||||
m_status(o.m_status), m_size(o.m_size), m_string(std::move(o.m_string)){
|
|
||||||
|
|
||||||
o.m_status = Status();
|
|
||||||
o.m_size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
StatusUtf8& operator=(StatusUtf8&& o) noexcept{
|
|
||||||
if (&o != this){
|
|
||||||
m_status = o.m_status;
|
|
||||||
m_size = o.m_size;
|
|
||||||
m_string = std::move(o.m_string);
|
|
||||||
|
|
||||||
o.m_status = Status();
|
|
||||||
o.m_size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the interpreted status.
|
|
||||||
Status status() const noexcept{
|
|
||||||
return m_status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the status to be interpreted.
|
|
||||||
void setStatus(Status status) noexcept{
|
|
||||||
m_status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the total number of bytes including null byte.
|
|
||||||
UInt32 size() const noexcept{
|
|
||||||
return m_string ? m_size : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The UTF8 string itself.
|
|
||||||
ConstString string() const noexcept{
|
|
||||||
return m_string.lock<const char>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Status m_status;
|
|
||||||
UInt32 m_size;
|
|
||||||
Detail::UniqueHandle m_string;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_STATUS_HPP
|
|
||||||
|
|
|
@ -1,310 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015-2017 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_STRINGS_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_STRINGS_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
// specialization for twain strings
|
|
||||||
// on mac os, these strings do not contain null terminator
|
|
||||||
// instead, the first byte contains the length
|
|
||||||
template<std::size_t arraySize, std::size_t... i>
|
|
||||||
struct FixedArrayData<char, arraySize, IndexList<i...> > {
|
|
||||||
|
|
||||||
template<std::size_t inputSize>
|
|
||||||
constexpr FixedArrayData(const char(& arr)[inputSize]) noexcept :
|
|
||||||
m_arr{
|
|
||||||
#if defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
unsignedToSigned<unsigned char>(inputSize - 1),
|
|
||||||
#elif !defined(TWPP_DETAIL_OS_WIN) && !defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
# error "string data setup for yout platform here"
|
|
||||||
#endif
|
|
||||||
FixedArrayFlat<char, arraySize>(arr)[i]...
|
|
||||||
}{}
|
|
||||||
|
|
||||||
constexpr FixedArrayData() noexcept :
|
|
||||||
m_arr(){}
|
|
||||||
|
|
||||||
char m_arr[arraySize];
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// specialization for twain strings
|
|
||||||
// on mac os, these strings do not contain null terminator
|
|
||||||
// instead, the first byte contains the length
|
|
||||||
// so we provide one less index for the fixed array
|
|
||||||
// on windows, its element is zero-initialized due to it not being specified
|
|
||||||
// on mac os, the first byte contains the length, so the index is not used anyway
|
|
||||||
template<std::size_t arraySize>
|
|
||||||
struct FixedArray<char, arraySize> : public FixedArrayData<char, arraySize, typename Indexes<arraySize - 1>::Result> {
|
|
||||||
|
|
||||||
typedef FixedArrayData<char, arraySize, typename Indexes<arraySize - 1>::Result> ParentType;
|
|
||||||
typedef char Array[arraySize];
|
|
||||||
|
|
||||||
constexpr FixedArray() noexcept :
|
|
||||||
ParentType(){}
|
|
||||||
|
|
||||||
template<std::size_t inputSize>
|
|
||||||
constexpr FixedArray(const char(& arr)[inputSize]) noexcept :
|
|
||||||
ParentType(arr){
|
|
||||||
|
|
||||||
static_assert(inputSize <= arraySize, "string literal is too long");
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr const Array& array() const noexcept{
|
|
||||||
return ParentType::m_arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Array& array() noexcept{
|
|
||||||
return ParentType::m_arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// TWAIN string template.
|
|
||||||
/// \tparam arraySize String capacity, including either null byte, or length byte (Mac OS).
|
|
||||||
template<std::size_t arraySize>
|
|
||||||
class Str : private FixedArray<char, arraySize>{
|
|
||||||
|
|
||||||
typedef FixedArray<char, arraySize> DataType;
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef const char* const_iterator;
|
|
||||||
typedef char* iterator;
|
|
||||||
|
|
||||||
/// Maximal number of characters this string may hold.
|
|
||||||
/// Excluding null byte (length byte).
|
|
||||||
static constexpr UInt32 maxSize() noexcept{
|
|
||||||
return arraySize - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static_assert(maxSize() <= std::numeric_limits<unsigned char>::max(), "string type exceeds allowed sizes");
|
|
||||||
|
|
||||||
|
|
||||||
/// Creates an empty, zero-initialized string.
|
|
||||||
constexpr Str() noexcept{}
|
|
||||||
|
|
||||||
/// Creates a compile-time string from string literal (or char array).
|
|
||||||
/// \tparam inputSize Size of the string literal including null terminator.
|
|
||||||
/// \param str The string literal.
|
|
||||||
template<std::size_t inputSize>
|
|
||||||
constexpr Str(const char(& str)[inputSize]) noexcept :
|
|
||||||
DataType(str){
|
|
||||||
|
|
||||||
static_assert(inputSize <= arraySize, "string literal is too long");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Alias to length().
|
|
||||||
constexpr UInt32 size() const noexcept{
|
|
||||||
return length();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Length of the string (number of 8-bit characters).
|
|
||||||
/// O(1) on Mac OS, O(n) anywhere else.
|
|
||||||
constexpr UInt32 length() const noexcept{
|
|
||||||
#if defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
return static_cast<unsigned const char>(this->array()[0]);
|
|
||||||
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
return strLen(data());
|
|
||||||
#else
|
|
||||||
# error "String::length for your platform here"
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pointer to constant data.
|
|
||||||
/// On Mac OS, the data is NOT null-terminated,
|
|
||||||
/// and points to the first character after size byte.
|
|
||||||
/// This operation is unsafe, and its use may not be platform-independent.
|
|
||||||
constexpr const char* data() const noexcept{
|
|
||||||
#if defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
return this->array() + 1;
|
|
||||||
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
return this->array();
|
|
||||||
#else
|
|
||||||
# error "String::data for your platform here"
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pointer to data.
|
|
||||||
/// On Mac OS, the data is NOT null-terminated,
|
|
||||||
/// and points to the first character after size byte.
|
|
||||||
/// This operation is unsafe, and its use may not be platform-independent.
|
|
||||||
char* data() noexcept{
|
|
||||||
#if defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
return this->array() + 1;
|
|
||||||
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
return this->array();
|
|
||||||
#else
|
|
||||||
# error "String::data for your platform here"
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets string data.
|
|
||||||
/// Copies as much data as possible, discarding the rest.
|
|
||||||
/// The data needn't be null terminated.
|
|
||||||
/// \param str Data to copy.
|
|
||||||
/// \param size Maximal number of bytes to copy.
|
|
||||||
/// \return Number of bytes copied - the new length of this string.
|
|
||||||
UInt32 setData(const char* data, UInt32 size) noexcept{
|
|
||||||
char* arr = this->data();
|
|
||||||
UInt32 i = 0;
|
|
||||||
|
|
||||||
auto maxLen = std::min(maxSize(), size);
|
|
||||||
for ( ; i < maxLen && *data; i++, data++){
|
|
||||||
arr[i] = *data;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
*reinterpret_cast<unsigned char*>(this->array()) = static_cast<unsigned char>(i);
|
|
||||||
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
arr[i] = '\0';
|
|
||||||
#else
|
|
||||||
# error "String::setData for your platform here"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets string data.
|
|
||||||
/// Copies as much data as possible, discarding the rest.
|
|
||||||
/// The string must be null terminated.
|
|
||||||
/// \param str String to copy.
|
|
||||||
/// \return Number of characters copied - the new length of this string.
|
|
||||||
UInt32 setData(const char* str) noexcept{
|
|
||||||
return setData(str, maxSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets string data from container (e.g. std::string).
|
|
||||||
/// Copies as much data as possible, discarding the rest.
|
|
||||||
/// The string needn't be null terminated.
|
|
||||||
/// \tparam Contaier Container type.
|
|
||||||
/// \param cont Container with data to be copied.
|
|
||||||
/// \return Number of characters copied - the new length of this string.
|
|
||||||
template<typename Container, typename = typename std::enable_if<std::is_same<typename Container::value_type, char>::value>::type>
|
|
||||||
UInt32 setData(const Container& cont) noexcept{
|
|
||||||
return setData(cont.data(), static_cast<UInt32>(std::min<typename Container::size_type>(cont.size(), maxSize())));
|
|
||||||
}
|
|
||||||
|
|
||||||
char operator[](UInt32 i) const noexcept{
|
|
||||||
return data()[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
char& operator[](UInt32 i) noexcept{
|
|
||||||
return data()[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator begin() noexcept{
|
|
||||||
return data();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr const_iterator begin() const noexcept{
|
|
||||||
return cbegin();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr const_iterator cbegin() const noexcept{
|
|
||||||
return data();
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator end() noexcept{
|
|
||||||
return data() + length();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr const_iterator end() const noexcept{
|
|
||||||
return cend();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr const_iterator cend() const noexcept{
|
|
||||||
return data() + length();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string string() const{
|
|
||||||
return std::string(cbegin(), cend());
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t sizeA, std::size_t sizeB>
|
|
||||||
constexpr bool operator==(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
|
|
||||||
// length() is O(1) on mac os, O(n) anywhere else
|
|
||||||
#if defined(TWPP_DETAIL_OS_MAC)
|
|
||||||
return a.length() == b.length() && Detail::strCmp(a.data(), b.data()) == 0;
|
|
||||||
#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
return Detail::strCmp(a.data(), b.data()) == 0;
|
|
||||||
#else
|
|
||||||
# error "String equals operator for your platform here"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t sizeA, std::size_t sizeB>
|
|
||||||
constexpr bool operator<(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
|
|
||||||
return Detail::strCmp(a.data(), b.data()) < 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t sizeA, std::size_t sizeB>
|
|
||||||
constexpr bool operator>(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
|
|
||||||
return Detail::strCmp(a.data(), b.data()) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t sizeA, std::size_t sizeB>
|
|
||||||
constexpr bool operator!=(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t sizeA, std::size_t sizeB>
|
|
||||||
constexpr bool operator<=(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
|
|
||||||
return !(a > b);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t sizeA, std::size_t sizeB>
|
|
||||||
constexpr bool operator>=(const Detail::Str<sizeA>& a, const Detail::Str<sizeB>& b) noexcept{
|
|
||||||
return !(a < b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// TWAIN string that can contain up to 33 characters (bytes).
|
|
||||||
typedef Detail::Str<34> Str32;
|
|
||||||
|
|
||||||
/// TWAIN string that can contain up to 65 characters (bytes).
|
|
||||||
typedef Detail::Str<66> Str64;
|
|
||||||
|
|
||||||
/// TWAIN string that can contain up to 129 characters (bytes).
|
|
||||||
typedef Detail::Str<130> Str128;
|
|
||||||
|
|
||||||
/// TWAIN string that can contain up to 255 characters (bytes).
|
|
||||||
typedef Detail::Str<256> Str255;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_STRINGS_HPP
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
#ifndef TWGLUE_HPP
|
|
||||||
#define TWGLUE_HPP
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
// #include "Device/PublicFunc.h"
|
|
||||||
|
|
||||||
struct TwGlue {
|
|
||||||
|
|
||||||
TwGlue(const std::function<void(const GScanCap&)>& scan, const std::function<void()>& cancel) :
|
|
||||||
m_scan(scan), m_cancel(cancel){}
|
|
||||||
|
|
||||||
std::function<void(const GScanCap&)> m_scan;
|
|
||||||
std::function<void()> m_cancel;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // TWGLUE_HPP
|
|
|
@ -1,88 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_TYPES_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_TYPES_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
typedef std::uintptr_t UIntPtr;
|
|
||||||
typedef std::uint8_t UInt8;
|
|
||||||
typedef std::uint16_t UInt16;
|
|
||||||
typedef std::uint32_t UInt32;
|
|
||||||
typedef std::int8_t Int8;
|
|
||||||
typedef std::int16_t Int16;
|
|
||||||
typedef std::int32_t Int32;
|
|
||||||
|
|
||||||
/// Boolean value.
|
|
||||||
/// Implemented as a class to provide better type safety.
|
|
||||||
class Bool {
|
|
||||||
|
|
||||||
public:
|
|
||||||
constexpr Bool(bool value = false) noexcept :
|
|
||||||
m_value(value){}
|
|
||||||
|
|
||||||
constexpr operator bool() const noexcept{
|
|
||||||
return m_value != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Int16 m_value;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Handle to memory area.
|
|
||||||
/// Implemented as a class to provide better type safety.
|
|
||||||
class Handle {
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef Detail::RawHandle Raw;
|
|
||||||
|
|
||||||
constexpr explicit Handle(Raw raw = Raw()) noexcept :
|
|
||||||
m_raw(raw){}
|
|
||||||
|
|
||||||
/// Underlying OS-dependent handle.
|
|
||||||
constexpr Raw raw() const noexcept{
|
|
||||||
return m_raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr operator bool() const noexcept{
|
|
||||||
return m_raw != Raw();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Raw m_raw;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_TYPES_HPP
|
|
||||||
|
|
|
@ -1,149 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_TYPESOPS_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_TYPESOPS_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
/// Enumeration representing basic types.
|
|
||||||
enum class Type : UInt16 {
|
|
||||||
DontCare = 0xFFFF,
|
|
||||||
Int8 = 0x0000,
|
|
||||||
Int16 = 0x0001,
|
|
||||||
Int32 = 0x0002,
|
|
||||||
UInt8 = 0x0003,
|
|
||||||
UInt16 = 0x0004,
|
|
||||||
UInt32 = 0x0005,
|
|
||||||
Bool = 0x0006,
|
|
||||||
Fix32 = 0x0007,
|
|
||||||
Frame = 0x0008,
|
|
||||||
Str32 = 0x0009,
|
|
||||||
Str64 = 0x000a,
|
|
||||||
Str128 = 0x000b,
|
|
||||||
Str255 = 0x000c,
|
|
||||||
Handle = 0x000f
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Whether the enum value actually is a type, DontCare is not a type.
|
|
||||||
static inline bool isType(Type type){
|
|
||||||
switch (type){
|
|
||||||
case Type::Int8:
|
|
||||||
case Type::UInt8:
|
|
||||||
case Type::Int16:
|
|
||||||
case Type::UInt16:
|
|
||||||
case Type::Int32:
|
|
||||||
case Type::UInt32:
|
|
||||||
case Type::Bool:
|
|
||||||
case Type::Fix32:
|
|
||||||
case Type::Str32:
|
|
||||||
case Type::Str64:
|
|
||||||
case Type::Str128:
|
|
||||||
case Type::Str255:
|
|
||||||
case Type::Frame:
|
|
||||||
case Type::Handle:
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Size in bytes of a type represented by enum value.
|
|
||||||
static inline UInt32 typeSize(Type type){
|
|
||||||
switch (type){
|
|
||||||
case Type::Int8: return sizeof(Int8);
|
|
||||||
case Type::UInt8: return sizeof(UInt8);
|
|
||||||
case Type::Int16: return sizeof(Int16);
|
|
||||||
case Type::UInt16: return sizeof(UInt16);
|
|
||||||
case Type::Int32: return sizeof(Int32);
|
|
||||||
case Type::UInt32: return sizeof(UInt32);
|
|
||||||
case Type::Bool: return sizeof(Bool);
|
|
||||||
case Type::Fix32: return sizeof(Fix32);
|
|
||||||
case Type::Str32: return sizeof(Str32);
|
|
||||||
case Type::Str64: return sizeof(Str64);
|
|
||||||
case Type::Str128: return sizeof(Str128);
|
|
||||||
case Type::Str255: return sizeof(Str255);
|
|
||||||
case Type::Frame: return sizeof(Frame);
|
|
||||||
case Type::Handle: return sizeof(Handle);
|
|
||||||
default: throw TypeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
/// Conversion from Type enum to actual data type.
|
|
||||||
template<Type type> struct Twty {};
|
|
||||||
template<> struct Twty<Type::Int8> {typedef Int8 Type;};
|
|
||||||
template<> struct Twty<Type::Int16> {typedef Int16 Type;};
|
|
||||||
template<> struct Twty<Type::Int32> {typedef Int32 Type;};
|
|
||||||
template<> struct Twty<Type::UInt8> {typedef UInt8 Type;};
|
|
||||||
template<> struct Twty<Type::UInt16> {typedef UInt16 Type;};
|
|
||||||
template<> struct Twty<Type::UInt32> {typedef UInt32 Type;};
|
|
||||||
template<> struct Twty<Type::Bool> {typedef Bool Type;};
|
|
||||||
template<> struct Twty<Type::Fix32> {typedef Fix32 Type;};
|
|
||||||
template<> struct Twty<Type::Frame> {typedef Frame Type;};
|
|
||||||
template<> struct Twty<Type::Str32> {typedef Str32 Type;};
|
|
||||||
template<> struct Twty<Type::Str64> {typedef Str64 Type;};
|
|
||||||
template<> struct Twty<Type::Str128> {typedef Str128 Type;};
|
|
||||||
template<> struct Twty<Type::Str255> {typedef Str255 Type;};
|
|
||||||
template<> struct Twty<Type::Handle> {typedef Handle Type;};
|
|
||||||
|
|
||||||
|
|
||||||
// Conversion from data type to Type enum helpers.
|
|
||||||
template<typename DataType> struct Tytw;
|
|
||||||
|
|
||||||
template<typename DataType, bool isEnum> // true
|
|
||||||
struct TytwHelper : Tytw<typename std::underlying_type<DataType>::type> {};
|
|
||||||
|
|
||||||
template<typename DataType>
|
|
||||||
struct TytwHelper<DataType, false> {};
|
|
||||||
|
|
||||||
/// Conversion from data type to Type enum.
|
|
||||||
template<typename DataType> struct Tytw : TytwHelper<DataType, std::is_enum<DataType>::value> {};
|
|
||||||
template<> struct Tytw<Int8> {static constexpr const Type twty = Type::Int8;};
|
|
||||||
template<> struct Tytw<Int16> {static constexpr const Type twty = Type::Int16;};
|
|
||||||
template<> struct Tytw<Int32> {static constexpr const Type twty = Type::Int32;};
|
|
||||||
template<> struct Tytw<UInt8> {static constexpr const Type twty = Type::UInt8;};
|
|
||||||
template<> struct Tytw<UInt16> {static constexpr const Type twty = Type::UInt16;};
|
|
||||||
template<> struct Tytw<UInt32> {static constexpr const Type twty = Type::UInt32;};
|
|
||||||
template<> struct Tytw<Bool> {static constexpr const Type twty = Type::Bool;};
|
|
||||||
template<> struct Tytw<Fix32> {static constexpr const Type twty = Type::Fix32;};
|
|
||||||
template<> struct Tytw<Frame> {static constexpr const Type twty = Type::Frame;};
|
|
||||||
template<> struct Tytw<Str32> {static constexpr const Type twty = Type::Str32;};
|
|
||||||
template<> struct Tytw<Str64> {static constexpr const Type twty = Type::Str64;};
|
|
||||||
template<> struct Tytw<Str128> {static constexpr const Type twty = Type::Str128;};
|
|
||||||
template<> struct Tytw<Str255> {static constexpr const Type twty = Type::Str255;};
|
|
||||||
template<> struct Tytw<Handle> {static constexpr const Type twty = Type::Handle;};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_TYPESOPS_HPP
|
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015-2017 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_USERINTERFACE_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_USERINTERFACE_HPP
|
|
||||||
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
TWPP_DETAIL_PACK_BEGIN
|
|
||||||
/// Structure holding parameters for enabling or disabling data source.
|
|
||||||
class UserInterface {
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Creates a new UserInterface.
|
|
||||||
/// \param showUi Whether to show internal DS GUI. Disabling DS GUI might not be supported.
|
|
||||||
/// \param modalUi Whether DS GUI should be modal. Not used on Linux. Might not be supported on Windows.
|
|
||||||
/// \param parent Windows-only, others set to null. Handle to parent window. This object does NOT take ownership.
|
|
||||||
#if defined(TWPP_DETAIL_OS_WIN)
|
|
||||||
constexpr UserInterface(Bool showUi, Bool modalUi, Handle parent) noexcept :
|
|
||||||
m_showUi(showUi), m_modalUi(modalUi), m_parent(parent){}
|
|
||||||
#elif defined(TWPP_DETAIL_OS_MAC) || defined(TWPP_DETAIL_OS_LINUX)
|
|
||||||
constexpr UserInterface(Bool showUi, Bool modalUi, Handle parent = Handle()) noexcept :
|
|
||||||
m_showUi(showUi), m_modalUi(modalUi), m_parent(parent){}
|
|
||||||
#else
|
|
||||||
# error "UserInterface constructor for your platform here"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Whether to show internal DS GUI.
|
|
||||||
constexpr Bool showUi() const noexcept{
|
|
||||||
return m_showUi;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether DS GUI should be modal
|
|
||||||
constexpr Bool modalUi() const noexcept{
|
|
||||||
return m_modalUi;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handle to parent window.
|
|
||||||
constexpr Handle parent() const noexcept{
|
|
||||||
return m_parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Bool m_showUi;
|
|
||||||
Bool m_modalUi;
|
|
||||||
Handle m_parent;
|
|
||||||
|
|
||||||
};
|
|
||||||
TWPP_DETAIL_PACK_END
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_USERINTERFACE_HPP
|
|
||||||
|
|
|
@ -1,485 +0,0 @@
|
||||||
/*
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Martin Richter
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TWPP_DETAIL_FILE_UTILS_HPP
|
|
||||||
#define TWPP_DETAIL_FILE_UTILS_HPP
|
|
||||||
|
|
||||||
#undef max
|
|
||||||
#undef min
|
|
||||||
#include <limits>
|
|
||||||
#include "../twpp.hpp"
|
|
||||||
|
|
||||||
namespace Twpp {
|
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
|
|
||||||
/// Creates a template for testing whether a class contains public static method.
|
|
||||||
/// Use this macro anywhere a class may be defined, and pass method name
|
|
||||||
/// as its parameter. Then use `HasStaticMethod_<your-method-name>` template.
|
|
||||||
///
|
|
||||||
/// E. g.:
|
|
||||||
/// TWPP_DETAIL_CREATE_HAS_STATIC_METHOD(myMethod) // <- semicolon not required
|
|
||||||
/// HasStaticMethod_myMethod<MyClass, void(int, char)>::value
|
|
||||||
///
|
|
||||||
/// This test whether `MyClass` has static method `void MyClass::myMethod(int, char)`.
|
|
||||||
/// That is whether you may do this:
|
|
||||||
/// MyClass::myMethod(10, 'a');
|
|
||||||
#define TWPP_DETAIL_CREATE_HAS_STATIC_METHOD(methodName) \
|
|
||||||
template<typename T, typename Fn>\
|
|
||||||
class HasStaticMethod_ ## methodName;\
|
|
||||||
\
|
|
||||||
template<typename T, typename Ret, typename... Args>\
|
|
||||||
class HasStaticMethod_ ## methodName <T, Ret(Args...)> {\
|
|
||||||
\
|
|
||||||
template<typename U>\
|
|
||||||
static constexpr auto test(U*) ->\
|
|
||||||
typename std::is_same<decltype(U::methodName(std::declval<Args>()...)), Ret>::type;\
|
|
||||||
\
|
|
||||||
template<typename>\
|
|
||||||
static constexpr std::false_type test(...);\
|
|
||||||
\
|
|
||||||
public:\
|
|
||||||
typedef decltype(test<T>(0)) type;\
|
|
||||||
static constexpr const bool value = type::value;\
|
|
||||||
\
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Creates a template for testing whether a class contains public method.
|
|
||||||
/// Use this macro anywhere a class may be defined, and pass method name
|
|
||||||
/// as its parameter. Then use `HasMethod_<your-method-name>` template.
|
|
||||||
///
|
|
||||||
/// E. g.:
|
|
||||||
/// TWPP_DETAIL_CREATE_HAS_METHOD(myMethod) // <- semicolon not required
|
|
||||||
/// HasMethod_myMethod<MyClass, void(int, char)>::value
|
|
||||||
///
|
|
||||||
/// This test whether `MyClass` has method (AKA member function) `void MyClass::myMethod(int, char)`.
|
|
||||||
/// That is whether you may do this:
|
|
||||||
/// MyClass o ... ;
|
|
||||||
/// o.myMethod(10, 'a');
|
|
||||||
#define TWPP_DETAIL_CREATE_HAS_METHOD(methodName) \
|
|
||||||
template<typename T, typename Fn>\
|
|
||||||
class HasMethod_ ## methodName;\
|
|
||||||
\
|
|
||||||
template<typename T, typename Ret, typename... Args>\
|
|
||||||
class HasMethod_ ## methodName <T, Ret(Args...)> {\
|
|
||||||
\
|
|
||||||
template<typename U>\
|
|
||||||
static constexpr auto test(U*) ->\
|
|
||||||
typename std::is_same<decltype(std::declval<U>().methodName(std::declval<Args>()...)), Ret>::type;\
|
|
||||||
\
|
|
||||||
template<typename>\
|
|
||||||
static constexpr std::false_type test(...);\
|
|
||||||
\
|
|
||||||
public:\
|
|
||||||
typedef decltype(test<T>(0)) type;\
|
|
||||||
static constexpr const bool value = type::value;\
|
|
||||||
\
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Performs a pointer type cast, suppresses strict aliasing warnings.
|
|
||||||
/// \tparam T Type of the returned pointer. Must be pointer type (e.g. `char*`).
|
|
||||||
/// \param ptr Pointer to be cast.
|
|
||||||
/// \return Cast pointer.
|
|
||||||
template<typename T>
|
|
||||||
static constexpr inline T alias_cast(void* ptr) noexcept{
|
|
||||||
return reinterpret_cast<T>(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Performs a constant pointer type cast, suppresses strict aliasing warnings.
|
|
||||||
/// \tparam T Type of the returned pointer. Must be pointer type (e.g. `char*`).
|
|
||||||
/// \param ptr Pointer to be cast.
|
|
||||||
/// \return Cast pointer.
|
|
||||||
template<typename T>
|
|
||||||
static constexpr inline T alias_cast(const void* ptr) noexcept{
|
|
||||||
return reinterpret_cast<T>(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Suppresses warnings about unused parameters or arguments.
|
|
||||||
/// \tparam Args List of argument types. No need to specify explicitly.
|
|
||||||
template<typename... Args>
|
|
||||||
static inline void unused(const Args& ...) noexcept{}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// CODE FROM http://www.macieira.org/blog/2011/07/initialising-an-array-with-cx0x-using-constexpr-and-variadic-templates/
|
|
||||||
// BEGIN
|
|
||||||
template<std::size_t... Idx> struct IndexList {};
|
|
||||||
|
|
||||||
template<typename IndexList, std::size_t Right> struct Append;
|
|
||||||
template<std::size_t... Left, std::size_t Right>
|
|
||||||
struct Append<IndexList<Left...>, Right>{ typedef IndexList<Left..., Right> Result; };
|
|
||||||
|
|
||||||
template<std::size_t N> struct Indexes {
|
|
||||||
typedef typename Append<typename Indexes<N - 1>::Result, N - 1>::Result Result;
|
|
||||||
};
|
|
||||||
template<> struct Indexes<0> { typedef IndexList<> Result; };
|
|
||||||
// END
|
|
||||||
|
|
||||||
/// Converts an array of arbitary size to array-like recursive structure of fixed size (at compile time).
|
|
||||||
/// Provide template specialization if special handling of elements is required, and you do care
|
|
||||||
/// about their positions - otherwise see FixedArrayData below.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
/// \tparam arraySize Number of elements in the fixed array.
|
|
||||||
template<typename T, std::size_t arraySize>
|
|
||||||
struct FixedArrayFlat : FixedArrayFlat<T, arraySize - 1> {
|
|
||||||
|
|
||||||
/// The index this structure (with this `arraySize`) holds.
|
|
||||||
static constexpr const std::size_t g_index = arraySize - 1;
|
|
||||||
|
|
||||||
/// Performs the conversion from arbiraty-size array to fixed-size structure.
|
|
||||||
/// We use left recursion to initialize values of all inherited structures first.
|
|
||||||
/// Then the value of this one is initialized, either copied from the input array itself,
|
|
||||||
/// or default-initialized in case the array is not large enough.
|
|
||||||
/// \tparam inputSize {Size of the input array. If smaller than the fixed array,
|
|
||||||
/// excessive elements are default-initialized (may be changed in specializations).
|
|
||||||
/// Providing larger array results in undefined behaviour.}
|
|
||||||
/// \param arr The arbitary-size array.
|
|
||||||
template<std::size_t inputSize>
|
|
||||||
constexpr inline FixedArrayFlat(const T(& arr)[inputSize]) noexcept :
|
|
||||||
FixedArrayFlat<T, g_index>(arr), m_val(g_index < inputSize ? arr[g_index] : T()){}
|
|
||||||
|
|
||||||
/// Returns value contained at specific index.
|
|
||||||
/// If the index if smaller than the size of the input array, a value is returned
|
|
||||||
/// as if the operation was performed on that array. Otherwise a default value
|
|
||||||
/// of the type `T` is returned (or anything else a specialization provides).
|
|
||||||
/// Behaviour of this operator is undefined if the index equals to or is greater than
|
|
||||||
/// the size of the fixed array.
|
|
||||||
/// \param i Value index.
|
|
||||||
/// \return Value at index.
|
|
||||||
constexpr inline T operator[](std::size_t i) const noexcept{
|
|
||||||
return i == g_index ? m_val : FixedArrayFlat<T, g_index>::operator [](i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Value held by this structure.
|
|
||||||
T m_val;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Converts an array of arbitary size to array-like recursive structure of fixed size (at compile time).
|
|
||||||
/// This template specialization terminates the recursion.
|
|
||||||
/// No need to provide any further specializations.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
template<typename T>
|
|
||||||
struct FixedArrayFlat<T, 0> {
|
|
||||||
|
|
||||||
template<std::size_t inputSize>
|
|
||||||
constexpr inline FixedArrayFlat(const T(&)[inputSize]) noexcept{}
|
|
||||||
|
|
||||||
constexpr inline T operator[](std::size_t) const noexcept{
|
|
||||||
return T();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// Converts an array of arbitary size to array of fixed size at compile time.
|
|
||||||
/// The job itself is done in the specialization below.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
/// \tparam arraySize Number of elements in the fixed array.
|
|
||||||
/// \tparam IndexList Type holding indexes of the fixed array.
|
|
||||||
template<typename T, std::size_t arraySize, typename IndexList>
|
|
||||||
struct FixedArrayData {};
|
|
||||||
|
|
||||||
/// Converts an array of arbitary size to array of fixed size at compile time.
|
|
||||||
/// Provide template specialization if special handling of elements is required, and you
|
|
||||||
/// don't care about their positions.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
/// \tparam arraySize Number of elements in the fixed array.
|
|
||||||
/// \tparam i Indexes of the fixed array.
|
|
||||||
template<typename T, std::size_t arraySize, std::size_t... i>
|
|
||||||
struct FixedArrayData<T, arraySize, IndexList<i...> > {
|
|
||||||
|
|
||||||
/// Performs the conversion from arbiraty-size array to fixed-size array.
|
|
||||||
/// Uses FixedArrayFlat to extend the input array to desired size.
|
|
||||||
/// \tparam inputSize Size of the input array.
|
|
||||||
/// \param arr The input array.
|
|
||||||
template<std::size_t inputSize>
|
|
||||||
constexpr FixedArrayData(const T(& arr)[inputSize]) noexcept :
|
|
||||||
m_arr{FixedArrayFlat<T, arraySize>(arr)[i]...}{}
|
|
||||||
|
|
||||||
/// Creates default-initialized array.
|
|
||||||
constexpr FixedArrayData() noexcept :
|
|
||||||
m_arr(){}
|
|
||||||
|
|
||||||
/// The fixed array.
|
|
||||||
T m_arr[arraySize];
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Compile-time constructible fixed-size array of type `T` and length `arraySize`.
|
|
||||||
/// The array can be constructed from variable-sized array
|
|
||||||
/// of up to `arraySize` elements at compile time.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
/// \tparam arraySize Number of elements in the array.
|
|
||||||
template<typename T, std::size_t arraySize>
|
|
||||||
struct FixedArray : public FixedArrayData<T, arraySize, typename Indexes<arraySize>::Result> {
|
|
||||||
|
|
||||||
typedef FixedArrayData<T, arraySize, typename Indexes<arraySize>::Result> ParentType;
|
|
||||||
typedef T Array[arraySize];
|
|
||||||
|
|
||||||
/// Creates default-initialized array.
|
|
||||||
constexpr FixedArray() noexcept :
|
|
||||||
ParentType(){}
|
|
||||||
|
|
||||||
/// Creates fixed-size array from variable-size array at compile time.
|
|
||||||
/// If the size of input array exceeds `arraySize`, a compile-time error is emited.
|
|
||||||
/// \tparam inputSize Number of elements of the input array.
|
|
||||||
/// \param arr The input array.
|
|
||||||
template<std::size_t inputSize>
|
|
||||||
constexpr FixedArray(const T(& arr)[inputSize]) noexcept :
|
|
||||||
ParentType(arr){
|
|
||||||
|
|
||||||
static_assert(inputSize <= arraySize, "array literal is too big");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The contained array.
|
|
||||||
constexpr const Array& array() const noexcept{
|
|
||||||
return ParentType::m_arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The contained array.
|
|
||||||
Array& array() noexcept{
|
|
||||||
return ParentType::m_arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Joins two arrays at compile time.
|
|
||||||
/// The job itself is done in the specialization below.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
/// \tparam lenA Size of the first array.
|
|
||||||
/// \tparam lenB Size of the second array.
|
|
||||||
/// \tparam IndexList Type holding indexes of the resulting array.
|
|
||||||
template<typename T, std::size_t lenA, std::size_t lenB, typename IndexList>
|
|
||||||
struct ArrayJoinData {};
|
|
||||||
|
|
||||||
/// Joins two arrays at compile time.
|
|
||||||
/// The result of this operation is an array that contains all the elements
|
|
||||||
/// from the first array immediately followed by all the elements from
|
|
||||||
/// the second array.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
/// \tparam lenA Size of the first array.
|
|
||||||
/// \tparam lenB Size of the second array.
|
|
||||||
/// \tparam i Indexes of the resulting array.
|
|
||||||
template<typename T, std::size_t lenA, std::size_t lenB, std::size_t... i>
|
|
||||||
struct ArrayJoinData<T, lenA, lenB, IndexList<i...> > {
|
|
||||||
|
|
||||||
/// Performs the join operation.
|
|
||||||
/// \param a The first array.
|
|
||||||
/// \param b The second array.
|
|
||||||
constexpr ArrayJoinData(const T(& a)[lenA], const T(& b)[lenB]) noexcept :
|
|
||||||
m_arr{(i < lenA ? a[i] : b[i - lenA])...}{}
|
|
||||||
|
|
||||||
/// The resulting array.
|
|
||||||
T m_arr[lenA + lenB];
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Compile-time join operation of two arrays of the same type.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
/// \tparam lenA Size of the first array.
|
|
||||||
/// \tparam lenB Size of the second array.
|
|
||||||
template<typename T, std::size_t lenA, std::size_t lenB>
|
|
||||||
struct ArrayJoin : public ArrayJoinData<T, lenA, lenB, typename Indexes<lenA + lenB>::Result> {
|
|
||||||
|
|
||||||
typedef ArrayJoinData<T, lenA, lenB, typename Indexes<lenA + lenB>::Result> ParentType;
|
|
||||||
typedef T Array[lenA + lenB];
|
|
||||||
|
|
||||||
/// Performs the join operation.
|
|
||||||
/// \param a The first array.
|
|
||||||
/// \param b The second array.
|
|
||||||
constexpr ArrayJoin(const T(& a)[lenA], const T(& b)[lenB]) noexcept :
|
|
||||||
ParentType(a, b){}
|
|
||||||
|
|
||||||
/// The joined array.
|
|
||||||
constexpr const Array& array() const noexcept{
|
|
||||||
return ParentType::m_arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The joined array.
|
|
||||||
Array& array() noexcept{
|
|
||||||
return ParentType::m_arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Performs compile-time array join operation.
|
|
||||||
/// This is a helper function, see ArrayJoin and ArrayJoinData for more info.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
/// \tparam lenA Size of the first array.
|
|
||||||
/// \tparam lenB Size of the second array.
|
|
||||||
/// \param a The first array.
|
|
||||||
/// \param b The second array.
|
|
||||||
/// \return The joined array.
|
|
||||||
template<typename T, std::size_t lenA, std::size_t lenB>
|
|
||||||
static constexpr inline ArrayJoin<T, lenA, lenB> arrayJoin(const T(& a)[lenA], const T(& b)[lenB]) noexcept{
|
|
||||||
return {a, b};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// The loop that checks the suffix at compile time, see endsWith below.
|
|
||||||
/// Checks are performed from right to left.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
/// \tparam arrLen The size of the array to be checked for the suffix.
|
|
||||||
/// \tparam subLen The size of the suffix array.
|
|
||||||
/// \param arr The array to be checked for the suffix.
|
|
||||||
/// \param sub The suffix array.
|
|
||||||
/// \param endOff Offset from the last element to be checked in this call.
|
|
||||||
/// \return Whether the suffix is contained.
|
|
||||||
template<typename T, std::size_t arrLen, std::size_t subLen>
|
|
||||||
static constexpr inline bool endsWithLoop(const T(& arr)[arrLen], const T(& sub)[subLen], std::size_t endOff){
|
|
||||||
return endOff >= subLen || (arr[arrLen - 1 - endOff] == sub[subLen - 1 - endOff] && endsWithLoop(arr, sub, endOff + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks whether the input array contains supplied suffix at compile time.
|
|
||||||
/// \tparam T Element type.
|
|
||||||
/// \tparam arrLen The size of the array to be checked for the suffix.
|
|
||||||
/// \tparam subLen The size of the suffix array.
|
|
||||||
/// \param arr The array to be checked for the suffix.
|
|
||||||
/// \param sub The suffix array.
|
|
||||||
/// \return Whether the suffix is contained.
|
|
||||||
template<typename T, std::size_t arrLen, std::size_t subLen>
|
|
||||||
static constexpr inline bool endsWith(const T(& arr)[arrLen], const T(& sub)[subLen]){
|
|
||||||
return arrLen >= subLen && endsWithLoop(arr, sub, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implementation of compile-time C string length.
|
|
||||||
/// Uses tail recursion.
|
|
||||||
/// \param str The string, or its remaining part.
|
|
||||||
/// \param len Length of the previous, already processed, part of the string.
|
|
||||||
/// \return Length of the string.
|
|
||||||
static constexpr inline std::size_t strLenImpl(const char* str, std::size_t len = 0) noexcept{
|
|
||||||
return *str == '\0' ? len : strLenImpl(str + 1, len + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compile-time C string length.
|
|
||||||
/// \param str The string.
|
|
||||||
/// \return Length of the string.
|
|
||||||
static constexpr inline std::size_t strLen(const char* str) noexcept{
|
|
||||||
return strLenImpl(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Unsigned to signed conversion, using static_cast.
|
|
||||||
/// Available only if integers are represented using 2 complement.
|
|
||||||
/// Specialization handles non-2 complement cases.
|
|
||||||
/// \tparam T An integral type.
|
|
||||||
/// \tparam _2complement Whether ints are represented as 2 complement.
|
|
||||||
template<typename T, bool _2complement> // true
|
|
||||||
struct UnsigToSig {
|
|
||||||
typedef typename std::make_signed<T>::type Signed;
|
|
||||||
typedef typename std::make_unsigned<T>::type Unsigned;
|
|
||||||
|
|
||||||
static constexpr Signed convert(Unsigned val) noexcept{
|
|
||||||
return static_cast<Signed>(val);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Unsigned to signed conversion.
|
|
||||||
/// This specialization is used when architecture does not use 2 complement.
|
|
||||||
/// \tparam T An integral type.
|
|
||||||
template<typename T>
|
|
||||||
struct UnsigToSig<T, false> {
|
|
||||||
typedef typename std::make_signed<T>::type Signed;
|
|
||||||
typedef typename std::make_unsigned<T>::type Unsigned;
|
|
||||||
|
|
||||||
static constexpr Signed convert(Unsigned val) noexcept{
|
|
||||||
return val <= std::numeric_limits<Signed>::max() ?
|
|
||||||
static_cast<Signed>(val) :
|
|
||||||
static_cast<Signed>(val - std::numeric_limits<Signed>::min()) + std::numeric_limits<Signed>::min();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Converts, at compile time, an unsigned integer to its signed counterpart.
|
|
||||||
/// This holds true: unsignedValue == static_cast<unsigned type>(unsignedToSigned(unsignedValue))
|
|
||||||
/// \tparam T Unsigned integral type.
|
|
||||||
/// \param val Unsigned value to be converted to signed.
|
|
||||||
/// \return Signed value that can be converted back to its unsigned type.
|
|
||||||
template<typename T, typename = typename std::enable_if<std::is_unsigned<T>::value>::type>
|
|
||||||
static constexpr inline typename std::make_signed<T>::type unsignedToSigned(T val) noexcept{
|
|
||||||
typedef typename std::make_signed<T>::type Signed;
|
|
||||||
typedef typename std::make_unsigned<T>::type Unsigned;
|
|
||||||
|
|
||||||
return UnsigToSig<T, static_cast<Signed>(-1) == static_cast<Signed>(~Unsigned(0))>::convert(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compares two C strings at compile time as if strcmp was used.
|
|
||||||
/// \param a First string.
|
|
||||||
/// \param b Second string.
|
|
||||||
/// \return See strcmp.
|
|
||||||
static constexpr inline int strCmp(const char* a, const char* b) noexcept{
|
|
||||||
return *a != *b ? (static_cast<int>(*a) - *b) : (*a == '\0' ? 0 : strCmp(a + 1, b + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Absolute value.
|
|
||||||
/// Default implementation handles signed values
|
|
||||||
/// of non-integral types.
|
|
||||||
/// \tparam T Data type.
|
|
||||||
/// \tparam integral Whether the type is integral.
|
|
||||||
/// \tparam unsig Whether the data type is unsigned.
|
|
||||||
template<typename T, bool integral, bool unsig> // false, false
|
|
||||||
struct Abs {
|
|
||||||
static constexpr inline T abs(T a) noexcept{
|
|
||||||
return a >= T() ? a : -a;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Absolute value.
|
|
||||||
/// This handles signed values of integral types.
|
|
||||||
/// \tparam T Data type.
|
|
||||||
template<typename T>
|
|
||||||
struct Abs<T, true, false> {
|
|
||||||
static constexpr inline T abs(T a) noexcept{
|
|
||||||
return std::abs(a);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Absolute value.
|
|
||||||
/// This handles unsigned values.
|
|
||||||
/// \tparam T Data type.
|
|
||||||
template<typename T, bool integral>
|
|
||||||
struct Abs<T, integral, true> {
|
|
||||||
static constexpr inline T abs(T a) noexcept{
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Absolute value.
|
|
||||||
/// Handles anything that has `bool operator >=(const T&)` (or equiv.),
|
|
||||||
/// `T operator-()`, and its default value represents `zero`.
|
|
||||||
/// \tparam T Data type.
|
|
||||||
/// \param a Value.
|
|
||||||
template<typename T>
|
|
||||||
static constexpr inline T abs(T a) noexcept{
|
|
||||||
return Abs<T, std::is_integral<T>::value, std::is_unsigned<T>::value>::abs(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWPP_DETAIL_FILE_UTILS_HPP
|
|
||||||
|
|
Loading…
Reference in New Issue