mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
Api (#48)
* WIP * WIP * WIP * cleaned up multi * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * split up python module * WIP * WIP * WIP * WIP * WIP * ok * fixed bugs from rebase * WIP * fixed broken test * WIP * fixed python * WIP * sphinx help * including new commands * docs * WIP * WIP * more tests * added missing public header * WIP
This commit is contained in:
21
sample/CMakeLists.txt
Normal file
21
sample/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
add_executable(a api.cpp)
|
||||
target_link_libraries(a
|
||||
slsDetectorShared
|
||||
slsSupportLib
|
||||
pthread
|
||||
rt
|
||||
)
|
||||
|
||||
set_target_properties(a PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||
)
|
||||
|
||||
|
||||
add_executable(result useResult.cpp)
|
||||
target_link_libraries(result
|
||||
slsDetectorShared
|
||||
)
|
||||
|
||||
set_target_properties(result PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||
)
|
67
sample/api.cpp
Normal file
67
sample/api.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include "Detector.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const std::chrono::nanoseconds &t) {
|
||||
os << t.count() << "ns";
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename T, typename _ = void>
|
||||
struct is_container : std::false_type {};
|
||||
|
||||
template <typename... Ts> struct is_container_helper {};
|
||||
|
||||
template <typename T>
|
||||
struct is_container<
|
||||
T, typename std::conditional<
|
||||
false,
|
||||
is_container_helper<typename T::value_type, typename T::size_type,
|
||||
typename T::iterator, typename T::const_iterator,
|
||||
decltype(std::declval<T>().size()),
|
||||
decltype(std::declval<T>().begin()),
|
||||
decltype(std::declval<T>().end()),
|
||||
decltype(std::declval<T>().cbegin()),
|
||||
decltype(std::declval<T>().cend()),
|
||||
decltype(std::declval<T>().empty())>,
|
||||
void>::type> : public std::true_type {};
|
||||
|
||||
template <typename Container>
|
||||
auto operator<<(std::ostream &os, const Container &con) ->
|
||||
typename std::enable_if<is_container<Container>::value,
|
||||
std::ostream &>::type {
|
||||
if (con.empty())
|
||||
return os << "[]";
|
||||
auto it = con.cbegin();
|
||||
os << '[' << *it++;
|
||||
while (it != con.cend())
|
||||
os << ", " << *it++;
|
||||
return os << ']';
|
||||
}
|
||||
|
||||
using sls::Detector;
|
||||
using std::chrono::nanoseconds;
|
||||
using std::chrono::seconds;
|
||||
|
||||
int main() {
|
||||
Detector d;
|
||||
d.setConfig("/home/l_frojdh/virtual.config");
|
||||
|
||||
// d.setExptime(nanoseconds(500)); // set exptime of all modules
|
||||
// auto t0 = d.getExptime();
|
||||
// std::cout << "exptime: " << t0 << '\n';
|
||||
|
||||
// d.setExptime(seconds(1), {1}); // set exptime of module one
|
||||
// auto t1 = d.getExptime({1,3,5}); // get exptime of module 1, 3 and 5
|
||||
// std::cout << "exptime: " <<t1 << '\n';
|
||||
|
||||
std::cout << "Period: " << d.getPeriod() << '\n';
|
||||
std::cout << "Period: " << d.getPeriod().squash() << '\n';
|
||||
// std::cout << "fname: " << d.getFname() << "\n";
|
||||
|
||||
// std::cout << "fwrite: " << std::boolalpha << d.getFwrite() << '\n';
|
||||
|
||||
// d.freeSharedMemory();
|
||||
|
||||
}
|
55
sample/useResult.cpp
Normal file
55
sample/useResult.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include <iostream>
|
||||
#include "Result.h"
|
||||
#include "ToString.h"
|
||||
|
||||
auto main() -> int {
|
||||
|
||||
using sls::Result; // declared in namespace sls
|
||||
using sls::ToString;
|
||||
|
||||
std::cout << "Examples on usage of Result<T>\n";
|
||||
|
||||
// Result exposes the underlying constructors of std::vector
|
||||
Result<int> res{1, 2, 3, 4, 5};
|
||||
std::cout << "res: " << res << '\n';
|
||||
|
||||
Result<double> res2(5, 3.7);
|
||||
std::cout << "res2: " << res2 << '\n';
|
||||
|
||||
// and can be converted to and from a vector. However, the
|
||||
// conversion to a vector is not efficient since a copy is made
|
||||
// and should only be done when a vector is needed for further use
|
||||
// in most sense and in standard algorithms Result<T> behaves as a
|
||||
// vector.
|
||||
std::vector<int> vec(5, 5);
|
||||
std::cout << "vec: " << ToString(vec) << "\n";
|
||||
|
||||
Result<int> res3 = vec;
|
||||
std::cout << "res3: " << res3 << '\n';
|
||||
|
||||
std::vector<int> vec2 = res3;
|
||||
std::cout << "vec2: " << ToString(vec2) << "\n";
|
||||
|
||||
|
||||
// WARNING this feature is still not decied, its convenient
|
||||
// but might turn out to be a source of bugs...
|
||||
// it is also possible to convert from Result<T> to T
|
||||
int r = res3;
|
||||
std::cout << "r: " << r << '\n';
|
||||
std::cout << "static_cast<int>: " << static_cast<int>(res3) << '\n';
|
||||
std::cout << "static_cast<double>: " << static_cast<double>(res3) << '\n';
|
||||
|
||||
int r2 = res;
|
||||
std::cout << "res: " << res << " converted to int: " << r2 << "\n";
|
||||
|
||||
//Using squash we can also convert to a single value
|
||||
std::cout << "res.squash(): " << res.squash() << '\n';
|
||||
std::cout << "res3.squash(): " << res3.squash() << '\n';
|
||||
|
||||
|
||||
//.squash also takes a default value
|
||||
std::cout << "res.squash(-1): " << res.squash(-1) << '\n';
|
||||
std::cout << "res3.squash(-1): " << res3.squash(-1) << '\n';
|
||||
|
||||
//
|
||||
}
|
Reference in New Issue
Block a user