Structures and services for compatibility with the C language

Introduced classes

abstract class CArray[E: nullable Object]

c :: CArray

A thin wrapper around a NativeCArray adding length information
class CByteArray

c :: CByteArray

Wrapper around an array of unsigned char in C (unsigned char*) with length and destroy state
class CCStringArray

c :: CCStringArray

Wrapper around an array of CString in C (char**) with length and destroy state.
class CIntArray

c :: CIntArray

Wrapper around an array of int in C (int*) with length and destroy state
class CUInt16Array

c :: CUInt16Array

Wrapper of a C array of type uint16_t* with length and destroy state
extern class NativeCArray

c :: NativeCArray

A native C array, as in a pointer to the first element of the array
extern class NativeCByteArray

c :: NativeCByteArray

An array of unsigned char in C (unsigned char*)
extern class NativeCIntArray

c :: NativeCIntArray

An array of int in C (int*)
extern class NativeCStringArray

c :: NativeCStringArray

An array of CString in C (char**)
extern class NativeCUInt16Array

c :: NativeCUInt16Array

An array of uint16_t in C

Redefined classes

redef extern class CString

c :: c $ CString

C string char *

All class definitions

abstract class CArray[E: nullable Object]

c $ CArray

A thin wrapper around a NativeCArray adding length information
class CByteArray

c $ CByteArray

Wrapper around an array of unsigned char in C (unsigned char*) with length and destroy state
class CCStringArray

c $ CCStringArray

Wrapper around an array of CString in C (char**) with length and destroy state.
class CIntArray

c $ CIntArray

Wrapper around an array of int in C (int*) with length and destroy state
redef extern class CString

c :: c $ CString

C string char *
class CUInt16Array

c $ CUInt16Array

Wrapper of a C array of type uint16_t* with length and destroy state
extern class NativeCArray

c $ NativeCArray

A native C array, as in a pointer to the first element of the array
extern class NativeCByteArray

c $ NativeCByteArray

An array of unsigned char in C (unsigned char*)
extern class NativeCIntArray

c $ NativeCIntArray

An array of int in C (int*)
extern class NativeCStringArray

c $ NativeCStringArray

An array of CString in C (char**)
extern class NativeCUInt16Array

c $ NativeCUInt16Array

An array of uint16_t in C
package_diagram c::c c core core c::c->core android::load_image load_image android::load_image->c::c glesv2::glesv2 glesv2 glesv2::glesv2->c::c mongodb::native_mongodb native_mongodb mongodb::native_mongodb->c::c mpi::mpi mpi mpi::mpi->c::c gamnit::display_android display_android gamnit::display_android->android::load_image gamnit::display_android... ... gamnit::display_android...->gamnit::display_android gamnit::display display gamnit::display->glesv2::glesv2 glesv2::opengles2_hello_triangle opengles2_hello_triangle glesv2::opengles2_hello_triangle->glesv2::glesv2 gamnit::display... ... gamnit::display...->gamnit::display glesv2::opengles2_hello_triangle... ... glesv2::opengles2_hello_triangle...->glesv2::opengles2_hello_triangle mongodb::mongodb mongodb mongodb::mongodb->mongodb::native_mongodb mongodb::mongodb... ... mongodb::mongodb...->mongodb::mongodb mpi::mpi_simple mpi_simple mpi::mpi_simple->mpi::mpi mpi::mpi_simple... ... mpi::mpi_simple...->mpi::mpi_simple

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module math

core :: math

Mathematical operations
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O

Parents

module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.

Children

module glesv2

glesv2 :: glesv2

OpenGL graphics rendering library for embedded systems, version 2.0
module load_image

android :: load_image

Low-level services to load pixel data from the assets
module mpi

mpi :: mpi

Implementation of the Message Passing Interface protocol by wrapping OpenMPI
module native_mongodb

mongodb :: native_mongodb

Native wrapper for the MongoDB C Driver

Descendants

module a_star-m

a_star-m

module android19

gamnit :: android19

Variation using features from Android API 19
module bmfont

gamnit :: bmfont

Parse Angel Code BMFont format and draw text
module camera_control

gamnit :: camera_control

Simple camera control for user, as the method accept_scroll_and_zoom
module camera_control_android

gamnit :: camera_control_android

Two fingers camera manipulation, pinch to zoom and slide to scroll
module camera_control_linux

gamnit :: camera_control_linux

Mouse wheel and middle mouse button to control camera
module cameras

gamnit :: cameras

Camera services producing Model-View-Projection matrices
module cameras_cache

gamnit :: cameras_cache

Cache the Matrix produced by Camera::mvp_matrix
module cardboard

gamnit :: cardboard

