Class: AutoC::CString

Inherits:
Association show all
Includes:
STD, Sequential
Defined in:
lib/autoc/cstring.rb

Overview

Value type string wrapper of the plain C string

Constant Summary collapse

Range =

Range

ContiguousRange

Constants included from STD

STD::ASSERT_H, STD::BOOL, STD::CHAR, STD::COMPLEX, STD::COMPLEX_H, STD::DOUBLE, STD::DOUBLE_COMPLEX, STD::DOUBLE_T, STD::FLOAT, STD::FLOAT_COMPLEX, STD::FLOAT_T, STD::INT, STD::INTMAX_T, STD::INTPTR_T, STD::INTTYPES_H, STD::LONG, STD::LONG_DOUBLE, STD::LONG_DOUBLE_COMPLEX, STD::LONG_LONG, STD::MALLOC_H, STD::MATH_H, STD::PTRDIFF_T, STD::SHORT, STD::SIGNED_CHAR, STD::SIZE_T, STD::STDBOOL_H, STD::STDDEF_H, STD::STDLIB_H, STD::STRING_H, STD::UINTMAX_T, STD::UINTPTR_T, STD::UNSIGNED, STD::UNSIGNED_CHAR, STD::UNSIGNED_LONG, STD::UNSIGNED_LONG_LONG, STD::UNSIGNED_SHORT, STD::WCHAR_T

Constants inherited from Composite

AutoC::Composite::DEFINITIONS, AutoC::Composite::PRIVATE

Constants included from Entity

Entity::ReferenceSet

Instance Attribute Summary

Attributes inherited from Association

#index

Attributes inherited from Collection

#element

Attributes inherited from Composite

#_master, #visibility

Attributes inherited from Type

#signature

Instance Method Summary collapse

Methods inherited from Association

#comparable?, #copyable?, #destructible?, #hashable?, #orderable?

Methods inherited from Collection

#comparable?, #copyable?, #destructible?, #hashable?, new, #orderable?

Methods inherited from Composite

allocator, allocator=, decorator, decorator=, #defgroup, #hasher, hasher, hasher=, #identifier, #ingroup, #inspect, #internal?, #memory, new, #prefix, #private?, #public?, #respond_to_missing?, #to_value

Methods included from Entity

#<=>, #complexity, #dependencies, #forward_declarations, #implementation, #interface, #position, #references, #total_dependencies, #total_references

Methods inherited from Type

abstract, #comparable?, #constructible?, #copy, #copyable?, #custom_constructible?, #custom_create, #default_create, #destroy, #destructible?, #hashable?, #inspect, #orderable?, #to_s, #to_type

Constructor Details

#initialize(type = :CString, char = :char, parallel: nil, **kws) ⇒ CString

Returns a new instance of CString.



23
24
25
26
27
# File 'lib/autoc/cstring.rb', line 23

def initialize(type = :CString, char = :char, parallel: nil, **kws)
  super(type, char, :size_t, **kws)
  dependencies << STRING_H
  @parallel = parallel
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class AutoC::Composite

Instance Method Details

#const_lvalueObject



35
# File 'lib/autoc/cstring.rb', line 35

def const_lvalue = @clv ||= Value.new(self, reference: true, constant: true)

#const_rvalueObject



33
# File 'lib/autoc/cstring.rb', line 33

def const_rvalue = @crv ||= Value.new(self, constant: true)

#default_constructible?Boolean

Returns:

  • (Boolean)


19
# File 'lib/autoc/cstring.rb', line 19

def default_constructible? = false

#lvalueObject



31
# File 'lib/autoc/cstring.rb', line 31

def lvalue = @lv ||= Value.new(self, reference: true)

#rangeObject



21
# File 'lib/autoc/cstring.rb', line 21

def range = @range ||= Range.new(self, visibility: visibility, parallel: @parallel)

#render_forward_declarations(stream) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/autoc/cstring.rb', line 60

def render_forward_declarations(stream)
  stream << %{
    #include <stdio.h>
    #include <malloc.h>
    #include <stdarg.h>
    /* overridable internal buffer size (in chars, not bytes) for *sprintf() operations */
    #ifndef AUTOC_BUFFER_SIZE
      #define AUTOC_BUFFER_SIZE 1024
    #endif
  }
  super
end

#render_interface(stream) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/autoc/cstring.rb', line 37

def render_interface(stream)
  if public?
    stream << %{
      /**
        #{defgroup}

        @brief Value type wrapper of the plain C string

        This type represents a (paper thin) wrapper around the plain C string (char *) with proper value semantics.

        @since 2.0
      */
    }
  else
    stream << PRIVATE
  end
  stream << %{
    typedef #{element.lvalue} #{signature};
  }
end

#rvalueObject



29
# File 'lib/autoc/cstring.rb', line 29

def rvalue = @rv ||= Value.new(self)

#storage(target) ⇒ Object

Return C pointer to contiguous storage



58
# File 'lib/autoc/cstring.rb', line 58

def storage(target) = target # Return C pointer to contiguous storage

#type_tagObject



73
# File 'lib/autoc/cstring.rb', line 73

def type_tag = "#{signature}<#{element}>"