stdafx.h File Reference

Definition of base types and functions in a cross-platform compatible way. More...

#include <stdint.h>
#include <cstdio>
#include <cstddef>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cassert>

Go to the source code of this file.

Defines

#define __STDC_LIMIT_MACROS
#define fopen(file, mode)   fopen(OTTD2FS(file), mode)
#define SQ2OTTD(name)   (name)
#define OTTD2SQ(name)   (name)
#define PATHSEP   "/"
#define PATHSEPCHAR   '/'
#define OTTD_PRINTF64   "%lld"
#define OTTD_PRINTFHEX64   "%llx"
#define PRINTF_SIZE   "%zu"
#define PERSONAL_DIR   ""
#define assert_compile(expr)   typedef int __ct_assert__[1 - 2 * !(expr)]
#define assert_tcompile(expr)   assert(expr)
#define M_PI_2   1.57079632679489661923
#define M_PI   3.14159265358979323846
#define lengthof(x)   (sizeof(x) / sizeof(x[0]))
 Return the length of an fixed size array.
#define endof(x)   (&x[lengthof(x)])
 Get the end element of an fixed size array.
#define lastof(x)   (&x[lengthof(x) - 1])
 Get the last element of an fixed size array.
#define cpp_offsetof(s, m)   (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)
#define offsetof(s, m)   cpp_offsetof(s, m)
#define cpp_sizeof(base, variable)   (sizeof(((base*)8)->variable))
 Gets the size of a variable within a class.
#define cpp_lengthof(base, variable)   (cpp_sizeof(base, variable) / cpp_sizeof(base, variable[0]))
 Gets the length of an array variable within a class.
#define NOT_REACHED()   error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
#define assert(expression)   if (!(expression)) error("Assertion failed at line %i of %s: %s", __LINE__, __FILE__, #expression);
#define OTTD_ASSERT
#define MAX_PATH   PATH_MAX
#define MAX_UVALUE(type)   ((type)~(type)0)
 The largest value that can be entered in a variable.

Typedefs

typedef unsigned char byte
typedef unsigned int uint
typedef unsigned char uint8
typedef signed char int8
typedef unsigned short uint16
typedef signed short int16
typedef unsigned int uint32
typedef signed int int32
typedef unsigned __int64 uint64
typedef signed __int64 int64

Functions

const char * FS2OTTD (const char *name)
const char * OTTD2FS (const char *name)
 Convert from OpenTTD's encoding to that of the local environment.
 assert_compile (sizeof(uint64)==8)
 assert_compile (sizeof(uint32)==4)
 assert_compile (sizeof(uint16)==2)
 assert_compile (sizeof(uint8)==1)
void NORETURN CDECL usererror (const char *str,...) WARN_FORMAT(1
void NORETURN CDECL void
NORETURN CDECL 
error (const char *str,...) WARN_FORMAT(1

Detailed Description

Definition of base types and functions in a cross-platform compatible way.

Definition in file stdafx.h.


Define Documentation

#define cpp_lengthof ( base,
variable   )     (cpp_sizeof(base, variable) / cpp_sizeof(base, variable[0]))

Gets the length of an array variable within a class.

Parameters:
base The class the variable is in.
variable The array variable to get the size of.
Returns:
the length of the array

Definition at line 389 of file stdafx.h.

#define cpp_sizeof ( base,
variable   )     (sizeof(((base*)8)->variable))

Gets the size of a variable within a class.

Parameters:
base The class the variable is in.
variable The variable to get the size of.
Returns:
the size of the variable

Definition at line 381 of file stdafx.h.

#define endof (  )     (&x[lengthof(x)])

Get the end element of an fixed size array.

Parameters:
x The pointer to the first element of the array
Returns:
The pointer past to the last element of the array

Definition at line 360 of file stdafx.h.

Referenced by DoLoad(), DrawCargoListText(), SmallStackSafeStackAlloc< T, length >::EndOf(), FormatString(), GetDebugString(), AirportSpec::GetIndex(), GetSavegameFormat(), GetTownName(), GrowTown(), HandleCrash(), CrashLog::InitialiseCrashLog(), LoadFromHighScore(), SaveToHighScore(), SetDebugString(), ShowRefitOptionsList(), TerraformTileHeight(), and SelectCompanyLiveryWindow::UpdateWidgetSize().

#define lastof (  )     (&x[lengthof(x) - 1])

Get the last element of an fixed size array.

Parameters:
x The pointer to the first element of the array
Returns:
The pointer to the last element of the array

Definition at line 368 of file stdafx.h.

Referenced by ScenarioScanner::AddFile(), FiosFileScanner::AddFile(), TarScanner::AddFile(), AI_CreateAIDummy(), Subsidy::AwardTo(), CargoSpecNameSorter(), NetworkChatWindow::ChatTabCompletionNextItem(), CheckExternalFiles(), CloneVehicleName(), CmdFoundTown(), CopyFromOldName(), DEF_UDP_RECEIVE_COMMAND(), CrashLogOSX::DisplayCrashDialog(), DoAutosave(), DrawCargoListText(), NetworkContentListWindow::DrawDetails(), DrawNewsString(), DrawRoadVehDetails(), DrawString(), DrawStringMultiLine(), CheatWindow::DrawWidget(), AIInfo::DummyConstructor(), EngineNameSorter(), ExtractTar(), FioFOpenFile(), FiosGetFileList(), FormatString(), FS2OTTD(), GamelogRevision(), GenerateCompanyName(), GeneratePresidentName(), NetworkAddress::GetAddressAsString(), GetAllCargoSuffixes(), GetDebugString(), GetFileTitle(), GetFiosItem(), GetFullFilename(), GetKeyboardLayout(), GetLanguageList(), GetSavegameFormat(), GetSaveLoadErrorString(), GetStringBoundingBox(), GetStringHeight(), VehicleGroupWindow::GroupNameSorter(), HandleSavegameLoadCrash(), HelpDialogFunc(), IndustryDirectoryWindow::IndustryNameSorter(), IndustryTypeNameSorter(), IniSaveSettings(), IsGoodGRFConfigList(), IsSameAI(), LanguagePackHeader::IsValid(), KeycodeToString(), AIInstance::LoadCompatibilityScripts(), LoadFromHighScore(), CrashLogOSX::MakeCrashLog(), CrashLog::MakeCrashLog(), MakeScreenshot(), NetworkAddChatMessage(), NetworkAddress::NetworkAddress(), NetworkFindBroadcastIPsInternal(), NetworkGameListHandleDelayedInsert(), NetworkHandlePauseChange(), NetworkSendCommand(), NetworkServerChangeClientName(), NetworkServerSetCompanyPassword(), NetworkUDPQueryServerThread(), SaveLoadWindow::OnClick(), NetworkContentDownloadStatusWindow::OnDownloadProgress(), LandInfoWindow::OnInit(), NetworkStartServerWindow::OnKeyPress(), NetworkGameWindow::OnKeyPress(), AIDebugWindow::OnKeyPress(), CustomCurrencyWindow::OnQueryTextFinished(), NetworkStartServerWindow::OnQueryTextFinished(), ClientNetworkContentSocketHandler::OnReceiveData(), DepotWindow::OnRightClick(), OTTD2FS(), PrintGrfInfo(), DriverFactoryBase::RegisterDriver(), NetworkAddress::Resolve(), SaveHighScoreValue(), SaveKeycodes(), IniFile::SaveToDisk(), FileScanner::Scan(), DriverFactoryBase::SelectDriver(), SetFallbackFont(), SignListWindow::SetFilterString(), ShowErrorMessage(), ShowHelp(), ShowNewGrfVehicleError(), ShowRefitOptionsList(), SignList::SignNameFilter(), SignList::SignNameSorter(), CompanyStationsWindow::StationNameSorter(), TownDirectoryWindow::TownNameSorter(), NetworkContentListWindow::TypeSorter(), ViewportSign::UpdatePosition(), VehicleNameSorter(), VerifyTownName(), and DriverFactoryBase::~DriverFactoryBase().

#define lengthof (  )     (sizeof(x) / sizeof(x[0]))

Return the length of an fixed size array.

Unlike sizeof this function returns the number of elements of the given type.

