本文整理汇总了C++中FileObject类的典型用法代码示例。如果您正苦于以下问题:C++ FileObject类的具体用法?C++ FileObject怎么用?C++ FileObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: amx_fwrite
// native fwrite(file, data, mode);
static cell AMX_NATIVE_CALL amx_fwrite(AMX *amx, cell *params)
{
FileObject* fp = reinterpret_cast<FileObject*>(params[1]);
if (!fp)
{
return 0;
}
cell data = params[2];
size_t size = params[3];
switch (size)
{
case BLOCK_CHAR:
{
char value = static_cast<char>(data);
return fp->Write(&value, sizeof(value));
}
case BLOCK_SHORT:
{
short value = static_cast<short>(data);
return fp->Write(&value, sizeof(value));
}
case BLOCK_INT:
{
int value = static_cast<int>(data);
return fp->Write(&value, sizeof(value));
}
}
return 0;
}
示例2: ERROR_MSG
//-------------------------------------------------------------------------------------
bool FileDataDownload::process()
{
ResourceObjectPtr fptr = Resmgr::getSingleton().openResource(path_.c_str(), "rb");
if(fptr == NULL || !fptr->valid())
{
ERROR_MSG(fmt::format("FileDataDownload::process(): can't open {}.\n",
Resmgr::getSingleton().matchRes(path_).c_str()));
error_ = true;
return false;
}
FileObject* f = static_cast<FileObject*>(fptr.get());
if(totalBytes_ == 0)
{
f->seek(0, SEEK_END);
totalBytes_ = f->tell();
}
f->seek(totalSentBytes_, SEEK_SET);
remainSent_ = f->read(stream_, 65535);
currSent_ = 0;
if(remainSent_ == 0)
remainSent_ = totalBytes_ - totalSentBytes_;
return false;
}
示例3: amx_fprintf
// native fprintf(file, const fmt[], any:...);
static cell AMX_NATIVE_CALL amx_fprintf(AMX *amx, cell *params)
{
FileObject* fp = reinterpret_cast<FileObject*>(params[1]);
if (!fp)
{
return 0;
}
int length;
const char* string = format_amxstring(amx, params, 2, length);
if (ValveFile *vfile = fp->AsValveFile())
{
return g_FileSystem->FPrintf(vfile->handle(), const_cast<char*>("%s"), string);
}
else if (SystemFile *sysfile = fp->AsSystemFile())
{
return fprintf(sysfile->handle(), "%s", string);
}
else
{
assert(false);
}
return 0;
}
示例4: readColladaFile
domCOLLADA* ColladaShapeLoader::readColladaFile(const String& path)
{
// Check if this file is already loaded into the database
domCOLLADA* root = sDAE.getRoot(path.c_str());
if (root)
return root;
// Load the Collada file into memory
FileObject fo;
if (!fo.readMemory(path))
{
daeErrorHandler::get()->handleError(avar("Could not read %s into memory", path.c_str()));
return NULL;
}
root = sDAE.openFromMemory(path.c_str(), (const char*)fo.buffer());
if (!root || !root->getLibrary_visual_scenes_array().getCount()) {
daeErrorHandler::get()->handleError(avar("Could not parse %s", path.c_str()));
return NULL;
}
// Fixup issues in the model
ColladaUtils::applyConditioners(root);
// Recursively load external DAE references
TSShapeLoader::updateProgress(TSShapeLoader::Load_ExternalRefs, "Loading external references...");
for (S32 iRef = 0; iRef < root->getDocument()->getReferencedDocuments().getCount(); iRef++) {
String refPath = (daeString)root->getDocument()->getReferencedDocuments()[iRef];
if (refPath.endsWith(".dae") && !readColladaFile(refPath))
daeErrorHandler::get()->handleError(avar("Failed to load external reference: %s", refPath.c_str()));
}
return root;
}
示例5: amx_fwrite_blocks
// native fwrite_blocks(file, const data[], blocks, mode);
static cell AMX_NATIVE_CALL amx_fwrite_blocks(AMX *amx, cell *params)
{
FileObject* fp = reinterpret_cast<FileObject*>(params[1]);
if (!fp)
{
return 0;
}
cell* data = get_amxaddr(amx, params[2]);
cell blocks = params[3];
cell size = params[4];
size_t read = 0;
switch (size)
{
case BLOCK_CHAR:
{
for (cell i = 0; i < blocks; ++i)
{
char value = data[i];
if (fp->Write(&value, sizeof(value)) != sizeof(value))
{
break;
}
read += sizeof(value);
}
break;
}
case BLOCK_SHORT:
{
for (cell i = 0; i < blocks; ++i)
{
short value = data[i];
if (fp->Write(&value, sizeof(value)) != sizeof(value))
{
break;
}
read += sizeof(value);
}
break;
}
case BLOCK_INT:
{
read = fp->Write(data, sizeof(cell) * blocks);
break;
}
default:
{
return 0;
}
}
return read / size;
}
示例6: strcpy
FileObject* FTPSession::FindPathObject(const char * filepath) {
if (!filepath)
return NULL;
char tempstr[MAX_PATH];
strcpy(tempstr, filepath);
FileObject * current = m_rootObject;
char * curname = strtok (tempstr, "/");
while(curname) {
if (current->GetChildCount() == 0) //search did not finish, but cannot find child
return NULL;
int i = 0;
int count = current->GetChildCount();
for(i = 0; i < count; i++) {
if ( !strcmp( current->GetChild(i)->GetName(), curname ) ) {
current = current->GetChild(i);
curname = strtok (NULL, "/");
break;
}
}
if (i == count) //none of the children match
return NULL;
}
return current;
}
示例7: edit
void FileCommands::edit(FileSystemUser* fileSystem, string fileName) {
FileObject* fo = fileSystem->getFileObject();
fileName += "$";
int t = fo->getObject(fileName);
if(t) {
fo->setPos(t);
string newContent;
char buff[512];
cout<<"enter new content: ";
cin.getline(buff, 512);
newContent = buff;
int begPos = fo->getBeginPos();
string sys = fileSystem->getSystem();
fo->go(fileName);
int beg = fo->getPos();
fo->setEndPos();
int end = fo->getPos();
sys.erase(beg, end-beg + 1);
sys.insert(beg, newContent);
fileSystem->setNewSystem(sys);
fo->setBeginPos(begPos);
fo->setFileContent(fileName, newContent);
}else {
notFoundFile(fileName);
return;
}
}
示例8: OnConnect
int FTPWindow::OnConnect(int code) {
if (code != 0) //automated connect
return 0;
FileObject * root = m_ftpSession->GetRootObject();
m_treeview.AddRoot(root);
FileObject * last = root;
while(last->GetChildCount() > 0) {
last = last->GetChild(0);
}
m_treeview.EnsureObjectVisible(last);
TreeView_Select(m_treeview.GetHWND(), last->GetData(), TVGN_CARET);
m_ftpSession->GetDirectory(last->GetPath());
TCHAR * info = SU::TSprintfNB(TEXT("Connected to %T"), m_ftpSession->GetCurrentProfile()->GetName());
SetInfo(info);
delete [] info;
SetToolbarState();
return 0;
}
示例9: lsdir
void FileCommands::lsdir(FileSystemUser* fileSystem) {
FileObject* fo = fileSystem->getFileObject();
cout<<endl;
vector<string> dirs = fo->getDirs();
for(int i = 0; i<dirs.size(); ++i) {
cout<<dirs[i]<<endl;
}
cout<<endl;
}
示例10: lsfile
void FileCommands::lsfile(FileSystemUser* fileSystem) {
FileObject* fo = fileSystem->getFileObject();
cout<<endl;
vector<string> files = fo->getFiles();
for(int i = 0; i<files.size(); ++i) {
cout<<files[i]<<endl;
}
cout<<endl;
}
示例11: amx_ftell
// native ftell(file);
static cell AMX_NATIVE_CALL amx_ftell(AMX *amx, cell *params)
{
FileObject* fp = reinterpret_cast<FileObject*>(params[1]);
if (!fp)
{
return 0;
}
return fp->Tell();
}
示例12: amx_fflush
// native fflush(file);
static cell AMX_NATIVE_CALL amx_fflush(AMX *amx, cell *params)
{
FileObject* fp = reinterpret_cast<FileObject*>(params[1]);
if (fp)
{
return fp->Flush();
}
return -1;
}
示例13: amx_feof
// native feof(file);
static cell AMX_NATIVE_CALL amx_feof(AMX *amx, cell *params)
{
FileObject* fp = reinterpret_cast<FileObject*>(params[1]);
if (fp)
{
return fp->EndOfFile();
}
return 1;
}
示例14: amx_fclose
// native fclose(file);
static cell AMX_NATIVE_CALL amx_fclose(AMX *amx, cell *params)
{
FileObject* fp = reinterpret_cast<FileObject*>(params[1]);
if (fp)
{
fp->Close();
}
return 1;
}
示例15: amx_fseek
// native fseek(file, position, start);
static cell AMX_NATIVE_CALL amx_fseek(AMX *amx, cell *params)
{
FileObject* fp = reinterpret_cast<FileObject*>(params[1]);
if (!fp)
{
return 0;
}
return !fp->Seek(params[2], params[3]);
}