mardi 1 octobre 2019

Is there a way to make this crossplatform?

Im trying to get rid of a platform dependent code.

This code gets a string formated by a mask ("%Y-%m-%d %H:%M:%S") and convert it to std::tm struct and a std::time seconds. Is there any way to make this code crossplatform (windows/linux) without using a factory pattern?

KDATETIME& KDATETIME::operator= (const char* k)
{
std::string smask;
smask = (std::string)this->mask;
std::string sk;
sk=k;
tm.tm_isdst=-1;

#ifdef WINDOWS    <<---- THIS BLOCK 

std::istringstream ss(sk);
ss >> std::get_time(&tm, smask.c_str());

#else

strptime(sk.c_str(), smask.c_str(), &tm);

#endif          <<------

this->time = mktime(&tm);  // t is now your desired time_t
[...]
}

Aucun commentaire:

Enregistrer un commentaire