Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
system.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 #include "common/singleton.h"
28 
29 #include <string>
30 
36 {
47 };
48 
56 {
57  SDR_OK,
58  SDR_CANCEL,
59  SDR_YES,
60  SDR_NO
61 };
62 
68 {
75 };
76 
77 /*
78  * Forward declaration of time stamp struct
79  * SystemTimeStamp should only be used in a pointer context.
80  * The implementation details are hidden because of platform dependence.
81  */
82 struct SystemTimeStamp;
83 
91 class CSystemUtils : public CSingleton<CSystemUtils>
92 {
93 public:
95  static CSystemUtils* Create();
96 
98  virtual void Init() = 0;
99 
101  virtual SystemDialogResult SystemDialog(SystemDialogType, const std::string &title, const std::string &message) = 0;
102 
104  TEST_VIRTUAL SystemDialogResult ConsoleSystemDialog(SystemDialogType type, const std::string& title, const std::string& message);
105 
107  TEST_VIRTUAL SystemTimeStamp* CreateTimeStamp();
108 
110  TEST_VIRTUAL void DestroyTimeStamp(SystemTimeStamp *stamp);
111 
113  TEST_VIRTUAL void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src);
114 
116  virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp) = 0;
117 
119 
120  TEST_VIRTUAL float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit = STU_SEC);
121 
123 
124  virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) = 0;
125 
127  virtual std::string GetDataPath();
128 
130  virtual std::string GetLangPath();
131 
133  virtual std::string GetSaveDir();
134 
136  virtual void Usleep(int usecs) = 0;
137 };
138 
141 {
142  return CSystemUtils::GetInstancePointer();
143 }
144 
milliseconds
Definition: system.h:72
CSingleton base class for singletons.
TEST_VIRTUAL void DestroyTimeStamp(SystemTimeStamp *stamp)
Destroys a time stamp object.
Definition: system.cpp:150
virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp)=0
Returns a time stamp associated with current time.
virtual void Init()=0
Performs platform-specific initialization.
microseconds
Definition: system.h:74
virtual void Usleep(int usecs)=0
Sleep for given amount of microseconds.
SystemDialogType
Type of system dialog.
Definition: system.h:35
Warning message.
Definition: system.h:40
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after)=0
Returns the exact (in nanosecond units) difference between two timestamps.
Definition: singleton.h:30
Yes/No question.
Definition: system.h:44
virtual std::string GetSaveDir()
Returns the save dir location.
Definition: system.cpp:187
TEST_VIRTUAL SystemDialogResult ConsoleSystemDialog(SystemDialogType type, const std::string &title, const std::string &message)
Displays a fallback system dialog using console.
Definition: system.cpp:59
Error message.
Definition: system.h:42
static CSystemUtils * Create()
Creates system utils for specific platform.
Definition: system.cpp:44
Information message.
Definition: system.h:38
virtual std::string GetLangPath()
Returns the translations path.
Definition: system.cpp:182
TEST_VIRTUAL float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit=STU_SEC)
Returns a difference between two timestamps in given time unit.
Definition: system.cpp:160
seconds
Definition: system.h:70
SystemTimeUnit
Time unit.
Definition: system.h:67
SystemDialogResult
Result of system dialog.
Definition: system.h:55
virtual SystemDialogResult SystemDialog(SystemDialogType, const std::string &title, const std::string &message)=0
Displays a system dialog.
Ok/Cancel question.
Definition: system.h:46
Platform-specific utils.
Definition: system.h:91
Definition: system_linux.h:30
TEST_VIRTUAL void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src)
Copies the time stamp from src to dst.
Definition: system.cpp:155
virtual std::string GetDataPath()
Returns the data path (containing textures, levels, helpfiles, etc)
Definition: system.cpp:177
CSystemUtils * GetSystemUtils()
Global function to get CSystemUtils instance.
Definition: system.h:140
TEST_VIRTUAL SystemTimeStamp * CreateTimeStamp()
Creates a new time stamp object.
Definition: system.cpp:145