Class: AutoC::Composite Abstract

Inherits:
Type
  • Object
show all
Includes:
Entity, STD
Defined in:
lib/autoc/composite.rb

Overview

This class is abstract.

Direct Known Subclasses

Box, Collection, Range, Record, GenericValue

Defined Under Namespace

Modules: Decorator Classes: Method

Constant Summary collapse

PRIVATE =
"\n/** @private */\n"
DEFINITIONS =
Code.new(
  interface: %{
    #ifndef AUTOC_INLINE
      #if defined(__cplusplus)
        #define AUTOC_INLINE inline
      #elif defined(__clang__)
        #define AUTOC_INLINE static __inline __attribute__((unused))
      #elif __STDC_VERSION__ >= 199901L
        #define AUTOC_INLINE static inline
      #else
        #define AUTOC_INLINE static __inline
      #endif
    #endif
    #ifndef AUTOC_EXTERN
      #ifdef __cplusplus
        #define AUTOC_EXTERN extern "C"
      #else
        #define AUTOC_EXTERN extern
      #endif
    #endif
  }
)

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 Type

#signature

Class Method Summary collapse

Instance Method Summary collapse

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_constructible?, #default_create, #destroy, #destructible?, #hashable?, #orderable?, #to_s, #to_type

Constructor Details

#initialize(signature, visibility: :public, decorator: nil, allocator: nil, hasher: nil, _master: nil) ⇒ Composite

Returns a new instance of Composite.



31
32
33
34
35
36
37
38
39
40
# File 'lib/autoc/composite.rb', line 31

def initialize(signature, visibility: :public, decorator: nil, allocator: nil, hasher: nil, _master: nil)
  super(signature)
  @methods = {}
  @hasher = hasher
  @decorator = decorator
  @allocator = allocator
  @visibility = visibility
  dependencies << DEFINITIONS << ASSERT_H << self.memory << self.hasher
  @_master = _master
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object (private)



140
141
142
143
144
145
146
147
148
149
# File 'lib/autoc/composite.rb', line 140

def method_missing(meth, *args)
  if (method = @methods[meth]).nil?
    # On anything thats not a defined method return a type-decorated identifier
    # This allows to generate arbitrary type-qualified identifiers with #{type.foo}
    raise "unexpected arguments" unless args.empty?
    identifier(meth)
  else
    method
  end
end

Instance Attribute Details

#_masterObject (readonly)

Internal reference to the containing type if this type is used as implementing type



29
30
31
# File 'lib/autoc/composite.rb', line 29

def _master
  @_master
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



27
28
29
# File 'lib/autoc/composite.rb', line 27

def visibility
  @visibility
end

Class Method Details

.allocatorObject



92
# File 'lib/autoc/composite.rb', line 92

def self.allocator = @allocator

.allocator=(allocator) ⇒ Object



90
# File 'lib/autoc/composite.rb', line 90

def self.allocator=(allocator) @allocator = allocator end

.decoratorObject



88
# File 'lib/autoc/composite.rb', line 88

def self.decorator = @decorator

.decorator=(decorator) ⇒ Object



86
# File 'lib/autoc/composite.rb', line 86

def self.decorator=(decorator) @decorator = decorator end

.hasherObject



98
# File 'lib/autoc/composite.rb', line 98

def self.hasher = @hasher

.hasher=(hasher) ⇒ Object



96
# File 'lib/autoc/composite.rb', line 96

def self.hasher=(hasher) @hasher = hasher end

.new(*args, **kws, &block) ⇒ Object



42
43
44
45
46
# File 'lib/autoc/composite.rb', line 42

def self.new(*args, **kws, &block)
  obj = super
  obj.send(:configure)
  obj
end

Instance Method Details

#const_lvalueObject



56
# File 'lib/autoc/composite.rb', line 56

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

#const_rvalueObject



54
# File 'lib/autoc/composite.rb', line 54

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

#defgroupObject



78
# File 'lib/autoc/composite.rb', line 78

def defgroup = (public? ? :@public : :@internal).to_s + " @defgroup #{signature} #{type_tag}"

#hasherObject



84
# File 'lib/autoc/composite.rb', line 84

def hasher = (@hasher.nil? ? Composite.hasher : @hasher)

#identifier(id, **kws) ⇒ Object

Decorate identifier with type-specific prefix



66
# File 'lib/autoc/composite.rb', line 66

def identifier(id, **kws) = (@decorator.nil? ? Composite.decorator : @decorator).(self, id, **kws)

#ingroupObject



80
# File 'lib/autoc/composite.rb', line 80

def ingroup = (public? ? :@public : :@internal).to_s + " @ingroup #{signature}"

#inspectObject



63
# File 'lib/autoc/composite.rb', line 63

def inspect = "#{signature} <#{self.class}>"

#internal?Boolean

Returns:

  • (Boolean)


72
# File 'lib/autoc/composite.rb', line 72

def internal? = @visibility == :internal

#lvalueObject



52
# File 'lib/autoc/composite.rb', line 52

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

#memoryObject



82
# File 'lib/autoc/composite.rb', line 82

def memory = (@allocator.nil? ? Composite.allocator : @allocator)

#prefixObject

Prefix used to generate type-qualified identifiers By default it returns the C side type signature but can be overridden to handle the cases where the signature is not itself a valid C identifier (char*, for example)



61
# File 'lib/autoc/composite.rb', line 61

def prefix = signature

#private?Boolean

Returns:

  • (Boolean)


70
# File 'lib/autoc/composite.rb', line 70

def private? = @visibility == :private

#public?Boolean

Returns:

  • (Boolean)


68
# File 'lib/autoc/composite.rb', line 68

def public? = @visibility == :public

#respond_to_missing?(meth, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


74
# File 'lib/autoc/composite.rb', line 74

def respond_to_missing?(meth, include_private = false) = @methods.has_key?(meth) ? true : super

#rvalueObject



50
# File 'lib/autoc/composite.rb', line 50

def rvalue = @rv ||= Value.new(self, reference: true)

#to_valueObject



48
# File 'lib/autoc/composite.rb', line 48

def to_value = Value.new(self)

#type_tagObject



76
# File 'lib/autoc/composite.rb', line 76

def type_tag = signature