2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations
2020-03-04
04:56 AM
- last edited on
2021-09-15
12:38 PM
by
Noemi Balogh
2020-03-04 02:16 PM
2020-03-05 06:03 AM
class CustomerData { public: GS::Guid guid; GS::UniString name; GS::UniString city; GS::UniString country; double aa; int ii; bool modified; bool markedAsDeleted; CustomerData () : modified (false), markedAsDeleted (false) { } CustomerData (const API_ModulData& modulData, const GS::UniString& modulName) : modified (false), markedAsDeleted (false) { guid.ConvertFromString (modulName); if (modulData.dataHdl != nullptr && modulData.dataVersion == 1) { IO::MemoryIChannel memChannel (*modulData.dataHdl, BMGetHandleSize (modulData.dataHdl)); if (modulData.platformSign != GS::Act_Platform_Sign) { GS::PlatformSign ps = (modulData.platformSign == GS::Win_Platform_Sign) ? GS::Win_Platform_Sign : ((modulData.platformSign == GS::Mac_Platform_Sign) ? GS::Mac_Platform_Sign : GS::Mactel_Platform_Sign); IO::SetPlatformIProtocol (memChannel, ps); } Read (memChannel); } } GSErrCode Read (GS::IChannel& ic) { name.Read (ic); city.Read (ic); country.Read (ic); return ic.GetInputStatus (); } GSErrCode Write (GS::OChannel& oc) const { name.Write (oc); city.Write (oc); country.Write (oc); return oc.GetOutputStatus (); } void GenerateRandomContent (void) { static const char firstNames[10][32] = { "Albert", "Alex", "Alfred", "Amy", "Andrew", "Angelina", "Anne", "Anthony", "Arnold", "Arthur" }; static const char familyNames[10][32] = { "Smith", "Johnson", "Williams", "Brown", "Jones", "Miller", "Davis", "Garcia", "Rodriguez", "Wilson" }; static const char cities[10][32] = { "San Francisco", "Budapest", "Amsterdam", "Venezia", "Helsinki", "Limassol", "Tokyo", "Barcelona", "Abuja", "Auckland" }; static const char countries[10][32] = { "United States", "Hungary", "Netherlands", "Italy", "Finland", "Cyprus", "Japan", "Spain", "Nigeria", "New Zeeland" }; Int32 firstNameIndex = rand () % 10; Int32 familyNameIndex = rand () % 10; Int32 locationIndex = rand () % 10; name = GS::UniString (firstNames[firstNameIndex]) + " " + GS::UniString (familyNames[familyNameIndex]); city = GS::UniString (cities[locationIndex]); country = GS::UniString (countries[locationIndex]); } };
static void ConvertModulesFromOldFormat (void) { GS::Array<GS::UniString> modulNameList; ACAPI_ModulData_GetList (&modulNameList); for (GS::Array<GS::UniString>::ConstIterator it = modulNameList.Enumerate (); it != nullptr; ++it) { const GS::UniString& oldModulName = *it; API_ModulData oldModulData; BNZeroMemory (&oldModulData, sizeof (API_ModulData)); if (ACAPI_ModulData_GetInfo (&oldModulData, oldModulName) == NoError) { if (oldModulData.dataVersion < 1) { // old version (all customers stored in the same moduldata) if (ACAPI_ModulData_Get (&oldModulData, oldModulName) == NoError) { IO::MemoryIChannel oldModulMemChannel (*oldModulData.dataHdl, BMGetHandleSize (oldModulData.dataHdl)); if (oldModulData.platformSign != GS::Act_Platform_Sign) { GS::PlatformSign ps = (oldModulData.platformSign == GS::Win_Platform_Sign) ? GS::Win_Platform_Sign : ((oldModulData.platformSign == GS::Mac_Platform_Sign) ? GS::Mac_Platform_Sign : GS::Mactel_Platform_Sign); IO::SetPlatformIProtocol (oldModulMemChannel, ps); } USize nObjects = 0; oldModulMemChannel.Read (nObjects); for (USize i = 0; i < nObjects; i++) { CustomerData customerData; customerData.guid.Generate (); customerData.Read (oldModulMemChannel); API_ModulData modulData; BNZeroMemory (&modulData, sizeof (API_ModulData)); modulData.dataVersion = 1; modulData.platformSign = GS::Act_Platform_Sign; IO::MemoryOChannel memChannel; if (customerData.Write (memChannel) == NoError) { BMPtrToHandle (memChannel.GetDestination (), &modulData.dataHdl, memChannel.GetDataSize ()); ACAPI_ModulData_Store (&modulData, customerData.guid.ToUniString ()); // store converted BMKillHandle (&modulData.dataHdl); } } } BMKillHandle (&oldModulData.dataHdl); ACAPI_ModulData_Delete (oldModulName); // delete old format } } } } // ConvertModulesFromOldFormatThis code uses the classes IChannel and OChannel to read and write to the class data.
2020-03-05 11:49 AM
2020-03-09 03:26 AM