diff options
author | Pixel <pixel@nobis-crew.org> | 2009-11-13 16:28:15 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-11-13 16:28:15 -0800 |
commit | 8c415c3658e7f344dc803431726b50942e432702 (patch) | |
tree | 5fda308ffe4420e6d1ebd9df67e7535b8069ee5e /include/Input.h | |
parent | c12806450806909177058eb8e7f85dcbd24cbf1c (diff) |
BigClean: Input & Archive are a little bit more threadsafe now.
Diffstat (limited to 'include/Input.h')
-rw-r--r-- | include/Input.h | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/include/Input.h b/include/Input.h index 208b185..66fa839 100644 --- a/include/Input.h +++ b/include/Input.h @@ -24,6 +24,8 @@ #include <time.h> #include <BString.h> #include <Handle.h> +#include <Atomic.h> +#include <LockSmith.h> enum ArchiveType { ARCHIVE_BUILTIN = 0, @@ -33,17 +35,17 @@ enum ArchiveType { class Input : public Handle { public: Input(const String & = "") throw (GeneralException); - Input(const Input &); - virtual ~Input() { nb_input--; } - virtual bool CanWrite() const; - virtual bool CanRead() const; + Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) { Atomic::Increment(&nb_input); } + virtual ~Input() { Atomic::Decrement(&nb_input); } + virtual bool CanWrite() const { return false; } + virtual bool CanRead() const { return true; } virtual bool CanSeek() const; virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException); - virtual String GetName() const; - virtual ssize_t GetSize() const; - virtual time_t GetModif() const; + virtual String GetName() const { return n; } + virtual ssize_t GetSize() const { return size; } + virtual time_t GetModif() const { return date_modif; } virtual void SetZ(int = 9) throw (GeneralException); - static int GetNbInput(); + static int GetNbInput() { return nb_input; } struct openresults_t { String name; @@ -66,10 +68,10 @@ class Input : public Handle { class Stdin_t : public Input { public: - Stdin_t(); + Stdin_t() {} virtual ~Stdin_t() {} - virtual bool CanSeek() const; - virtual String GetName() const; + virtual bool CanSeek() const { return false; } + virtual String GetName() const { return "Stdin"; } }; extern Stdin_t Stdin; @@ -78,10 +80,10 @@ class Archive : public Base { public: Archive(const String &, int = ARCHIVE_BUILTIN); Archive(Handle *, int = ARCHIVE_BUILTIN); - virtual ~Archive(); + virtual ~Archive() throw(GeneralException) { throw GeneralException("Archives ain't meant to be deleted."); } protected: static Archive * inarchive(const String &); - Handle * GetHandle(); + Handle * GetHandle() { return archive; } int open(const String &, Input::openresults_t *); private: void create() throw (GeneralException); @@ -90,12 +92,11 @@ class Archive : public Base { class FileTree : public Base { public: FileTree(const String & = "", size_t = 0, int = 0, FileTree * = 0); - virtual ~FileTree(); int compute_ptrs(size_t = 0); - FileTree * Father(); - FileTree * Child(); - FileTree * Next(); - FileTree * Prev(); + FileTree * Father() { return father; } + FileTree * Child() { return child; } + FileTree * Next() { return next; } + FileTree * Prev() { return prev; } String name; int type; size_t size; @@ -109,6 +110,7 @@ class Archive : public Base { int type; Archive * next, * prev; static Archive * header; + static iLock lock; friend class Input; }; |