Initial commit
This commit is contained in:
231
application/demos/example.opengl/array.c
Normal file
231
application/demos/example.opengl/array.c
Normal file
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* This file is automaticaly generated, Please dont edit this file!
|
||||
*/
|
||||
#include <array.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int array_length( array * this ) {
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void * * array_data( array * this ) {
|
||||
|
||||
return this->items;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void * array_get( array * this, int index ) {
|
||||
|
||||
if ( index >= 0 && index < this->total ){
|
||||
|
||||
return this->items[index];
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void array_set( array * this, int index, void * item ) {
|
||||
|
||||
if ( index >= 0 && index < this->total ){
|
||||
|
||||
this->items[ index ] = item;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void array_resize( array * this, int capacity ) {
|
||||
|
||||
void * * items = realloc( this->items, sizeof( void * ) * capacity );
|
||||
|
||||
|
||||
this->items = items;
|
||||
|
||||
this->capacity = capacity;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void array_add( array * this, void * item ) {
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
array_resize( this, this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
this->items[ this->total++ ] = item;
|
||||
|
||||
}
|
||||
|
||||
|
||||
char * array_join( array * this, char * separator ) {
|
||||
|
||||
int count = array_length( this );
|
||||
|
||||
text * result = text_newPointer( "" );
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
|
||||
char * currentPart = this->items[ i ];
|
||||
|
||||
if( i > 0 ) {
|
||||
|
||||
text_append( result, separator );
|
||||
|
||||
}
|
||||
|
||||
text_append( result, currentPart );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return result->value;
|
||||
|
||||
}
|
||||
|
||||
void array_delete( array * this, int index ) {
|
||||
if ( index < 0 || index >= this->total ){
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
this->items[index] = NULL;
|
||||
|
||||
for ( int i = index; i < this->total - 1; i++ ) {
|
||||
|
||||
this->items[i] = this->items[i + 1];
|
||||
|
||||
this->items[i + 1] = NULL;
|
||||
|
||||
}
|
||||
|
||||
this->total--;
|
||||
|
||||
if ( this->total > 0 && this->total == this->capacity / 4 ){
|
||||
|
||||
array_resize( this, this->capacity / 2 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int array_array_push( array * this, void * item ) {
|
||||
|
||||
array_add( this, item );
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
void array_unshift( array * this, void * item ) {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
this->total++;
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
array_resize( this, this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
for ( int i = length - 1; i >= 0; --i ) {
|
||||
|
||||
this->items[ i + 1 ] = this->items[ i ];
|
||||
|
||||
}
|
||||
|
||||
this->items[ 0 ] = item;
|
||||
|
||||
}
|
||||
|
||||
void * array_pop( array * this ) {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
int lastIndex = length - 1;
|
||||
|
||||
void * lastItem = array_get( this, lastIndex );
|
||||
|
||||
array_delete( this, lastIndex );
|
||||
|
||||
return lastItem;
|
||||
|
||||
}
|
||||
|
||||
bool array_includes( array * this, char * value ) {
|
||||
|
||||
int count = array_length( this );
|
||||
|
||||
for ( int index = 0; index < count; ++index )
|
||||
{
|
||||
|
||||
char * currentText = array_get( this, index);
|
||||
|
||||
|
||||
|
||||
if( char_operator_compare( currentText , value) ) {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
array array_new() {
|
||||
|
||||
array instance;
|
||||
|
||||
instance.capacity = 10;
|
||||
|
||||
instance.total = 0;
|
||||
|
||||
instance.items = malloc( 10000000 );
|
||||
|
||||
return instance;
|
||||
|
||||
}
|
||||
|
||||
array * array_newPointer() {
|
||||
|
||||
struct array * pointer = malloc( sizeof ( struct array ) );
|
||||
|
||||
pointer->capacity = 10;
|
||||
|
||||
pointer->total = 0;
|
||||
|
||||
pointer->items = malloc( 10000000 );
|
||||
|
||||
return pointer;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user