mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
partial replacement of char arrays with std::string; minor updates, fixes and cleanup of mctools
This commit is contained in:
128
MemCell.cpp
128
MemCell.cpp
@@ -28,29 +28,37 @@ http://mozilla.org/MPL/2.0/.
|
||||
TMemCell::TMemCell(vector3 *p)
|
||||
{
|
||||
fValue1 = fValue2 = 0;
|
||||
szText = new char[256]; // musi być dla automatycznie tworzonych komórek dla odcinków
|
||||
// izolowanych
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
szText = new char[256]; // musi być dla automatycznie tworzonych komórek dla odcinków izolowanych
|
||||
#endif
|
||||
vPosition =
|
||||
p ? *p : vector3(0, 0, 0); // ustawienie współrzędnych, bo do TGroundNode nie ma dostępu
|
||||
bCommand = false; // komenda wysłana
|
||||
OnSent = NULL;
|
||||
}
|
||||
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
TMemCell::~TMemCell()
|
||||
{
|
||||
SafeDeleteArray(szText);
|
||||
}
|
||||
|
||||
#endif
|
||||
void TMemCell::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void TMemCell::UpdateValues(char *szNewText, double fNewValue1, double fNewValue2, int CheckMask)
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
void TMemCell::UpdateValues(char const *szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask)
|
||||
#else
|
||||
void TMemCell::UpdateValues( std::string const &szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask )
|
||||
#endif
|
||||
{
|
||||
if (CheckMask & update_memadd)
|
||||
{ // dodawanie wartości
|
||||
if (TestFlag(CheckMask, update_memstring))
|
||||
strcat(szText, szNewText);
|
||||
if( TestFlag( CheckMask, update_memstring ) )
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
strcat( szText, szNewText );
|
||||
#else
|
||||
szText += szNewText;
|
||||
#endif
|
||||
if (TestFlag(CheckMask, update_memval1))
|
||||
fValue1 += fNewValue1;
|
||||
if (TestFlag(CheckMask, update_memval2))
|
||||
@@ -58,8 +66,12 @@ void TMemCell::UpdateValues(char *szNewText, double fNewValue1, double fNewValue
|
||||
}
|
||||
else
|
||||
{
|
||||
if (TestFlag(CheckMask, update_memstring))
|
||||
strcpy(szText, szNewText);
|
||||
if( TestFlag( CheckMask, update_memstring ) )
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
strcpy( szText, szNewText );
|
||||
#else
|
||||
szText = szNewText;
|
||||
#endif
|
||||
if (TestFlag(CheckMask, update_memval1))
|
||||
fValue1 = fNewValue1;
|
||||
if (TestFlag(CheckMask, update_memval2))
|
||||
@@ -71,32 +83,56 @@ void TMemCell::UpdateValues(char *szNewText, double fNewValue1, double fNewValue
|
||||
|
||||
TCommandType TMemCell::CommandCheck()
|
||||
{ // rozpoznanie komendy
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
if (strcmp(szText, "SetVelocity") == 0) // najpopularniejsze
|
||||
#else
|
||||
if( szText == "SetVelocity" ) // najpopularniejsze
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_SetVelocity;
|
||||
bCommand = false; // ta komenda nie jest wysyłana
|
||||
}
|
||||
else if (strcmp(szText, "ShuntVelocity") == 0) // w tarczach manewrowych
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
else if( strcmp( szText, "ShuntVelocity" ) == 0 ) // w tarczach manewrowych
|
||||
#else
|
||||
else if( szText == "ShuntVelocity" ) // w tarczach manewrowych
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_ShuntVelocity;
|
||||
bCommand = false; // ta komenda nie jest wysyłana
|
||||
}
|
||||
else if (strcmp(szText, "Change_direction") == 0) // zdarza się
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
else if( strcmp( szText, "Change_direction" ) == 0 ) // zdarza się
|
||||
#else
|
||||
else if( szText == "Change_direction" ) // zdarza się
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_ChangeDirection;
|
||||
bCommand = true; // do wysłania
|
||||
}
|
||||
else if (strcmp(szText, "OutsideStation") == 0) // zdarza się
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
else if( strcmp( szText, "OutsideStation" ) == 0 ) // zdarza się
|
||||
#else
|
||||
else if( szText == "OutsideStation" ) // zdarza się
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_OutsideStation;
|
||||
bCommand = false; // tego nie powinno być w komórce
|
||||
}
|
||||
else if (strncmp(szText, "PassengerStopPoint:", 19) == 0) // porównanie początków
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
else if( strncmp( szText, "PassengerStopPoint:", 19 ) == 0 ) // porównanie początków
|
||||
#else
|
||||
else if( szText.compare( 0, 19, "PassengerStopPoint:" ) == 0 ) // porównanie początków
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_PassengerStopPoint;
|
||||
bCommand = false; // tego nie powinno być w komórce
|
||||
}
|
||||
else if (strcmp(szText, "SetProximityVelocity") == 0) // nie powinno tego być
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
else if( strcmp( szText, "SetProximityVelocity" ) == 0 ) // nie powinno tego być
|
||||
#else
|
||||
else if( szText == "SetProximityVelocity" ) // nie powinno tego być
|
||||
#endif
|
||||
{
|
||||
eCommand = cm_SetProximityVelocity;
|
||||
bCommand = false; // ta komenda nie jest wysyłana
|
||||
@@ -113,21 +149,25 @@ bool TMemCell::Load(cParser *parser)
|
||||
{
|
||||
std::string token;
|
||||
parser->getTokens(1, false); // case sensitive
|
||||
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
*parser >> token;
|
||||
SafeDeleteArray(szText);
|
||||
szText = new char[256]; // musi być bufor do łączenia tekstów
|
||||
strcpy(szText, token.c_str());
|
||||
parser->getTokens();
|
||||
*parser >> fValue1;
|
||||
parser->getTokens();
|
||||
*parser >> fValue2;
|
||||
#else
|
||||
*parser >> szText;
|
||||
#endif
|
||||
parser->getTokens( 2, false );
|
||||
*parser
|
||||
>> fValue1
|
||||
>> fValue2;
|
||||
parser->getTokens();
|
||||
*parser >> token;
|
||||
if (token.compare("none") != 0) // gdy różne od "none"
|
||||
if (token != "none") // gdy różne od "none"
|
||||
asTrackName = token; // sprawdzane przez IsEmpty()
|
||||
parser->getTokens();
|
||||
*parser >> token;
|
||||
if (token.compare("endmemcell") != 0)
|
||||
if (token != "endmemcell")
|
||||
Error("endmemcell statement missing");
|
||||
CommandCheck();
|
||||
return true;
|
||||
@@ -139,35 +179,22 @@ void TMemCell::PutCommand(TController *Mech, vector3 *Loc)
|
||||
Mech->PutCommand(szText, fValue1, fValue2, Loc);
|
||||
}
|
||||
|
||||
bool TMemCell::Compare(char *szTestText, double fTestValue1, double fTestValue2, int CheckMask)
|
||||
bool TMemCell::Compare(char const *szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask)
|
||||
{ // porównanie zawartości komórki pamięci z podanymi wartościami
|
||||
if (TestFlag(CheckMask, conditional_memstring))
|
||||
{ // porównać teksty
|
||||
/* char *pos = std::strstr(szTestText, "*"); // zwraca wskaźnik na pozycję albo NULL
|
||||
if( nullptr != pos ) { // porównanie fragmentu łańcucha
|
||||
int i = pos - szTestText; // ilość porównywanych znaków
|
||||
if( i ) { // jeśli nie jest pierwszym znakiem
|
||||
if( std::string( szTestText ).substr( 0, i ) != std::string( szText ).substr( 0, i ) ) {
|
||||
return false; // początki o długości (i) są różne
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( std::string( szTestText ) != std::string( szText ) ) {
|
||||
return false; //łąńcuchy są różne
|
||||
}
|
||||
*/ std::string
|
||||
source( szText ),
|
||||
std::string
|
||||
match( szTestText );
|
||||
auto range = match.find( '*' );
|
||||
if( range != std::string::npos ) {
|
||||
// compare string parts
|
||||
if( 0 != source.compare( 0, range, match, 0, range ) ) {
|
||||
if( 0 != szText.compare( 0, range, match, 0, range ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// compare full strings
|
||||
if( source != match ) {
|
||||
if( szText != match ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -177,6 +204,31 @@ bool TMemCell::Compare(char *szTestText, double fTestValue1, double fTestValue2,
|
||||
(!TestFlag(CheckMask, conditional_memval2) || (fValue2 == fTestValue2)));
|
||||
};
|
||||
|
||||
#ifndef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
|
||||
bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask ) {
|
||||
// porównanie zawartości komórki pamięci z podanymi wartościami
|
||||
if( TestFlag( CheckMask, conditional_memstring ) ) {
|
||||
// porównać teksty
|
||||
auto range = szTestText.find( '*' );
|
||||
if( range != std::string::npos ) {
|
||||
// compare string parts
|
||||
if( 0 != szText.compare( 0, range, szTestText, 0, range ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// compare full strings
|
||||
if( szText != szTestText ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// tekst zgodny, porównać resztę
|
||||
return ( ( !TestFlag( CheckMask, conditional_memval1 ) || ( fValue1 == fTestValue1 ) ) &&
|
||||
( !TestFlag( CheckMask, conditional_memval2 ) || ( fValue2 == fTestValue2 ) ) );
|
||||
};
|
||||
#endif
|
||||
|
||||
bool TMemCell::Render()
|
||||
{
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user