Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Properties | Methods | Protected Attributes
IndexPath Struct Reference

#include <IndexPath.h>

Overview

Index paths represent the path to an element or node within a tree or graph structure.

Definition at line 40 of file IndexPath.h.

Inheritance diagram for IndexPath:
Object

Properties

size_t * indexes
 The indexes. More...
 
size_t length
 The length of indexes. More...
 
Object object
 The superclass. More...
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class. More...
 

Methods

Class_IndexPath (void)
 The IndexPath archetype. More...
 
size_t indexAtPosition (const IndexPath *self, size_t position)
 
IndexPathinitWithIndex (IndexPath *self, size_t index)
 Initializes this IndexPath with the specified index. More...
 
IndexPathinitWithIndexes (IndexPath *self, size_t *indexes, size_t length)
 Initializes this IndexPath with the specified indexes and length. More...
 
- Methods inherited from Object
Class_Object (void)
 The Object archetype. More...
 
Objectcopy (const Object *self)
 Creates a shallow copy of this Object. More...
 
void dealloc (Object *self)
 Frees all resources held by this Object. More...
 
Stringdescription (const Object *self)
 
int hash (const Object *self)
 
Objectinit (Object *self)
 Initializes this Object. More...
 
_Bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object. More...
 
_Bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership. More...
 

Protected Attributes

IndexPathInterface * interface
 The interface. More...
 
- Protected Attributes inherited from Object
ObjectInterface * interface
 The interface. More...
 

Property Details

◆ indexes

size_t* IndexPath::indexes

The indexes.

Definition at line 56 of file IndexPath.h.

◆ interface

IndexPathInterface* IndexPath::interface
protected

The interface.

Definition at line 51 of file IndexPath.h.

◆ length

size_t IndexPath::length

The length of indexes.

Definition at line 61 of file IndexPath.h.

◆ object

Object IndexPath::object

The superclass.

Definition at line 45 of file IndexPath.h.

Method Details

◆ _IndexPath()

Class * _IndexPath ( void  )

The IndexPath archetype.

Returns
The IndexPath Class.

Definition at line 180 of file IndexPath.c.

180 {
181 static Class *clazz;
182 static Once once;
183
184 do_once(&once, {
185 clazz = _initialize(&(const ClassDef) {
186 .name = "IndexPath",
187 .superclass = _Object(),
188 .instanceSize = sizeof(IndexPath),
189 .interfaceOffset = offsetof(IndexPath, interface),
190 .interfaceSize = sizeof(IndexPathInterface),
192 });
193 });
194
195 return clazz;
196}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void initialize(Class *clazz)
Definition: IndexPath.c:163
long Once
The Once type.
Definition: Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition: Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition: Class.h:41
The runtime representation of a Class.
Definition: Class.h:95
Index paths represent the path to an element or node within a tree or graph structure.
Definition: IndexPath.h:40
IndexPathInterface * interface
The interface.
Definition: IndexPath.h:51
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition: Object.h:51
Class * _Object(void)
The Object archetype.
Definition: Object.c:136

◆ indexAtPosition()

size_t indexAtPosition ( const IndexPath self,
size_t  position 
)
Parameters
selfThe IndexPath.
positionThe index position.
Returns
The index at the given position.

Definition at line 122 of file IndexPath.c.

122 {
123
124 assert(position < self->length);
125
126 return self->indexes[position];
127}
size_t * indexes
The indexes.
Definition: IndexPath.h:56
size_t length
The length of indexes.
Definition: IndexPath.h:61

◆ initWithIndex()

IndexPath * initWithIndex ( IndexPath self,
size_t  index 
)

Initializes this IndexPath with the specified index.

Parameters
selfThe IndexPath.
indexThe index.
Returns
The intialized IndexPath, or NULL on error.

Definition at line 133 of file IndexPath.c.

133 {
134 return $(self, initWithIndexes, &index, 1);
135}
IndexPath * initWithIndexes(IndexPath *self, size_t *indexes, size_t length)
Initializes this IndexPath with the specified indexes and length.
Definition: IndexPath.c:141

◆ initWithIndexes()

IndexPath * initWithIndexes ( IndexPath self,
size_t *  indexes,
size_t  length 
)

Initializes this IndexPath with the specified indexes and length.

Parameters
selfThe IndexPath.
indexesThe indexes.
lengthThe length of indexes.
Returns
The intialized IndexPath, or NULL on error.

Definition at line 141 of file IndexPath.c.

141 {
142
143 self = (IndexPath *) super(Object, self, init);
144 if (self) {
145
146 self->length = length;
147 assert(self->length);
148
149 self->indexes = calloc(sizeof(size_t), length);
150 assert(self->indexes);
151
152 memcpy(self->indexes, indexes, sizeof(size_t) * length);
153 }
154
155 return self;
156}
#define super(type, obj, method,...)
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46
Object * init(Object *self)
Initializes this Object.
Definition: Object.c:83

The documentation for this struct was generated from the following files: