本文整理汇总了C++中FileHandle类的典型用法代码示例。如果您正苦于以下问题:C++ FileHandle类的具体用法?C++ FileHandle怎么用?C++ FileHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadLevels
unsigned char LevelManager::LoadLevels()
{
FileHandle f;
if (f.Open("Holes/course.db") != STATUS_OK)
{
return 0x2; // Failed to open file
}
char func[MAX_FUNC_SIZE], params[MAX_PARAM_SIZE];
while(!f.eof())
{
f.ReadLine('\n', func, params);
const string funcStr(func);
if (ExecuteCallback(__levelMgrFuncMap, funcStr, params, this) == STATUS_OK)
{
continue;
}
else if (ExecuteCallback(__levelFuncMap, funcStr, params, _levels->at(_levels->size() - 1)) == STATUS_OK)
{
continue;
}
// If this gets hit, then either the function specified in the file
// was incorrect, or there is no registered callback for that
// particular function
return 0x4;
}
f.Close();
return STATUS_OK;
}
示例2: test_sf_file_write_fhandle
bool test_sf_file_write_fhandle(const char *filename, const int kib_rw) {
bool result = true;
FileHandle* file = sd.open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if (file != NULL) {
int byte_write = 0;
timer.start();
for (int i = 0; i < kib_rw; i++) {
if (file->write(buffer, sizeof(buffer)) != sizeof(buffer)) {
result = false;
file->close();
printf("Write error!\r\n");
break;
} else {
byte_write++;
}
}
timer.stop();
file->close();
double test_time_sec = timer.read_us() / 1000000.0;
double speed = kib_rw / test_time_sec;
printf("%d KiB write in %.3f sec with speed of %.4f KiB/s\r\n", byte_write, test_time_sec, speed);
notify_performance_coefficient("write_kibps", speed);
} else {
printf("File '%s' not opened\r\n", filename);
result = false;
}
timer.reset();
return result;
}
示例3: m_hFileHandle
FileHandle::FileHandle(const FileHandle& handle)
: m_hFileHandle(fdopen(dup(fileno(handle.getHandle())), handle.getMode()))
, m_bIsOpen(handle.isOpen())
, m_szMode("rb")
, m_uiOffset(0)
{
}
示例4: TEST_F
//===----------------------------------------------------------------------===//
// Testcases
//===----------------------------------------------------------------------===//
TEST_F(ReadStageTest, quake) {
mcld::sys::fs::Path top_level = TOPDIR;
// set up output
m_pLinker->config()->output().setType(mcld::Output::DynObj);
m_pLinker->setOutput(top_level + "unittests/plasma.so");
// set up input
m_pLinker->addObject(top_level + "test/libs/ARM/Android/android-14/crtbegin_so.o");
m_pLinker->addObject(top_level + "test/Android/Plasma/ARM/plasma.o");
m_pLinker->addNameSpec("m");
m_pLinker->addNameSpec("log");
m_pLinker->addNameSpec("jnigraphics");
m_pLinker->addNameSpec("c");
m_pLinker->addObject(top_level + "test/libs/ARM/Android/android-14/crtend_so.o");
// dump status
m_pLinker->getDriver()->normalize();
FileHandle file;
file.open(top_level + "unittests/read_stage.xml",
FileHandle::ReadWrite | FileHandle::Create | FileHandle::Truncate, 0644);
InputTree::iterator input, inEnd = m_pLinker->config()->inputs().end();
for (input = m_pLinker->config()->inputs().begin(); input != inEnd; ++input) {
dumpInput(**input, file, 1);
}
dumpOutput(m_pLinker->config()->output(), file, 1);
// dump status
ASSERT_TRUE(m_pLinker->getDriver()->mergeSections());
}
示例5: _tmain
//void ConsumeData(void*)
//{
// while (!g_ProducerStarted)
// {
// Sleep(10);
// }
//
// FileHandle hConsumer = CreateFile(LN250FileName.c_str(),
// GENERIC_WRITE,
// FILE_SHARE_READ | FILE_SHARE_WRITE,
// NULL,
// OPEN_EXISTING, 0, NULL);
//
// if (!hConsumer.isValid())
// {
// UCSBUtility::LogError(__FUNCTION__, __FILE__, __LINE__, "Failed to open file %ls %d\\n", LN250FileName.c_str(),
// GetLastError());
// return;
// }
//
// char buffer[1024];
// DWORD totalRead = 0;
// while(g_ProducerStarted)
// {
// //DWORD size = GetFileSize(hFile, NULL);
// DWORD numRead = 0;
// ReadFile(hConsumer, &buffer, sizeof(buffer), &numRead, NULL);
// totalRead += numRead;
// Sleep(sleepConsumer);
// }
//
// UCSBUtility::LogError(__FUNCTION__, __FILE__, __LINE__, "Total Bytes Read %d\\n", totalRead);
//};
//
//
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hFile = CreateFile(LN250FileName.c_str(),
0,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS, 0, NULL);
CloseHandle(hFile);
FileHandle hProducer = CreateFile(LN250FileName.c_str(),
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS, 0, NULL);
if (!hProducer.isValid())
{
UCSBUtility::LogError(__FUNCTION__, __FILE__, __LINE__, "Failed to open file %ls %d\\n", LN250FileName.c_str(),
GetLastError());
return 1;
}
HANDLE hThread0 = (HANDLE) _beginthread(ProduceData, 0, (HANDLE)hProducer);
HANDLE hThread1 = (HANDLE) _beginthread(ProduceData, 0, (HANDLE)hProducer);
HANDLE handles[] = { hThread0, hThread1 };
WaitForMultipleObjects(2, handles, true, INFINITE);
return 0;
}
示例6: file
SmartPtr<VKShader>
VKDevice::create_shader (const char *file_name)
{
FileHandle file (file_name, "rb");
XCAM_FAIL_RETURN (
ERROR, file.is_valid (), NULL,
"VKDevice load shader failed when opend shader file:%s.",
XCAM_STR (file_name));
size_t file_size;
XCAM_FAIL_RETURN (
ERROR, xcam_ret_is_ok (file.get_file_size (file_size)) || file_size == 0, NULL,
"VKDevice load shader failed when read shader file:%s.",
XCAM_STR (file_name));
std::vector<uint32_t> content (XCAM_ALIGN_UP (file_size, 4) / 4, 0);
XCAM_FAIL_RETURN (
ERROR, xcam_ret_is_ok (file.read_file ((void *)content.data (), file_size)), NULL,
"VKDevice load shader failed when read shader file:%s.",
XCAM_STR (file_name));
file.close ();
SmartPtr<VKShader> shader = create_shader (content);
if (shader.ptr ())
shader->set_name (file_name);
return shader;
}
示例7: nextRecord
int PageDirectory::nextRecord(FileHandle &fh, RID &rid){
char buffer[PAGE_SIZE];
int pgid = rid.pageNum, slotid = -1;
RecordPage rp;
if (rid.pageNum != 0) {
fh.readPage(rid.pageNum, buffer);
rp = RecordPage(buffer);
if ((slotid = rp.nextRecord(rid.slotNum)) != -1) { // - 1 is current. + 0 is next
rid.slotNum = slotid;
return 0;
}
}
while (1) {
if ((pgid = nextRecordPageID(fh, pgid)) == -1)
return -1;
fh.readPage(pgid, buffer);
rp= RecordPage(buffer);
if ((slotid = rp.nextRecord(0)) != -1) {
rid.pageNum = pgid;
rid.slotNum = slotid;
return 0;
}
}
return -1;
}
示例8: file_close
void file_close(EngineState *s, int handle) {
debugC(2, kDebugLevelFile, "Closing file %d\n", handle);
FileHandle *f = getFileFromHandle(s, handle);
if (f)
f->close();
}
示例9: handleReference
// Open
//
// The caller gets a lock to the returned node handle.
status_t
ClientVolume::Open(Node* node, int openMode, FileHandle** _handle)
{
if (!node || !_handle)
return B_BAD_VALUE;
// open the node
FileHandle* handle = NULL;
status_t error = node->Open(openMode, &handle);
if (error != B_OK)
return error;
BReference<NodeHandle> handleReference(handle, true);
// lock the handle
handle->Lock();
// add the handle
error = fNodeHandles->AddNodeHandle(handle);
if (error != B_OK)
return error;
handleReference.Detach();
*_handle = handle;
return B_OK;
}
示例10: moveToNext
int PageDirectory::moveToNext(FileHandle &fh){
assert(get_next() != 0);
assert(get_pgnum() == PageDirectory::MaximunEntryNum());
fh.writePage(in_the_page, data);
in_the_page = get_next();
fh.readPage(in_the_page, data);
return in_the_page;
}
示例11: back
void PlayerManager::back()
{
m_playlistInterface->playPrevious();
FileHandle file = m_playlistInterface->currentFile();
if(!file.isNull())
play(file);
else
stop();
}
示例12: forward
void PlayerManager::forward()
{
m_playlistInterface->playNext();
FileHandle file = m_playlistInterface->currentFile();
if(!file.isNull())
play(file);
else
stop();
}
示例13: FileHandle
MemoryArea*
MemoryAreaFactory::produce(int pFD, FileHandle::OpenMode pMode)
{
FileHandle* handler = new FileHandle();
handler->delegate(pFD, pMode);
MemoryArea* result = allocate();
new (result) MemoryArea(*handler);
return result;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_frameworks_compile_mclinker,代码行数:11,代码来源:MemoryAreaFactory.cpp
示例14: emit
bool Linker::emit(int pFileDescriptor)
{
FileHandle file;
file.delegate(pFileDescriptor);
MemoryArea* output = new MemoryArea(file);
bool result = emit(*output);
delete output;
file.close();
return result;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_frameworks_compile_mclinker,代码行数:12,代码来源:Linker.cpp
示例15: parent
/** Returns a stream for writing to this file. Parent directories will be created if necessary.
* @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
* @throw GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
* {@link FileType#Internal} file, or if it could not be written. */
void FileHandle::write(bool append, ofstream& stream) const
{
FileHandle parentHandle = parent();
parentHandle.mkdirs();
std::ios_base::openmode mode;
mode = append? ios_base::out | ios_base::app: ios_base::out | ios_base::trunc;
stream.open(m_strFullPath.c_str(), mode);
if(stream.fail())
{
throw GdxRuntimeException("Error writing file: " + m_strFullPath);
}
}