Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
wtime.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/****************************************************************************\
20wtime Neal Kettler
21
22\****************************************************************************/
23#ifndef WTIME_HEADER
24#define WTIME_HEADER
25
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <assert.h>
30#include <sys/types.h>
31
32#ifndef _WINDOWS
33#include <unistd.h>
34#include <netinet/in.h>
35#include <sys/time.h>
36#else
37#include <sys/timeb.h>
38#include <winsock.h>
39#endif
40
41#include <time.h>
42#include <string.h>
43
44#include "wstypes.h"
45
46class Wtime
47{
48 public:
49
50 enum
51 {
52 POSITIVE=0,
53 NEGATIVE=1
54 };
55
56 Wtime(); // init to system time
57 Wtime( Wtime &other );
58 Wtime( uint32 other );
60
61 void Update(); // Update members sec & usec to system time
62
63
64 void PrintTime(FILE *out) const;
65 void PrintTime(char *out) const;
66 void PrintDate(FILE *out) const;
67 void PrintDate(char *out) const;
68
69 uint32 GetSec(void) const; // Get member variable 'sec'
70 uint32 GetUsec(void) const; // Get member variable 'usec'
71 void SetSec(uint32 newsec);
72 void SetUsec(uint32 newusec);
73 void Set(uint32 newsec,uint32 newusec);
74 bit8 ParseDate(char *in);
75 bit8 FormatTime(char *out, char *format);
76
77 struct timeval *GetTimeval(void);
78 void GetTimevalMT(struct timeval &tv);
79
80 uint32 GetSecond(void) const; // Second (0- 60) (60 is for a leap second)
81 uint32 GetMinute(void) const; // Minute (0 - 59)
82 uint32 GetHour(void) const; // Hour (0-23)
83 uint32 GetMDay(void) const; // Day of Month (1-31)
84 uint32 GetWDay(void) const; // Day of Week (1-7)
85 uint32 GetYDay(void) const; // Day of Year (1-366)
86 uint32 GetMonth(void) const; // Month (1-12)
87 uint32 GetYWeek(void) const; // Week of Year (1-53)
88 uint32 GetYear(void) const; // Year (e.g. 1997)
89
90 bit8 GetSign(void) const; // 0 = pos 1 = neg
91
92 int Compare(const Wtime &other) const;
93
94 // comparisons
95 bit8 operator == ( const Wtime &other ) const;
96 bit8 operator != ( const Wtime &other ) const;
97 bit8 operator < ( const Wtime &other ) const;
98 bit8 operator > ( const Wtime &other ) const;
99 bit8 operator <= ( const Wtime &other ) const;
100 bit8 operator >= ( const Wtime &other ) const;
101
102 // assignments
103 Wtime &operator = (const Wtime &other);
104 Wtime &operator = (const uint32 other);
105
106 // math
107 // signed
108 void SignedAdd(const Wtime &other);
109 void SignedSubtract(const Wtime &other);
110
111 // unsigned
112 Wtime &operator += (const Wtime &other);
113 Wtime &operator -= (const Wtime &other);
116
117 Wtime &operator += (const uint32 other);
118 Wtime &operator -= (const uint32 other);
121
122 protected:
123 uint32 sec; // seconds since Jan 1, 1970
124 uint32 usec; // microseconds (millionths of a second)
125 bit8 sign; // for time differences 0 = pos 1 = neg
126};
127
128#endif
char bit8
Definition wstypes.h:61
unsigned long uint32
Definition bittype.h:46
Definition wtime.h:47
bit8 operator>=(const Wtime &other) const
Definition wtime.cpp:599
int Compare(const Wtime &other) const
void SignedAdd(const Wtime &other)
void SignedSubtract(const Wtime &other)
bit8 sign
Definition wtime.h:125
struct timeval * GetTimeval(void)
bit8 operator<(const Wtime &other) const
Definition wtime.cpp:572
void Update()
void SetSec(uint32 newsec)
bit8 operator!=(const Wtime &other) const
Definition wtime.cpp:563
uint32 GetSec(void) const
Wtime(uint32 other)
Wtime operator+(Wtime &other)
Definition wtime.cpp:749
uint32 GetMinute(void) const
uint32 sec
Definition wtime.h:123
void SetUsec(uint32 newusec)
bit8 FormatTime(char *out, char *format)
bit8 operator<=(const Wtime &other) const
Definition wtime.cpp:590
uint32 GetYDay(void) const
void PrintTime(FILE *out) const
Wtime(Wtime &other)
bit8 ParseDate(char *in)
uint32 GetWDay(void) const
uint32 GetMDay(void) const
bit8 GetSign(void) const
uint32 GetMonth(void) const
void PrintDate(FILE *out) const
uint32 usec
Definition wtime.h:124
uint32 GetSecond(void) const
uint32 GetYear(void) const
@ POSITIVE
Definition wtime.h:52
@ NEGATIVE
Definition wtime.h:53
void PrintDate(char *out) const
Wtime & operator-=(const Wtime &other)
Definition wtime.cpp:721
Wtime operator-(Wtime &other)
Definition wtime.cpp:742
void PrintTime(char *out) const
void Set(uint32 newsec, uint32 newusec)
void GetTimevalMT(struct timeval &tv)
uint32 GetHour(void) const
bit8 operator>(const Wtime &other) const
Definition wtime.cpp:581
bit8 operator==(const Wtime &other) const
Definition wtime.cpp:554
uint32 GetYWeek(void) const
Wtime & operator+=(const Wtime &other)
Definition wtime.cpp:709
Wtime & operator=(const Wtime &other)
Definition wtime.cpp:757
uint32 GetUsec(void) const