File: utils.h

package info (click to toggle)
golly 3.3-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 20,176 kB
  • sloc: cpp: 72,638; ansic: 25,919; python: 7,921; sh: 4,245; objc: 3,721; java: 2,781; xml: 1,362; makefile: 530; javascript: 279; perl: 69
file content (101 lines) | stat: -rw-r--r-- 3,068 bytes parent folder | download | duplicates (3)
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
// This file is part of Golly.
// See docs/License.html for the copyright notice.

#ifndef _UTILS_H_
#define _UTILS_H_

#include <string>       // for std::string

class lifepoll;

// Various types and utility routines:

typedef struct {
    unsigned char r;
    unsigned char g;
    unsigned char b;
} gColor;               // a color in RGB space

typedef struct {
    int x;
    int y;
    int width;
    int height;
} gRect;                // a rectangle

void SetColor(gColor& color, unsigned char red, unsigned char green, unsigned char blue);
// Set given gColor to given RGB values.

void SetRect(gRect& rect, int x, int y, int width, int height);
// Set given gRect to given location and size.

void Warning(const char* msg);
// Beep and display message in a modal dialog.

bool YesNo(const char* msg);
// Similar to Warning, but there are 2 buttons: Yes and No.
// Returns true if Yes button is hit.

void Fatal(const char* msg);
// Beep, display message in a modal dialog, then exit app.

void Beep();
// Play beep sound, depending on user setting.

double TimeInSeconds();
// Get time of day, in seconds (accuracy in microsecs).

std::string CreateTempFileName(const char* prefix);
// Return path to a unique temporary file.

bool FileExists(const std::string& filepath);
// Does given file exist?

void RemoveFile(const std::string& filepath);
// Delete given file.

bool CopyFile(const std::string& inpath, const std::string& outpath);
// Return true if input file is successfully copied to output file.
// If the output file existed it is replaced.

bool MoveFile(const std::string& inpath, const std::string& outpath);
// Return true if input file is successfully moved to output file.
// If the output file existed it is replaced.

void FixURLPath(std::string& path);
// Replace "%..." with suitable chars for a file path (eg. %20 is changed to space).

bool IsHTMLFile(const std::string& filename);
// Return true if the given file's extension is .htm or .html
// (ignoring case).

bool IsTextFile(const std::string& filename);
// Return true if the given file's extension is .txt or .doc,
// or if it's not a HTML file and its name contains "readme"
// (ignoring case).

bool IsZipFile(const std::string& filename);
// Return true if the given file's extension is .zip or .gar
// (ignoring case).

bool IsRuleFile(const std::string& filename);
// Return true if the given file is a rule-related file with
// an extension of .rule or .table or .tree or .colors or .icons
// (ignoring case).

bool IsScriptFile(const std::string& filename);
// Return true if the given file is a Lua or Perl or Python script.
// It simply checks if the file's extension is .lua or .pl or .py
// (ignoring case).

bool EndsWith(const std::string& str, const std::string& suffix);
// Return true if given string ends with given suffix.

lifepoll* Poller();
void PollerReset();
void PollerInterrupt();
extern int event_checker;
// Poller is used by gollybase modules to process events.
// If event_checker > 0 then we've been called from the event checking code.

#endif