Parameters:
x The pointer to the first element of the array
Returns:
The number of elements

Definition at line 352 of file stdafx.h.

Referenced by _GenerateWorld(), AddGenericCallback(), AddGRFString(), AddNewsItem(), AfterLoadGame(), AICargoList_IndustryAccepting::AICargoList_IndustryAccepting(), AICargoList_IndustryProducing::AICargoList_IndustryProducing(), AIIndustryList_CargoAccepting::AIIndustryList_CargoAccepting(), AIIndustryList_CargoProducing::AIIndustryList_CargoProducing(), AITileList_IndustryAccepting::AITileList_IndustryAccepting(), AITileList_IndustryProducing::AITileList_IndustryProducing(), NWidgetServerListHeader::AssignSizePosition(), CalcHeightdiff(), AIRoad::CanBuildConnectedRoadPartsHere(), CanCargoServiceIndustry(), ChangeGRFNumUsedParams(), ChangeGRFParamMask(), ChangeIndustryProduction(), NetworkChatWindow::ChatTabCompletion(), CheckForMissingSprites(), AyStar::CheckTile(), CmdChangeCompanySetting(), CmdDoTownAction(), CmdFoundTown(), CmdRenamePresident(), CMSAForest(), CMSAMine(), Squirrel::CompileError(), IndustryCargoesWindow::ComputeCargoDisplay(), IndustryCargoesWindow::ComputeIndustryDisplay(), CargoesRow::ConnectIndustryAccepted(), CargoesRow::ConnectIndustryProduced(), ScriptFileInfo::Constructor(), IndustryCargoesWindow::CountMatchingAcceptingIndustries(), IndustryCargoesWindow::CountMatchingProducingIndustries(), debug(), debug_print(), DeliverGoodsToIndustry(), DeterminePaths(), DoCommandPInternal(), DoCreateNewIndustry(), DoLoad(), DoScanWorkingDirectory(), DrawEngineList(), IndustryViewWindow::DrawInfo(), DrawNewsString(), NewsWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), AboutWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), CompanyWindow::DrawWidget(), CheatWindow::DrawWidget(), error(), Squirrel::ErrorPrintFunc(), ExtractTar(), FillNewGRFVehicleCache(), FindIndustryToDeliver(), FiosGetFileList(), FixTTOEngines(), FormatBytes(), FormatString(), FreeTerminal(), FS2OTTD(), GenerateCompanyPasswordHash(), GenerateTownNameString(), AirportTileSpec::Get(), AirportSpec::Get(), CargoSpec::Get(), AIIndustryType::GetAcceptedCargo(), GetAllCargoSuffixes(), CargoSpec::GetArraySize(), NWidgetScenarioToolbarContainer::GetButtonArrangement(), NWidgetMainToolbarContainer::GetButtonArrangement(), IndustryDirectoryWindow::GetCargoTransportedPercentsIfValid(), GetCurrentLocale(), GetDistanceFromNearbyHouse(), GetDParam(), GetFreeUnitNumber(), GetFullFilename(), GetGenericCallbackResult(), IndustryDirectoryWindow::GetIndustryString(), AIIndustry::GetLastMonthProduction(), AIIndustry::GetLastMonthTransported(), AIIndustry::GetLastMonthTransportedPercentage(), GetMaskOfTownActions(), GetNetworkErrorMsg(), GetNewgrfCurrencyIdConverted(), GetNumberOfIndustries(), GRFFile::GetParam(), AIIndustryType::GetProducedCargo(), GetProductionAroundTiles(), AIIndustry::GetStockpiledCargo(), GetVehicleSpriteGroup(), AirportSpec::GetWithoutOverride(), GRFConfig::GRFConfig(), GRFLoadConfig(), HandleBiDiAndArabicShapes(), HelpDialogFunc(), IndustryCargoesWindow::HousesCanAccept(), IConsoleAliasExec(), IConsoleCmdExec(), IConsoleListSettings(), IndustryDirectoryWindow::IndustryProductionSorter(), InitializeLanguagePacks(), InitializeUnicodeGlyphMap(), InjectDParam(), InsertTextBufferClipboard(), AIIndustry::IsCargoAccepted(), IsCommandAllowedWhilePaused(), SmallSet< Tdir, items >::IsFull(), IsValidCommand(), NWidgetServerListHeader::IsWidgetVisible(), KeycodeToString(), LoadIntList(), LoadOldVehicle(), CrashLogWindows::LogModules(), CrashLogUnix::LogStacktrace(), LookupWithBuildOnSlopes(), MakeAustrianTownName(), CargoesRow::MakeCargoLabel(), MakeCatalanTownName(), MakeCzechTownName(), MakeDanishTownName(), MakeDutchTownName(), MakeEnglishAdditionalTownName(), MakeEnglishOriginalTownName(), MakeFinnishTownName(), MakeFrenchTownName(), MakeGermanTownName(), MakeHungarianTownName(), MakeItalianTownName(), MakeNorwegianTownName(), MakePerformanceDetailPanels(), MakePolishTownName(), MakeRomanianTownName(), MakeSillyTownName(), MakeSlovakTownName(), MakeSpanishTownName(), MakeSwedishTownName(), MakeSwissTownName(), MakeTurkishTownName(), NewGRFWindow::NameSorter(), NetworkAddChatMessage(), NewGRFDisplay(), NewGRFWindow::OnClick(), NetworkStartServerWindow::OnClick(), IndustryViewWindow::OnClick(), CheatWindow::OnClick(), SmallMapWindow::OnInit(), LandInfoWindow::OnInit(), MainWindow::OnPaint(), HighScoreWindow::OnPaint(), AboutWindow::OnTick(), OTTD2FS(), ParseCode(), Squirrel::PrintFunc(), NetworkHTTPSocketHandler::Receive(), NetworkGameSocketHandler::ReceiveCommand(), RemapTTOColour(), ResetGenericCallbacks(), ResetObjects(), Squirrel::RunError(), SaveHighScoreValue(), SaveVersionInConfig(), FileScanner::Scan(), ScanPath(), DriverFactoryBase::SelectDriver(), NetworkGameSocketHandler::SendCommand(), SetDParam(), GRFConfig::SetParameterDefaults(), QueryWindow::SetStringParameters(), ErrmsgWindow::SetStringParameters(), SetupCargoForClimate(), NWidgetScenarioToolbarContainer::SetupSmallestSize(), SmallMapWindow::SetZoomLevel(), ShowInfoF(), SlCalcConvFileLen(), SlCalcConvMemLen(), StateGameLoop(), StringToContentType(), strnatcmp(), TriggerIndustryProduction(), UpdateIndustryStatistics(), UpdateStationAcceptance(), VehicleDetailsWindow::UpdateWidgetSize(), BuildObjectWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), ErrmsgWindow::UpdateWidgetSize(), AboutWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), CompanyLeagueWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), CheatWindow::UpdateWidgetSize(), and usererror().

