1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
////////////////////////////////////////////////////////////////////////////////
/*! @file General.h General definitions.
- Part of RANet - Research Assistant Net Library (based on ANSI C++).
- Copyright(C) 1994-2011, Viktor E. Bursian, St.Petersburg, Russia.
Viktor.Bursian@mail.ioffe.ru
*///////////////////////////////////////////////////////////////////////////////
#ifndef General_H
#define General_H
#include "RANet_global.h"
//#include <string>
//#include <sstream>
#include <limits>
#include <cmath>
namespace RA {
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/*! Закавычить, @b НЕ @b делая макроподстановки в аргументе.
@sa ZAKAVYCH
@macro
*/
#define TUPO_ZAKAVYCH(SSS) #SSS
/*! Закавычить, не забыв при этом сделать макроподстановки в аргументе.
Чтобы в десятый раз не наступать на те же грабли:
Stupid C! Казалось бы, этот макрос по определению тождественен
макросу @ref TUPO_ZAKAVYCH, но это не так! В этом макросе выполняются
макроподстановки в значении параметра, после чего @ref TUPO_ZAKAVYCH тупо
закавычивает уже результат.
При всём моём уважении к мистеру Ричи, какого дерьма он накурился,
разрабатывая С и его препроцессор? Это не в плане критики, а токмо для
того, чтобы знать, чем набить трубку, когда в следующий раз нарвусь.
@macro
*/
#define ZAKAVYCH(SSS) TUPO_ZAKAVYCH(SSS)
//------------------------------------------------------------------------------
#define TUPO_PRISOBACH(S,SS) S##SS
#define PRISOBACH(S,SS) TUPO_PRISOBACH(S,SS)
//------------------------------------------------------------------------------
/*! Предекларация класса, а также полезных производных типов:
ссылка на объект класса, ссылка на константный объект класса,
указатель на объект класса, и других.
@macro
*/
#define ANNOUNCE_CLASS(Class) \
class Class; \
typedef const Class c##Class; \
typedef Class & r##Class; \
typedef const Class & rc##Class; \
typedef Class * p##Class; \
typedef const Class * pc##Class; \
typedef const p##Class cp##Class; \
typedef const pc##Class cpc##Class;
/*! Идентичен макросу @ref ANNOUNCE_CLASS, изменённое имя служит
исключительно как комментарий для читателя: "это абстрактный класс".
@macro
*/
#define ANNOUNCE_ABSTRACT_CLASS(Class) \
ANNOUNCE_CLASS(Class)
//------------------------------------------------------------------------------
/*
#define MAKE_STRING_FROM(EXPR) \
static_cast<std::ostringstream*>( &(std::ostringstream() << EXPR) \
)->str()
*/
//enum relation {Less,Equal,Greater};
enum eTextFormat {Plain,HTML};
enum eTextDetalization {Laconic,Casual,Verbose};
typedef void * pointer;
typedef unsigned char byte;
//typedef unsigned short word; // 2 bytes
//typedef unsigned int dword; // 4 bytes
//typedef unsigned long long int qword; // 8 bytes
typedef long double real;
typedef double realIO;
//typedef __float80 real80;
typedef long double realIOv14;
//typedef __int32_t integer32t;//__int32_t is undefined under Win
//typedef __int32 integer32;//__int32 is undefined under Ubuntu
typedef qint32 integer;
typedef const char const_char;
typedef const_char * ptr_to_const_char;
typedef ptr_to_const_char const const_ptr_to_const_char;
typedef ptr_to_const_char literal;
//typedef const_ptr_to_const_char literal;
typedef long int tStreamPos;
//-------
RANet_EXPORT extern const real real_inf;
RANet_EXPORT extern const real real_nan;
#ifndef isinf
inline bool isinf (real x)
{
return (x == std::numeric_limits<real>::infinity())
|| (x == - std::numeric_limits<real>::infinity());
}
#endif
#ifndef isnan
inline bool isnan (real x)
{
return x != x;
}
#endif
inline real rmax (real a ,real b)
{
return ( a < b ? b : a );
}
inline real rmin (real a ,real b)
{
return ( a < b ? a : b );
}
inline integer Round (real x)
{
try{
return ( x < 0 ? int(x-0.5) : int(x+0.5) );
}catch(...){
return ( x < 0 ? std::numeric_limits<integer>::min()
: std::numeric_limits<integer>::max() );
};
}
//RANet_EXPORT extern real const ln10;
//! ten to the power of P
RANet_EXPORT extern real power10 (int P);
inline real power10 (real E)
{
// return exp(ln10*E);
return pow(10,E);
}
//inline real lg (real x)
//{
// return log(x)/ln10;
//}
inline double DoDummyJob (int duration)
{
double xxx=0;
for( int i=0 ; i < duration ; i++ )
for( int j=0 ; j < 14000 ; j++ )
xxx=xxx+sin(1e-2*i+1e-2*j);
return xxx;
}
//------------------------------------------------------------------------------
} //namespace RA
#endif
|