File: Object.h

package info (click to toggle)
torch 2-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,488 kB
  • ctags: 3,217
  • sloc: cpp: 14,272; makefile: 201
file content (122 lines) | stat: -rw-r--r-- 3,432 bytes parent folder | download
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (C) 2002 Ronan Collobert (collober@iro.umontreal.ca)
//                
//
// This file is part of Torch. Release II.
// [The Ultimate Machine Learning Library]
//
// Torch 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.
//
// Torch 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 Torch; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#ifndef OBJECT_INC
#define OBJECT_INC

#include "general.h"
#include "random.h"

namespace Torch {

//-----

typedef struct Option_
{
    char *name;
    char *help;
    int size;
    void *ptr;
    bool is_allowed_after_init;
} Option;

//-----

/** Provides a useful interface for managing options.
    Class inherited by almost all classes in Torch.
    
    @author Ronan Collobert (collober@iro.umontreal.ca)
*/
class Object
{
  public:

    int n_options;
    Option *options;
    bool is_already_initialized;

    ///
    Object();
    
    //-----

    /** Initialize the object.
        All objects *MUST* call the #init()#
        function of their parents.
    */
    virtual void init();

    /** Add the option #name#.
        This one has a pointer on #ptr# and has the size #size#.
        You can provide an help in #help#.
        (Note that if #help# is empty, its an empty string and not NULL).
        If the option can be changed at any time, you can set
        #is_allowed_after_init# to #true#.
    */
    void addOption(const char *name, int size, void *ptr, const char *help="", bool is_allowed_after_init=false);

    /** Several wrappers of #addOption()# for
        Int, Real and Bool options.
        Be carefull: there is no type checking.
    */
    void addIOption(const char *name, int *ptr,  int init_value,  const char *help="", bool is_allowed_after_init=false);

    ///
    void addROption(const char *name, real *ptr, real init_value, const char *help="", bool is_allowed_after_init=false);

    ///
    void addBOption(const char *name, bool *ptr, bool init_value, const char *help="", bool is_allowed_after_init=false);

    /// Set the option #name# to the value contained at #ptr#.
    void setOption(const char *name, void *ptr);

    /** Several wrappers of #setOption()# for
        Int, Real and Bool options.
        Be carefull: there is no type checking.
    */
    void setIOption(const char *name, int option);

    ///
    void setROption(const char *name, real option);

    ///
    void setBOption(const char *name, bool option);

    /// Load the object from a file pointer (\emph{not the options})
    virtual void loadFILE(FILE *file);

    /// Save the object to a file pointer (\emph{not the options})
    virtual void saveFILE(FILE *file);

    /// Load the machine from a file name (\emph{not the options})
    void load(const char *filename);

    /// Save the machine to a file name (\emph{not the options})
    void save(const char *filename);

    //-----

    virtual ~Object();
};


}

#endif