File: hdrl_parameter.c

package info (click to toggle)
cpl-plugin-xshoo 2.8.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,168 kB
  • sloc: ansic: 146,236; sh: 11,433; python: 2,342; makefile: 1,024
file content (163 lines) | stat: -rw-r--r-- 4,784 bytes parent folder | download | duplicates (9)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* $Id: hdrl_parameter.c,v 1.3 2013-10-10 13:47:35 jtaylor Exp $
 *
 * This file is part of the HDRL
 * Copyright (C) 2013 European Southern Observatory
 *
 * This program 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 program 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 program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 * $Author: jtaylor $
 * $Date: 2013-10-10 13:47:35 $
 * $Revision: 1.3 $
 * $Name: not supported by cvs2svn $
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/*-----------------------------------------------------------------------------
                                   Includes
 -----------------------------------------------------------------------------*/

#include "hdrl_parameter.h"
#include "hdrl_parameter_defs.h"
#include <cpl.h>

#include <stddef.h>
#include <assert.h>

/*----------------------------------------------------------------------------*/
/**
 * @defgroup hdrl_parameter   Parameter object
 *
 * The hdrl_parameter is the base object to store various hierarchical
 * parameters. It only provides the deletion functions, the parameters
 * themselves are implemented in their respective modules.
 *
 * @internal
 * see hdrl_parameter-test.c for an example usage
 */
/*----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
                                   Functions
 -----------------------------------------------------------------------------*/

/**@{*/

/** @cond PRIVATE */

/* ---------------------------------------------------------------------------*/
/**
 * @internal
 * @brief create new parameter of certain type
 *
 * @param type  type object which defines the type of the parameter
 *
 * @return hdrl_parameter of type 'typeobj'
 */
/* ---------------------------------------------------------------------------*/
hdrl_parameter * hdrl_parameter_new(const hdrl_parameter_typeobj * typeobj)
{
    hdrl_parameter * p = typeobj->fp_alloc(typeobj->obj_size);
    p->base = typeobj;
    return p;
}

/* ---------------------------------------------------------------------------*/
/**
 * @internal
 * @brief check if a parameter is of a certain type
 *
 * @param self  parameter to check
 * @param type  type required
 *
 * @return true iff parameter is of type "type"
 */
/* ---------------------------------------------------------------------------*/
int hdrl_parameter_check_type(const hdrl_parameter * self,
                              const hdrl_parameter_typeobj * type)
{
    /* we can't compare the base pointers as they may be different in recipes
     * and libraries when static linking */
    if (self) {
        return ((hdrl_parameter_typeobj *)self->base)->type == type->type;
    }
    else {
        return 0;
    }
}


/* ---------------------------------------------------------------------------*/
/**
 * @internal
 * @brief get typeobject of parameter
 *
 * @param self  parameter to check
 * @return pointer to type object
 *
 */
/* ---------------------------------------------------------------------------*/
const hdrl_parameter_typeobj * hdrl_parameter_get_type(const hdrl_parameter * self)
{
    return self->base;
}

/** @endcond */

/* ---------------------------------------------------------------------------*/
/**
 * @brief shallow delete of a parameter
 *
 * @param obj parameter to delete, may be NULL
 *
 * will not delete sub parameters
 * @see hdrl_parameter_destroy
 */
/* ---------------------------------------------------------------------------*/
void hdrl_parameter_delete(hdrl_parameter * obj)
{
    if (obj) {
        obj->base->fp_free(obj);
    }
}

/* ---------------------------------------------------------------------------*/
/**
 * @brief deep delete of a parameter
 *
 * @param obj parameter to delete, may be NULL
 *
 * deletes all sub parameters via the registered deep destructor
 */
/* ---------------------------------------------------------------------------*/
void hdrl_parameter_destroy(hdrl_parameter * obj)
{
    if (obj == NULL) {
        return;
    }

    if (obj->base->fp_destroy) {
        obj->base->fp_destroy(obj);
    }
    else {
        obj->base->fp_free(obj);
    }
}

/**@}*/