Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
File.h
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "AddonClass.h"
12#include "AddonString.h"
13#include "LanguageHook.h"
14#include "commons/Buffer.h"
15#include "filesystem/File.h"
16
17#include <algorithm>
18
19namespace XBMCAddon
20{
21
22 namespace xbmcvfs
23 {
24
25 //
57 //
58 class File : public AddonClass
59 {
60 XFILE::CFile* file;
61 public:
62 inline File(const String& filepath, const char* mode = NULL) : file(new XFILE::CFile())
63 {
64 DelayedCallGuard dg(languageHook);
65 if (mode && strncmp(mode, "w", 1) == 0)
66 file->OpenForWrite(filepath,true);
67 else
68 file->Open(filepath, XFILE::READ_NO_CACHE);
69 }
70
71 inline ~File() override { delete file; }
72
73#if !defined(DOXYGEN_SHOULD_USE_THIS)
74 inline File* __enter__() { return this; }
75 inline void __exit__() { close(); }
76#endif
77
78#ifdef DOXYGEN_SHOULD_USE_THIS
108 read(...);
109#else
110 inline String read(unsigned long numBytes = 0)
111 {
112 XbmcCommons::Buffer b = readBytes(numBytes);
113 return b.getString(numBytes == 0 ? b.remaining() : std::min((unsigned long)b.remaining(),numBytes));
114 }
115#endif
116
117#ifdef DOXYGEN_SHOULD_USE_THIS
148#else
149 XbmcCommons::Buffer readBytes(unsigned long numBytes = 0);
150#endif
151
152#ifdef DOXYGEN_SHOULD_USE_THIS
181 write(...);
182#else
183 bool write(XbmcCommons::Buffer& buffer);
184#endif
185
186#ifdef DOXYGEN_SHOULD_USE_THIS
215#else
216 inline long long size() { DelayedCallGuard dg(languageHook); return file->GetLength(); }
217#endif
218
219#ifdef DOXYGEN_SHOULD_USE_THIS
250 seek(...);
251#else
252 inline long long seek(long long seekBytes, int iWhence = SEEK_SET) { DelayedCallGuard dg(languageHook); return file->Seek(seekBytes,iWhence); }
253#endif
254
255#ifdef DOXYGEN_SHOULD_USE_THIS
285#else
286 inline long long tell() { DelayedCallGuard dg(languageHook); return file->GetPosition(); }
287#endif
288
289#ifdef DOXYGEN_SHOULD_USE_THIS
315#else
316 inline void close() { DelayedCallGuard dg(languageHook); file->Close(); }
317#endif
318
319#ifndef SWIG
320 inline const XFILE::CFile* getFile() const { return file; }
321#endif
322
323 };
325 }
326}
Definition File.h:59
read(...)
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
write(...)
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
seek(...)
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
size()
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
tell()
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
readBytes(...)
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
close()
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...