Class: AutoC::Record

Inherits:
Composite show all
Defined in:
lib/autoc/record.rb

Overview

C struct wrapper with managed fields

Constant Summary

Constants inherited from Composite

Composite::DEFINITIONS, Composite::PRIVATE

Constants included from Entity

Entity::ReferenceSet

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

Instance Attribute Summary collapse

Attributes inherited from Composite

#_master, #visibility

Attributes inherited from Type

#signature

Instance Method Summary collapse

Methods inherited from Composite

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

Methods included from Entity

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

Methods inherited from Type

abstract, #constructible?, #copy, #custom_create, #default_create, #destroy, #inspect, #to_s, #to_type

Constructor Details

#initialize(type, fields, visibility: :public, profile: :blackbox, **kws) ⇒ Record

Returns a new instance of Record.



27
28
29
30
31
# File 'lib/autoc/record.rb', line 27

def initialize(type, fields, visibility: :public, profile: :blackbox, **kws)
  super(type, visibility:, **kws)
  setup_profile(profile)
  setup_fields(fields)
end

Dynamic Method Handling

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

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



17
18
19
# File 'lib/autoc/record.rb', line 17

def fields
  @fields
end

Instance Method Details

#comparable?Boolean

Returns:

  • (Boolean)


22
# File 'lib/autoc/record.rb', line 22

def comparable? = fields.values.all? { |t| t.comparable? }

#copyable?Boolean

Returns:

  • (Boolean)


23
# File 'lib/autoc/record.rb', line 23

def copyable? = fields.values.all? { |t| t.copyable? }

#custom_constructible?Boolean

Returns:

  • (Boolean)


20
# File 'lib/autoc/record.rb', line 20

def custom_constructible? = fields.values.all? { |t| t.copyable? }

#default_constructible?Boolean

Returns:

  • (Boolean)


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

def default_constructible? = fields.values.all? { |t| t.default_constructible? }

#destructible?Boolean

Returns:

  • (Boolean)


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

def destructible? = fields.values.any? { |t| t.destructible? }

#hashable?Boolean

Returns:

  • (Boolean)


24
# File 'lib/autoc/record.rb', line 24

def hashable? = fields.values.all? { |t| t.hashable? }

#orderable?Boolean

Returns:

  • (Boolean)


25
# File 'lib/autoc/record.rb', line 25

def orderable? = false

#render_interface(stream) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/autoc/record.rb', line 33

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

        @brief Value type wrapper of the C struct

        @since 2.0
      */
    }
    if @opaque
      stream << %{
        /**
          #{ingroup}

          @brief Opaque struct holding state of the record

          @since 2.0
        */
      }
    else
      stream << %{
        /**
          #{ingroup}

          @brief Open struct holding state of the record

          The struct's fields are directly acessible.
          However, care must be taken when modifying the struct's contents directly
          as it may break the contract(s) of certain (namely, hash- and tree-based) containers.

          For the safety reasons these fields should be generally treated read-only.

          @since 2.0
        */
      }
    end
  else
    stream << PRIVATE
  end
  stream << 'typedef struct {'
    fields.each { |name, type| stream << field_declaration(type, name) }
  stream << "} #{signature};"
end

#type_tagObject



79
# File 'lib/autoc/record.rb', line 79

def type_tag = "#{signature}<#{fields.values.join(',')}>"