Attribute::Attribute(const DataColumn& col) { totalUnique = 0; name = col.Name(); PopulateMaps(col); totalEntities = col.size; }
int main(int argc, char **argv) { // This program should receive one parameter - the folder of compressed bits if(argc != 2) { std::cout << "Pass correct parameters. Usage: " << argv[0] << " <folder of compressed bit files" << std::endl; return -1; } // Check if the folder exist boost::filesystem::path libPath(argv[1]); if(!boost::filesystem::exists(libPath)) { std::cout << "The folder " << libPath.string().c_str() << " does not exist" << std::endl; return -1; } // Maps to store the information on tile type, elements and configs std::vector<ConfigBitMap> configMapVector; std::vector<ElementConfigMap> elementMapVector; TiletypeElementMap tileMap; // Write the database file to disk std::string dbFileName = kFamily + ".ldb"; boost::filesystem::path dbFilePath = libPath / dbFileName; std::ofstream dbFile(dbFilePath.string().c_str(), std::ofstream::binary); if(!dbFile.good()) { std::cout << "Could not open file " << dbFilePath.string() << " to write" << std::endl; return -1; } // Populate the maps PopulateMaps(libPath, tileMap, elementMapVector, configMapVector); std::cout << "Opened file " << dbFilePath.string() << " to store library database" << std::endl; dbFile.write("<<<<BITLIBDB>>>>", 16); // std::cout << "Tile map size " << sizeof(tileMap.size()) << std::endl; uint32_t dataSize; dataSize = tileMap.size(); dbFile.write((char *) (&dataSize), sizeof(dataSize)); // Now go over the map data structure and write it to a file // File format is given at the top of this file TiletypeElementMap::const_iterator pTiletypes = tileMap.begin(); TiletypeElementMap::const_iterator eTiletypes = tileMap.end(); while(pTiletypes != eTiletypes) { // Write the tile name char count, name string and element count dataSize = pTiletypes->first.size(); dbFile.write((const char *) &dataSize, sizeof(dataSize)); dbFile.write((const char *) pTiletypes->first.c_str(), pTiletypes->first.size()); dataSize = pTiletypes->second.size(); dbFile.write((const char*) &dataSize, sizeof(dataSize)); std::cout << "Tile type " << pTiletypes->first << " has " << pTiletypes->second.size() << " elements." << std::endl; // Iterate over elements ElementConfigMap::const_iterator pElements = pTiletypes->second.begin(); ElementConfigMap::const_iterator eElements = pTiletypes->second.end(); while(pElements != eElements) { // Write element name char count, name string and config count dataSize = pElements->first.size(); dbFile.write((const char *) &dataSize, sizeof(dataSize)); dbFile.write((const char *) pElements->first.c_str(), pElements->first.size()); dataSize = pElements->second.size(); dbFile.write((const char *) &dataSize, sizeof(dataSize)); // std::cout << " Element type " << pElements->first << " has " // << pElements->second.size() << " configs." << std::endl; // Itereate over configs ConfigBitMap::const_iterator pConfigs = pElements->second.begin(); ConfigBitMap::const_iterator eConfigs = pElements->second.end(); while(pConfigs != eConfigs) { // Write config namem char count, name string and count of bit addresses dataSize = pConfigs->first.size(); dbFile.write((const char *) &dataSize, sizeof(dataSize)); dbFile.write(pConfigs->first.c_str(), pConfigs->first.size()); dataSize = pConfigs->second.size(); dbFile.write((const char *) &dataSize, sizeof(dataSize)); // Write the bit addresses for(std::vector<uint32_t>::const_iterator iter = pConfigs->second.begin(); iter != pConfigs->second.end(); iter++) { dbFile.write((char *) &*iter, sizeof(uint32_t)); } // std::cout << "\t" << pConfigs->first << " " << pConfigs->second.size(); pConfigs++; } // std::cout << std::endl; pElements++; } pTiletypes++; } return 0; }