Stimfit @PACKAGE_VERSION@
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------------
2// common.h
3// Downloaded from http://www.intantech.com/files/CLAMP_source_code_v1_0.zip
4// as of 2017-03-13
5//
6// Original comment and license information:
7// Intan Technologies
8// Common Header File
9// Version 2.0 (25 August 2015)
10//
11// Provides common functionality for RHD and CLAMP source code.
12//
13// Copyright (c) 2014-2015 Intan Technologies LLC
14//
15// This software is provided 'as-is', without any express or implied warranty.
16// In no event will the authors be held liable for any damages arising from the
17// use of this software.
18//
19// Permission is granted to anyone to use this software for any applications that
20// use Intan Technologies integrated circuits, and to alter it and redistribute it
21// freely.
22//
23// See http://www.intantech.com for documentation and product information.
24//----------------------------------------------------------------------------------
25
26#pragma once
27
28#include <iosfwd>
29#include <string>
30#include <stdexcept>
31#include <sstream>
32
33using std::endl;
34
35// Debug output window printing macro
36#define DEBUGOUT( s ) \
37{ \
38 std::ostringstream os_; \
39 os_ << " DEBUG: " << s; \
40 OutputDebugStringA( os_.str().c_str() ); \
41}
42
43// Logging -----------------------------------------------------------------
44// Logging goes to this, which may point to dev_null
45extern std::ostream* logger;
46
47extern std::ostream* nulllogger; // Always points to dev_null
48
49// To
50#define LOG(x) ((x) ? (*logger) : (*nulllogger))
51
52// Use SetLogger(&std::cerr), for example, or SetLogger(nullptr).
53std::ostream* SetLogger(std::ostream* logger_);
54
55// _T macro for unicode support ---------------------------------------------
56#ifndef _T
57 #if defined(_WIN32) && defined(_UNICODE)
58 #define _T(x) L ##x
59 #else
60 #define _T(x) x
61 #endif
62#endif
63
64std::wstring toWString(const std::string& s);
65std::string toString(const std::wstring& ws);
66
67// Throws an exception if value has more than numBits set. For example, if you're trying to put something into 3 bits, and you specify 15.
68template <typename T>
69T CheckBits(T value, unsigned int numBits) {
70 T mask = (-1 << numBits);
71 if ((value & mask) != 0) {
72 throw std::invalid_argument("Invalid value with too many bits set.");
73 }
74 return value;
75}
76
77#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember))
78
79#if defined WIN32
80 #define NOMINMAX
81 #include <windows.h>
82 bool _trace(TCHAR *format, ...);
83 #ifdef _DEBUG
84 #define TRACE _trace
85 #else
86 #define TRACE false && _trace
87 #endif
88#endif
std::ostream * logger
std::ostream * nulllogger
std::wstring toWString(const std::string &s)
std::string toString(const std::wstring &ws)
T CheckBits(T value, unsigned int numBits)
Definition common.h:69
std::ostream * SetLogger(std::ostream *logger_)
char TCHAR
Definition unix.h:123