Update the orientation of world_camera at each frame using the head position given by android::cardboard
module depth

gamnit :: depth

Framework for 3D games in Nit
module depth_core

gamnit :: depth_core

Base entities of the depth 3D game framework
module display

gamnit :: display

Abstract display services
module display_android

gamnit :: display_android

Gamnit display implementation for Android
module display_ios

gamnit :: display_ios

Gamnit display implementation for iOS
module display_linux

gamnit :: display_linux

Gamnit display implementation for GNU/Linux using egl, sdl and x11
module dynamic_resolution

gamnit :: dynamic_resolution

Virtual screen with a resolution independent from the real screen
module egl

gamnit :: egl

Use of EGL to implement Gamnit on GNU/Linux and Android
module flat

gamnit :: flat

Simple API for 2D games, built around Sprite and App::update
module flat_core

gamnit :: flat_core

Core services for the flat API for 2D games
module font

gamnit :: font

Abstract font drawing services, implemented by bmfont and tileset
module gamnit

gamnit :: gamnit

Game and multimedia framework for Nit
module gamnit_android

gamnit :: gamnit_android

Support services for Gamnit on Android
module gamnit_ios

gamnit :: gamnit_ios

Support services for gamnit on iOS
module gamnit_linux

gamnit :: gamnit_linux

Support services for Gamnit on GNU/Linux
module input_ios

gamnit :: input_ios

Gamnit event support for iOS
module keys

gamnit :: keys

Simple service keeping track of which keys are currently pressed
module limit_fps

gamnit :: limit_fps

Frame-rate control for applications
module loader

github :: loader

module model_dimensions

gamnit :: model_dimensions

Dimensions related services for Model and Mesh
module mongodb

mongodb :: mongodb

MongoDB Nit Driver.
module more_lights

gamnit :: more_lights

More implementations of Light
module more_materials

gamnit :: more_materials

Various material implementations
module more_meshes

gamnit :: more_meshes

More simple geometric meshes
module more_models

gamnit :: more_models

Services to load models from the assets folder
module opengles2_hello_triangle

glesv2 :: opengles2_hello_triangle

Basic example of OpenGL ES 2.0 usage using SDL 2
module particles

gamnit :: particles

Particle effects
module pop_repos

popcorn :: pop_repos

Repositories for data management.
module programs

gamnit :: programs

Services for graphical programs with shaders, attributes and uniforms
module queries

mongodb :: queries

Mongo queries framework
module selection

gamnit :: selection

Select Actor from a screen coordinate
module sensors

android :: sensors

Access Android sensors
module shadow

gamnit :: shadow

Shadow mapping using a depth texture
module stereoscopic_view

gamnit :: stereoscopic_view

Refine EulerCamera and App::frame_core_draw to get a stereoscopic view
module textures

gamnit :: textures

Load textures, create subtextures and manage their life-cycle
module tileset

gamnit :: tileset

Support for TileSet, TileSetFont and drawing text with TextSprites
module virtual_gamepad

gamnit :: virtual_gamepad

Virtual gamepad mapped to keyboard keys for quick and dirty mobile support
module vr

gamnit :: vr

VR support for gamnit depth, for Android only
# Structures and services for compatibility with the C language
module c

import core
intrude import core::collection::array

# A thin wrapper around a `NativeCArray` adding length information
abstract class CArray[E]
	super AbstractArrayRead[E]

	# The corresponding C type
	type NATIVE: NativeCArray

	# Pointer to the real C array
	var native_array: NATIVE is noinit

	init(length: Int) is old_style_init do self._length = length

	redef fun [](index)
	do
		assert not destroyed
		assert index >= 0 and index < length
		return native_array[index]
	end

	# Set `val` at `index`.
	fun []=(index: Int, val: E)
	do
		assert not destroyed
		assert index >= 0 and index < length
		native_array[index] = val
	end

	# Was this instance destroyed?
	#
	# See `CArray::destroy`.
	var destroyed = false

	# Free used memory used by `native_array`.
	#
	# Also set `destroyed` to true.
	fun destroy
	do
		if destroyed then return

		native_array.free
		destroyed = true
	end
end

# A native C array, as in a pointer to the first element of the array
extern class NativeCArray `{ void * `}

	# Type of contained elements.
	type E: nullable Object

	# Get element at `index`.
	fun [](index: Int): E is abstract

	# Set `val` at `index`.
	fun []=(index: Int, val: E) is abstract

	# Return pointer to the address to the second element of this array
	#
	# This is the standard `+` operator on pointers in C
	fun +(offset: Int): SELF is abstract
end

