Program Listing for File helper.hpp¶
↰ Return to documentation for file (include/nix/valid/helper.hpp)
// Copyright (c) 2013, German Neuroinformatics Node (G-Node)
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted under the terms of the BSD License. See
// LICENSE file in the root of the Project.
#ifndef NIX_HELPER_H
#define NIX_HELPER_H
#include <nix/base/IDimensions.hpp>
#include <nix/Platform.hpp>
#include <nix/util/util.hpp>
#include <nix/types.hpp>
#include <boost/optional.hpp>
#include <string>
#include <vector>
namespace nix {
namespace valid {
struct NIXAPI Message {
std::string id;
std::string msg;
boost::optional<std::string> name;
Message() { }
Message(std::string new_id, std::string new_msg)
: id(new_id), msg(new_msg)
{
}
Message(std::string id, std::string msg, boost::optional<std::string> name)
: id(std::move(id)), msg(std::move(msg)), name(std::move(name))
{}
};
#ifndef _WIN32
template<typename T>
class NIXAPI hasID
{
typedef char one;
typedef long two;
template<typename C> static one test( decltype(&C::id) ) ;
template<typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(char) };
};
#else
template<typename T>
class hasID
{
public:
__if_exists(T::id) {
static const bool value = true;
}
__if_not_exists(T::id) {
static const bool value = false;
}
};
#endif
#ifndef _WIN32
template<typename T>
class NIXAPI hasEmpty
{
typedef char one;
typedef long two;
template<typename C> static one test( decltype(&C::empty) ) ;
template<typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(char) };
};
#else
template<typename T>
class hasEmpty
{
public:
__if_exists(T::empty) {
static const bool value = true;
}
__if_not_exists(T::empty) {
static const bool value = false;
}
};
#endif
template<bool HAS_ID>
class NIXAPI ID {
public:
template<typename TOBJ>
auto get(TOBJ parent) -> decltype(parent.id()) {
return parent.id();
}
};
template<>
class NIXAPI ID<false> {
public:
template<typename TOBJ>
std::string get(TOBJ parent) {
return std::string("unknown");
}
};
std::vector<std::string> getDimensionsUnits(DataArray darray);
} // namespace valid
} // namespace nix
#endif // NIX_HELPER_H