ChibiOS/HAL  6.1.0
hal_objects.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file hal_objects.h
19  * @brief Base object.
20  * @details This header defines a base object that is the root for the
21  * inheritance system.
22  *
23  * @addtogroup HAL_BASE_OBJECT
24  * @details HAL uses concepts of Object Oriented Programming even if it
25  * is written in C. Things like simple inheritance, multiple
26  * inheritance and interfaces are used through the system.
27  * This module defines a "base object" that is the ancestor of
28  * all classes in the system.
29  * @{
30  */
31 
32 #ifndef HAL_OBJECTS_H
33 #define HAL_OBJECTS_H
34 
35 /**
36  * @brief @p BaseObject specific methods.
37  * @note This object defines no methods.
38  */
39 #define _base_object_methods \
40  /* Instance offset, used for multiple inheritance, normally zero. It
41  represents the offset between the current object and the container
42  object*/ \
43  size_t instance_offset;
44 
45 /**
46  * @brief @p BaseObject specific data.
47  * @note This object defines no data.
48  */
49 #define _base_object_data
50 
51 /**
52  * @brief @p BaseObject virtual methods table.
53  */
54 struct BaseObjectVMT {
56 };
57 
58 /**
59  * @brief Base stream class.
60  * @details This class represents a generic blocking unbuffered sequential
61  * data stream.
62  */
63 typedef struct {
64  /** @brief Virtual Methods Table.*/
65  const struct BaseObjectVMT *vmt;
67 } BaseObject;
68 
69 /**
70  * @name Macro Functions (BaseObject)
71  * @{
72  */
73 /**
74  * @brief Returns the instance pointer starting from an interface pointer.
75  *
76  * @param[in] type the type of the instance pointer, it is used for casting
77  * @param[in] ip the interface pointer
78  * @return A pointer to the object implementing the interface
79  */
80 #define objGetInstance(type, ip) \
81  (type)(((size_t)(ip)) - (ip)->vmt->instance_offset)
82 /** @} */
83 
84 #endif /* HAL_OBJECTS_H */
85 
86 /** @} */
Base stream class.
Definition: hal_objects.h:63
#define _base_object_data
BaseObject specific data.
Definition: hal_objects.h:49
#define _base_object_methods
BaseObject specific methods.
Definition: hal_objects.h:39
const struct BaseObjectVMT * vmt
Virtual Methods Table.
Definition: hal_objects.h:65
BaseObject virtual methods table.
Definition: hal_objects.h:54