# Wrapper around an array of `int` in C (`int*`) with length and destroy state
class CIntArray
	super CArray[Int]
	redef type NATIVE: NativeCIntArray

	# Initialize a new CIntArray of `size` elements.
	init(size: Int) is old_style_init do
		native_array = new NativeCIntArray(size)
		super size
	end

	# Create from a `SequenceRead[Int]`
	new from(array: SequenceRead[Int])
	do
		var carray = new CIntArray(array.length)
		for i in array.length.times do
			carray[i] = array[i]
		end
		return carray
	end
end

# An array of `int` in C (`int*`)
extern class NativeCIntArray `{ int* `}
	super NativeCArray
	redef type E: Int

	# Initialize a new NativeCIntArray of `size` elements.
	new(size: Int) `{ return calloc(size, sizeof(int)); `}

	redef fun [](index) `{ return self[index]; `}
	redef fun []=(index, val) `{ self[index] = val; `}

	redef fun +(offset) `{ return self + offset; `}
end

# Wrapper of a C array of type `uint16_t*` with length and destroy state
class CUInt16Array
	super CArray[Int]
	redef type NATIVE: NativeCUInt16Array

	# Initialize a new CIntArray of `size` elements.
	init(size: Int) is old_style_init do
		native_array = new NativeCUInt16Array(size)
		super size
	end

	# Create from a `SequenceRead[Int]`
	new from(array: SequenceRead[Int])
	do
		var carray = new CUInt16Array(array.length)
		for i in array.length.times do
			carray[i] = array[i]
		end
		return carray
	end
end

# An array of `uint16_t` in C
extern class NativeCUInt16Array `{ uint16_t* `}
	super NativeCArray
	redef type E: Int

	# Initialize a new NativeCUInt16Array of `size` elements.
	new(size: Int) `{ return calloc(size, sizeof(uint16_t)); `}

	redef fun [](index) `{ return self[index]; `}
	redef fun []=(index, val) `{ self[index] = val; `}

	redef fun +(offset) `{ return self + offset; `}
end

# Wrapper around an array of `unsigned char` in C (`unsigned char*`) with length and destroy state
class CByteArray
	super CArray[Byte]
	redef type NATIVE: NativeCByteArray

	# Allocate a new array of `size`
	init(size: Int) is old_style_init do
		native_array = new NativeCByteArray(size)
		super size
	end

	# Create from a `SequenceRead[Byte]`
	new from(array: SequenceRead[Byte])
	do
		var carray = new CByteArray(array.length)
		for i in array.length.times do
			carray[i] = array[i]
		end
		return carray
	end

	# Safely move `n` bytes from `dst_offset` to `src_offset`, inside this array
	#
	# Require: all arguments greater than 0 and ranges within `length`
	fun move(dst_offset, src_offset, n: Int)
	do
		assert dst_offset >= 0 and src_offset >= 0 and n >= 0
		assert dst_offset + n <= length
		assert src_offset + n <= length

		native_array.move(dst_offset, src_offset, n)
	end
end

# An array of `unsigned char` in C (`unsigned char*`)
extern class NativeCByteArray `{ unsigned char* `}
	super NativeCArray
	redef type E: Byte

	# Allocate a new array of `size`
	new(size: Int) `{ return calloc(size, sizeof(unsigned char)); `}

	redef fun [](index) `{ return self[index]; `}
	redef fun []=(index, val) `{ self[index] = val; `}

	redef fun +(offset) `{ return self + offset; `}

	# Move `n` bytes from `dst_offset` to `src_offset`
	fun move(dst_offset, src_offset, n: Int) `{
		memmove(self+dst_offset, self+src_offset, n);
	`}
end

# Wrapper around an array of `CString` in C (`char**`) with length and destroy state.
class CCStringArray
	super CArray[CString]

	redef type NATIVE: NativeCStringArray

	# Initialize a new NativeCStringArray of `size` elements.
	init(size: Int) is old_style_init do
		native_array = new NativeCStringArray(size)
		super size
	end

	# Create from an `SequenceRead[CString]`
	new from(array: SequenceRead[CString])
	do
		var carray = new CCStringArray(array.length)
		for i in array.length.times do
			carray[i] = array[i]
		end
		return carray
	end
end

# An array of `CString` in C (`char**`)
extern class NativeCStringArray `{ char** `}
	super NativeCArray

	redef type E: CString

	# Initialize a new NativeCStringArray of `size` elements.
	new(size: Int) `{ return calloc(size, sizeof(char*)); `}

	redef fun [](index) `{ return self[index]; `}
	redef fun []=(index, val) `{ self[index] = val; `}
	redef fun +(offset) `{ return self + offset; `}
end

redef class CString
	super NativeCArray
	redef type E: Char

	redef fun +(offset) `{ return self + offset; `}
end
lib/c/c.nit:17,1--252,3