EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
misc.h
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24 */
25 
26 #ifndef __MISC_H__INCL__
27 #define __MISC_H__INCL__
28 #include <eve-compat.h>
29 
39 uint16 crc_hqx( const uint8* data, size_t len, uint16 crc = 0 );
40 
48 int64 filesize( const char* filename );
56 int64 filesize( FILE* fd );
57 
67 int64 npowof2( int64 num );
68 
77 int64 MakeRandomInt( int64 low = 0, int64 high = RAND_MAX );
86 double MakeRandomFloat( double low = 0, double high = 1 );
87 
88 inline bool IsEven(int64 number) { return ((number %2) == 0); }
89 inline bool IsNaN(double x) { return x!= x; }
90 
91 uint32 CreatePIDFile(const std::string& filename);
92 
93 namespace EvE {
94  // returns the minimum of x,y as double
95  inline double min(double x, double y) { return ((x < y) ? x : y); }
96  // returns the minimum of x,y as 32b integer
97  inline int32 min(int32 x, int32 y) { return ((x < y) ? x : y); }
98  // returns the minimum of x,y and 1
99  double min1(double x, double y);
100  // returns the minimum of x,y and z
101  double min(double x, double y, double z);
102  // returns the max of x,y with y=0 by default
103  inline int64 max(int64 x, int64 y=0) { return ((x > y) ? x : y); }
104  // returns the maximum of x,y with y=0 by default
105  inline double max(double x, double y=0) { return ((x > y) ? x : y); }
106  // returns the maximum of x,y and z
107  double max(double x, double y, double z);
108  // prints the top10 items in stack to stdout
109  void traceStack(void);
110  // Find Case Insensitive Sub String in a given substring
111  bool icontains(std::string data, std::string toSearch, size_t pos = 0);
112  // format given time (in seconds) to month/week/day/hour/minute/second
113  // <0 will return "Invalid Time". 0 will return "None"
114  const char* FormatTime(int64 time=-1);
115  // format given time (in seconds) to month/week/day/hour/minute/second
116  // <0 will return "Invalid Time". 0 will return "None"
117  const char* FormatTime(double time=-1);
118 
119  double trunicate2(double dig=0);
120 }
121 
122 #endif /* !__MISC_H__INCL__ */
unsigned __int8 uint8
Definition: eve-compat.h:46
itemID[count] Create count or of the specified() x() y(z)-Jump to the specified position in space.Stopped." ) COMMAND( translocate
double trunicate2(double dig=0)
Definition: misc.cpp:276
double min(double x, double y)
Definition: misc.h:95
int64 filesize(const char *filename)
Obtains filesize.
Definition: misc.cpp:75
signed __int32 int32
Definition: eve-compat.h:49
uint16 crc_hqx(const uint8 *data, size_t len, uint16 crc=0)
Definition: misc.cpp:67
bool IsEven(int64 number)
Definition: misc.h:88
double MakeRandomFloat(double low=0, double high=1)
Generates random real from interval [low; high].
Definition: misc.cpp:114
Definition: Trig.h:15
uint32 CreatePIDFile(const std::string &filename)
create PID file
Definition: misc.cpp:131
unsigned __int32 uint32
Definition: eve-compat.h:50
double min1(double x, double y)
Definition: misc.cpp:150
signed __int64 int64
Definition: eve-compat.h:51
int64 max(int64 x, int64 y=0)
Definition: misc.h:103
int64 MakeRandomInt(int64 low=0, int64 high=RAND_MAX)
Generates random integer from interval [low; high].
Definition: misc.cpp:109
int64 npowof2(int64 num)
Calculates next (greater or equal) power-of-two number.
Definition: misc.cpp:95
const char * FormatTime(int64 time=-1)
Definition: misc.cpp:204
void traceStack(void)
Definition: misc.cpp:169
unsigned __int16 uint16
Definition: eve-compat.h:48
bool icontains(std::string data, std::string toSearch, size_t pos=0)
Definition: misc.cpp:194
bool IsNaN(double x)
Definition: misc.h:89