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


C++ FileUtils类代码示例

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


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

示例1: LoadPlayerData

void CDataManager::LoadPlayerData()
{
	FileUtils* Utils = FileUtils::sharedFileUtils();
	string fString = FileUtils::sharedFileUtils()->getWritablePath() + "player_data.json";
	string szData;

	ssize_t fileSize;
	const char* stream = (char*)Utils->getFileData(fString, "rb", &fileSize);

	if (stream == NULL)
	{
		m_PlayerData.m_szName = "Guest";
		m_PlayerData.m_nStage1Count = 0;
		m_PlayerData.m_nStage2Count = 0;
		m_PlayerData.m_nStage3Count = 0;
	}
	else
	{
		string data = string((const char*)stream, fileSize);
		CC_SAFE_DELETE_ARRAY(stream);

		//Document doc;

		/*if (doc.Parse<0>(data.c_str()).HasParseError())
			CCLOG(doc.GetParseError());*/
		/*else
		{
			m_PlayerData.m_szName = doc["PlayerName"].GetString();
			m_PlayerData.m_nStage1Count = doc["Stage1"].GetInt();
			m_PlayerData.m_nStage2Count = doc["Stage2"].GetInt();
			m_PlayerData.m_nStage3Count = doc["Stage3"].GetInt();
		}*/
	}
}
开发者ID:godole,项目名称:Memory,代码行数:34,代码来源:DataManager.cpp

示例2: printFileUtils

static void printFileUtils(int fd)
{
    FileUtils* fu = FileUtils::getInstance();

    mydprintf(fd, "\nSearch Paths:\n");
    auto list = fu->getSearchPaths();
    for( const auto &item : list) {
        mydprintf(fd, "%s\n", item.c_str());
    }

    mydprintf(fd, "\nResolution Order:\n");
    list = fu->getSearchResolutionsOrder();
    for( const auto &item : list) {
        mydprintf(fd, "%s\n", item.c_str());
    }

    mydprintf(fd, "\nWriteble Path:\n");
    mydprintf(fd, "%s\n", fu->getWritablePath().c_str());

    mydprintf(fd, "\nFull Path Cache:\n");
    auto cache = fu->getFullPathCache();
    for( const auto &item : cache) {
        mydprintf(fd, "%s -> %s\n", item.first.c_str(), item.second.c_str());
    }
}
开发者ID:Abioy,项目名称:OpenBird,代码行数:25,代码来源:CCConsole.cpp

示例3: LoadResource

void ActorManager::LoadResource(const vector<Name>& resNameList)
{
	//1.打开文件
	FileUtils* fin = FileUtils::getInstance();
	Data data = fin->getDataFromFile("data/Actor.json");
	CCASSERT(!data.isNull(), "[Actor.json] Lost!");

	//2.载入json
	string str = string((char*)data.getBytes(), data.getSize());
	rapidjson::Document root;
	root.Parse<0>(str.c_str());
	CCASSERT(root.IsObject() && root.HasMember("actordata"), "illegal [Actor.json]");

	//3.读取json数据
	int Size = root["actordata"].Size();
	for (int i = 0; i < Size; i++) {
		string name = root["actordata"][i]["name"].GetString();
		if (std::find(resNameList.begin(), resNameList.end(), name) != resNameList.end())
		{
			ActorData d;
			d.defaultanimate=root["actordata"][i]["defaultanimate"].GetString();
			int size = root["actordata"][i]["actioncount"].GetInt();
			CCASSERT(size != 0, "framecount must NOT equal 0");
			for (int j = 0; j < size; j++) {
				d.maps[root["actordata"][i]["actionName"][j].GetString()] = root["actordata"][i]["animateName"][j].GetString();
			}
			m_actordata[name] = d;
		}
	}
}
开发者ID:aa13058219642,项目名称:My-Tower-Defents-Freamwork,代码行数:30,代码来源:ActorManager.cpp

示例4: LoadResponsesForTraining_new

void AnnHelper::LoadResponsesForTraining_new(std::vector<std::string> _files, cv::Mat& _response)
{
	FileUtils futils;
	MathUtils mathUtils;
	MatUtils matutils;
	Mat responses;

	for (string filename : _files)
	{
		//获取图片信息文件路径
		string fileinfo = filename.substr(0, filename.find_last_of('\\'));//目录
		fileinfo += "\\training_data_new.txt";
		//读取结果矩阵
		vector<string> matNames;
		vector<string> matStrs;
		futils.ReadMatFile(matStrs, matNames, fileinfo);
		assert(matStrs.size() > 0);

		int bcodeIndex = 0;//数值矩阵
		int bitIndex = 0;//位数矩阵

		for (int i = 0; i < matNames.size(); i++)
		{
			if (matNames[i] == "code")
			{
				bcodeIndex = i;
			}
			if (matNames[i] == "bit")
			{
				bitIndex = i;
			}
		}

		string bcode = "";
		Mat decCodeMat = matutils.ToMat(matStrs[bcodeIndex]);
		Mat bitMat = matutils.ToMat(matStrs[bitIndex]);
		assert(decCodeMat.cols == bitMat.cols);
		int bitNum=0;
		int bit = 0;
		for (int i = 0; i < decCodeMat.cols; i++)
		{
			bitNum = decCodeMat.at<float>(0, i);
			bit = bitMat.at<float>(0, i);
			bcode += mathUtils.ConvertToBinary(bitNum, bit);
		}
		stringstream ss;
		Mat resMat(1, bcode.length(), CV_32F);
		for (int i = 0; i < resMat.cols; i++)
		{
			ss << bcode[i];
			float ib = 0.;
			ss >> ib;
			resMat.at<float>(0, i) = ib;
			ss.clear();
		}
		matutils.AddMatRow(responses, resMat, responses);
	}
	_response = responses;
}
开发者ID:matinJ,项目名称:AnnClassifier,代码行数:59,代码来源:AnnHelper.cpp

示例5: onExit

void TestUnicodePath::onExit()
{
    
    FileUtils *sharedFileUtils = FileUtils::getInstance();
    sharedFileUtils->purgeCachedEntries();
    sharedFileUtils->setFilenameLookupDictionary(ValueMap());
    FileUtilsDemo::onExit();
}
开发者ID:anilgulgor,项目名称:myGame,代码行数:8,代码来源:FileUtilsTest.cpp

示例6: CCAssert

int LuaStack::executeScriptFile(const char* filename)
{
    CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename");
    
    static const std::string BYTECODE_FILE_EXT    = ".luac";
    static const std::string NOT_BYTECODE_FILE_EXT = ".lua";
    
    std::string buf(filename);
    //
    // remove .lua or .luac
    //
    size_t pos = buf.rfind(BYTECODE_FILE_EXT);
    if (pos != std::string::npos)
    {
        buf = buf.substr(0, pos);
    }
    else
    {
        pos = buf.rfind(NOT_BYTECODE_FILE_EXT);
        if (pos == buf.length() - NOT_BYTECODE_FILE_EXT.length())
        {
            buf = buf.substr(0, pos);
        }
    }
    
    FileUtils *utils = FileUtils::getInstance();
    //
    // 1. check .lua suffix
    // 2. check .luac suffix
    //
    std::string tmpfilename = buf + NOT_BYTECODE_FILE_EXT;
    if (utils->isFileExist(tmpfilename))
    {
        buf = tmpfilename;
    }
    else
    {
        tmpfilename = buf + BYTECODE_FILE_EXT;
        if (utils->isFileExist(tmpfilename))
        {
            buf = tmpfilename;
        }
    }
    
    std::string fullPath = utils->fullPathForFilename(buf);
    Data data = utils->getDataFromFile(fullPath);
    int rn = 0;
    if (!data.isNull())
    {
        if (luaLoadBuffer(_state, (const char*)data.getBytes(), (int)data.getSize(), fullPath.c_str()) == 0)
        {
            rn = executeFunction(0);
        }
    }
    return rn;
}
开发者ID:JustDo1989,项目名称:DragonBonesCPPForLua,代码行数:56,代码来源:CCLuaStack.cpp

示例7: setResourceRootPath

void Application::setResourceRootPath(const std::string& rootResDir)
{
    _resourceRootPath = rootResDir;
    if (_resourceRootPath[_resourceRootPath.length() - 1] != '/')
    {
        _resourceRootPath += '/';
    }
    FileUtils* pFileUtils = FileUtils::getInstance();
    std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
    searchPaths.insert(searchPaths.begin(), _resourceRootPath);
    pFileUtils->setSearchPaths(searchPaths);
}
开发者ID:BeemoLin,项目名称:daca,代码行数:12,代码来源:CCApplication-linux.cpp

示例8: initResourcePath

void AppDelegate::initResourcePath()
{
	FileUtils* sharedFileUtils = FileUtils::getInstance();
    std::string strBasePath = sharedFileUtils->getWritablePath();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)|| (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    sharedFileUtils->addSearchPath("res/");
#else
    sharedFileUtils->addSearchPath("../../res/");
#endif
    
    sharedFileUtils->addSearchPath(strBasePath + "upd/", true);
}
开发者ID:chenquanjun,项目名称:Cocos2dxEncyptAndUpdate,代码行数:13,代码来源:AppDelegate.cpp

示例9: FileUtils_createFile

static jboolean FileUtils_createFile(JNIEnv* env,jobject thiz,jstring filePath)
{
	FileUtils* fileUtils = (FileUtils*)env->GetIntField(thiz,fileUtilsFieldID);
	if(fileUtils == NULL)
		return -1;
	const jchar* jFilePath = env->GetStringChars(filePath,NULL);
	jsize j_size = env->GetStringLength(filePath);
	char* s_filePath = UTF16toUTF8((jchar*)jFilePath,(size_t*)&j_size);
	bool ret = fileUtils->createFile(s_filePath);
	env->ReleaseStringChars(filePath,jFilePath);
	free(s_filePath);
	return ret;
}
开发者ID:Andyload,项目名称:JniDemo,代码行数:13,代码来源:fileutils_jni.cpp

