当前位置: 首页>>代码示例>>C++>>正文


C++ CDatabase::createFromScratch方法代码示例

本文整理汇总了C++中CDatabase::createFromScratch方法的典型用法代码示例。如果您正苦于以下问题:C++ CDatabase::createFromScratch方法的具体用法?C++ CDatabase::createFromScratch怎么用?C++ CDatabase::createFromScratch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CDatabase的用法示例。


在下文中一共展示了CDatabase::createFromScratch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getDatabase

/*
 * Load a database and adapt to the description if needed
 */
CDatabase*	CDbManager::loadDatabase(TDatabaseId id, const string& description, CLog* log)
{
	CHECK_DB_MGR_INIT(loadDatabase, false);

	nlinfo("CDbManager::loadDatabase(): load/setup database '%d'", id);

	CDatabase*	db = getDatabase(id);

	// database not loaded yet?
	if (db == NULL)
	{
		// create a memory image
		db = createDatabase(id, log);
		if (db == NULL)
		{
			log->displayNL("failed to create database '%d'", id);
			return NULL;
		}

		// if can't load database
		if (!db->loadState())
		{
			nlinfo("CDbManager::loadDatabase(): database '%d' doesn't exist, create new", id);

			// create a new database with the new description
			if (!db->createFromScratch(description))
			{
				log->displayNL("failed to create database '%d' from scratch", id);
				return NULL;
			}

			return db;
		}
	}

	CDatabase*	adapted = db->adapt(description);
	if (adapted ==  NULL)
	{
		log->displayNL("failed to adapt database '%s' to new description", db->getName().c_str());
		return NULL;
	}

	// database changed?
	if (db != adapted)
	{
		// replace old on with new one
		_DatabaseMap[id] = adapted;
		// and delete old
		delete db;
	}

	return adapted;
}
开发者ID:,项目名称:,代码行数:56,代码来源:

示例2: buildReference

/*
 * Adapt database to new description
 * \param description is the latest xml description of the database
 * \returns true is adaptation succeded
 */
CDatabase*	CDatabase::adapt(const string& description)
{
	PDS_DEBUG("adapt()");

	if (!initialised())
	{
		PDS_WARNING("adapt(): failed, database not initialised");
		return NULL;
	}

	// get 'From' HashKey
	CHashKey	hash1 = _Description.getHashKey();
	// get 'Into' HashKey
	CHashKey	hash2 = getSHA1((const uint8*)(description.c_str()), (uint32)description.size());

	// same hash, ok go on
	if (hash1 == hash2)
		return this;

	// build a clean reference if needed
	if (!isReferenceUpToDate())
	{
		if (!buildReference())
		{
			PDS_WARNING("adapt(): failed to buildReference()");
			return false;
		}
	}

	// backup old reference
	if (!_Reference.save(_Reference.getPath()+"ref"))
	{
		PDS_WARNING("adapt(): failed to backup reference index");
	}

	// create a new destination database
	CDatabase*	into = new CDatabase(_State.Id);

	if (!into->createFromScratch(description))
	{
		PDS_WARNING("adapt(): failed to create new reference");
		delete into;
		return NULL;
	}

	CDatabaseAdapter	adapter;

	if (!adapter.build(this, into))
	{
		PDS_WARNING("adapt(): failed to build() adapter");
		delete into;
		return NULL;
	}

	if (!adapter.buildContent())
	{
		PDS_WARNING("adapt(): adapter failed to buildContent()");
		delete into;
		return NULL;
	}

	// rebuild volatile data
	// that is all non persistant data that can be found from persistant data
	if (!into->rebuildVolatileData())
	{
		PDS_WARNING("adapt(): failed to rebuildVolatileData()");
		delete into;
		return NULL;
	}

	// init timestamps as database is ready to run
	into->initTimestamps();

	return into;
}
开发者ID:,项目名称:,代码行数:80,代码来源:


注:本文中的CDatabase::createFromScratch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。