#define MAX_UVALUE ( type   )     ((type)~(type)0)

The largest value that can be entered in a variable.

Parameters:
type the type of the variable

Definition at line 439 of file stdafx.h.

Referenced by CompanyCheckBankrupt(), AirportTileSpec::Get(), Town::GetRandom(), Industry::GetRandom(), HandleBankruptcyTakeover(), Scrollbar::SetCapacity(), Scrollbar::SetCount(), and IConsoleLine::Truncate().


Function Documentation

const char* OTTD2FS ( const char *  name  ) 

Convert from OpenTTD's encoding to that of the local environment.

When the project is built in UNICODE the system codepage is irrelevant and the converted string is wide. In ANSI mode, the UTF8 string is converted to multi-byte. OpenTTD internal encoding is UTF8. The returned value's contents can only be guaranteed until the next call to this function. So if the value is needed for anything else, use convert_from_fs

Parameters:
name pointer to a valid string that will be converted (UTF8)
Returns:
pointer to the converted string; if failed string is of zero-length
See also:
the current code-page comes from video\win32_v.cpp, event-notification WM_INPUTLANGCHANGE

Definition at line 212 of file os2.cpp.

References convert_to_fs(), DEBUG, lastof, and lengthof.


Generated on Fri Mar 18 23:17:53 2011 for OpenTTD by  doxygen 1.6.1