示例10: touch_file

void touch_file(bool single)
{
  FileUtils file;
  int ret = file.open("test1.txt", O_WRONLY | O_TRUNC | O_CREAT, 0644);
  ASSERT_NE(ret, 0);
  
  vector<string> v;
  gen_file(v, single);

  for (size_t i = 0;i < v.size();i++) {
    file.write(v[i].c_str(), v[i].size());
  }
  file.close();
}
开发者ID:Abioy,项目名称:oceanbase,代码行数:14,代码来源:test_file_reader.cpp

示例11: FileUtils

bool AdjustBMParam::saveParameters(){

    FileUtils* fileUtils = new FileUtils();

    QString fileName = fileUtils->saveFile();

    int preFilterSz = this->ui->preFilterSz->value();
    int preFilterCap = this->ui->preFilterCap->value();
    int sadWndSz = this->ui->SADWndSz->value();
    int minDisp = this->ui->minDisp->value();
    int numDisp = 16*(this->ui->numDisp->value());
    int texture = this->ui->textureth->value();
    int uniquness = this->ui->uniq->value();
    int spkWndSz = this->ui->speckleWndSz->value();
    int spkRange = this->ui->specklerange->value();

    if(sadWndSz%2==0)
        sadWndSz++;
    if(sadWndSz<5)
        sadWndSz = 5;

    if(preFilterSz%2==0)
        preFilterSz++;
    if(preFilterSz<5)
        preFilterSz = 5;


    CvFileStorage* fstorage = cvOpenFileStorage(fileName.toLocal8Bit().data(), NULL, CV_STORAGE_WRITE);
    if(fstorage == NULL){
        fprintf(stderr,"ERROR: File storage NULL!\n");
        return false;
    }

    cvWriteInt(fstorage, "preFilterSize", preFilterSz);
    cvWriteInt(fstorage, "preFilterCap", preFilterCap);
    cvWriteInt(fstorage, "sadWindowSize", sadWndSz);
    cvWriteInt(fstorage, "minDisp", minDisp);
    cvWriteInt(fstorage, "numDisp", numDisp);
    cvWriteInt(fstorage, "textureThreshold", texture);
    cvWriteInt(fstorage, "uniquness", uniquness);
    cvWriteInt(fstorage, "spkWindowSize", spkWndSz);
    cvWriteInt(fstorage,"spkRange", spkRange);

    cvReleaseFileStorage(&fstorage);

    delete fileUtils;

    return true;

}
开发者ID:asergiu,项目名称:camcalib,代码行数:50,代码来源:adjustbmparam.cpp

示例12: main

int main(int argc, char *argv[])
{
  FileUtils tools;
  std::string root(argv[1]);
  
  if(argc != 2)
  {
    std::cerr << "Usage: file_utils <root_directory>\n";
    return 1;
  }
  
  // Find all duplicate files start at root directory
  tools.FindDups(root);
  
}
开发者ID:cirick,项目名称:FileUtils,代码行数:15,代码来源:main.cpp

示例13: init

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    FileUtils *fu = FileUtils::getInstance();
    ValueMap vm = fu->getValueMapFromFile("data.plist");
    log("%s",vm["name"].asString().c_str());
    
    return true;
}
开发者ID:Chris-Xin,项目名称:Cocos2dXLessons20140303,代码行数:16,代码来源:HelloWorldScene.cpp

示例14: CCAssert

int LuaStack::executeScriptFile(const char* filename)
{
    CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename");

    FileUtils *utils = FileUtils::getInstance();
    std::string fullPath = utils->fullPathForFilename(filename);
    Data data = utils->getDataFromFile(fullPath);
    int rn = 0;
    if (!data.isNull()) {
        if (luaLoadBuffer(_state, (const char*)data.getBytes(), (int)data.getSize(), fullPath.c_str()) == 0) {
            rn = executeFunction(0);
        }
    }
    return rn;
}
开发者ID:JackTongy,项目名称:shared,代码行数:15,代码来源:CCLuaStack.cpp

示例15: if

bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("Bomberman", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
        glview = GLViewImpl::create("Bomberman");
#endif
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0f / 60);

    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
    auto frameSize = glview->getFrameSize();
    // if the frame's height is larger than the height of medium size.
    if (frameSize.height > mediumResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is larger than the height of small size.
    else if (frameSize.height > smallResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is smaller than the height of medium size.
    else
    {        
        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
    }

    register_all_packages();
	FileUtils* fileUtils = FileUtils::getInstance();
	fileUtils->addSearchPath("res");
    // create a scene. it's an autorelease object
    auto scene = GameStartScene::createScene();
    // run
    director->runWithScene(scene);
	CCLOG("Animation Interval = %f", director->getAnimationInterval());
    return true;
}
开发者ID:Jian0326,项目名称:Bomberman,代码行数:48,代码来源:AppDelegate.cpp


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