summaryrefslogtreecommitdiffstats
path: root/tdefile-plugins/torrent/bbase.h
blob: 7a4693c6c3aba58956cfb3bf89437e776b9ec56b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright (c) 2003, 2004 Michael Pyne <michael.pyne@kdemail.net>
 *
 * This software is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; see the file COPYING.
 * If not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
#ifndef _BBASE_H
#define _BBASE_H

#include <ksharedptr.h>

class TQIODevice;

/**
 * Abstract base class for the b-encoded types.  Re-implemented
 * by BInt, BList, BDict, and BString.  Derive from this class in
 * order to make a new type for the b-encoding suite.  Classes
 * derived from this one should not throw exceptions.  Instead,
 * they should implement isValid(), and allow calling modules to
 * check error status that way.
 *
 * @author Michael Pyne <mpyne@grammarian.homelinux.net>
 * @see BInt, BList, BDict, BString, TDESharedPtr
 */

// Derive from TDEShared to enable use of TDESharedPtr.
class BBase : public TDEShared
{
    public:

    /**
     * Identifies the particular class that has been instantiated.  All
     * subclasses of this class should have an identifier here.
     */
    enum classID { 
        bBase,   /**< This class is BBase.  No subclass should return this. */
        bString, /**< This class is a BString. */
        bInt,    /**< This class is a BInt. */
        bList,   /**< This class is a BList. */
        bDict    /**< This class is a BDict. (Dictionary/Map) */
    };

    /**
     * Returns the type identification of the object.  It will
     * be a value in the classID enum.  A subclass of this class
     * must implement this function.
     *
     * @return type identifier of the class
     * @see classID
     */
    virtual classID type_id() const = 0;

    /**
     * Destructor for the class.  This function must be reimplemented
     * in subclasses.
     */
    virtual ~BBase () { ; }

    /**
     * Returns the validity status of the object.  Newly constructed
     * objects are invalid unless the initialization sequence completed
     * successfully.
     *
     * @return the validity status of the object
     */
    virtual bool isValid() const = 0;
    
    /**
     * Outputs the b-encoded representation of the object to the given
     * TQIODevice.
     * @param device the TQIODevice to write to
     * @return true on a successful write, false otherwise
     */
    virtual bool writeToDevice (TQIODevice &device) = 0;
};

#endif /* _BBASE_H */

// vim: set et sw=4 ts=4: