transforms/Xtreams__ObjectAnalyseStream.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 20 Mar 2013 12:03:03 +0000
changeset 120 2ffa5dddf5e8
parent 111 44ac233b2f83
permissions -rw-r--r--
Merged heads 8afa49727a25 b7321b3f5858

"{ Package: 'stx:goodies/xtreams/transforms' }"

"{ NameSpace: Xtreams }"

ReadStream subclass:#ObjectAnalyseStream
	instanceVariableNames:'marshaler nothing log depth objects int_8 int_16 int_32 int_64
		uint_16 uint_32 uint_64 float_ double_'
	classVariableNames:''
	poolDictionaries:''
	category:'Xtreams-Transforms'
!


!ObjectAnalyseStream class methodsFor:'instance creation'!

on: aDestination
	^self on: aDestination marshaler: ObjectMarshaler new
!

on: aDestination marshaler: aMarshaler
	^self new on: aDestination marshaler: aMarshaler
! !

!ObjectAnalyseStream methodsFor:'accessing'!

get
	| details |
	marshaler analyse: self.
	details := log conclusion.
	log := String new writing.
	self complete.
	^details
!

read: anInteger into: aSequenceableCollection at: startIndex
	| count |
	count := 0.
	[anInteger timesRepeat:
		[marshaler analyse: self.
		aSequenceableCollection at: startIndex + count put: log conclusion.
		log := String new writing.
		self complete.
		count := count + 1]]
			on: Incomplete do: [:exception |
				aSequenceableCollection at: startIndex + count put: log conclusion.
				log := String new writing.
				self complete.
				(Incomplete on: aSequenceableCollection count: count at: startIndex) raise].
	^anInteger
! !

!ObjectAnalyseStream methodsFor:'initialize-release'!

contentsSpecies
	^Array
!

on: aSource marshaler: aMarshaler
	super on: aSource.
	marshaler := aMarshaler.
	nothing := Object new.
	objects := OrderedCollection with: Transcript.
	depth := 0.

	log := String new writing.
	int_8 := aSource interpreting: #signedChar.
	(self log: 'header' do: [marshaler configureAnalyse: aSource])
		ifTrue: [
			int_16 := aSource interpreting: #signedShort_be.
			int_32 := aSource interpreting: #signedLong_be.
			int_64 := aSource interpreting: #signedLonglong_be.
			uint_16 := aSource interpreting: #unsignedShort_be.
			uint_32 := aSource interpreting: #unsignedLong_be.
			uint_64 := aSource interpreting: #unsignedLonglong_be]
		ifFalse: [
			int_16 := aSource interpreting: #signedShort_le.
			int_32 := aSource interpreting: #signedLong_le.
			int_64 := aSource interpreting: #signedLonglong_le.
			uint_16 := aSource interpreting: #unsignedShort_le.
			uint_32 := aSource interpreting: #unsignedLong_le.
			uint_64 := aSource interpreting: #unsignedLonglong_le].
	float_ := aSource interpreting: #float.
	double_ := aSource interpreting: #double
! !

!ObjectAnalyseStream methodsFor:'primitives'!

double
	^double_
!

float
	^float_
!

int16
	^int_16
!

int32
	^int_32
!

int64
	^int_64
!

int8
	^int_8
!

uint16
	^uint_16
!

uint32
	^uint_32
!

uint64
	^uint_64
!

uint8
	^source
! !

!ObjectAnalyseStream methodsFor:'private'!

complete
	objects := OrderedCollection with: Transcript
!

log: type do: aBlock
	| superlog sublog position incomplete |
	position := source position.
	superlog := log.
	log := String new writing.

	depth := depth + 1.
	incomplete := false.
	^[aBlock on: Incomplete do: [:ex | incomplete := true. ex pass]] ensure:
		[depth := depth - 1.
		sublog := log conclusion.
		log := superlog.

		incomplete ifFalse:
			[log tab: depth; print: position; write: '+'; print: (source position - position); tab.
			type isCharacters
				ifTrue:	[log write: type]
				ifFalse:	[log write: type value].
			log cr; write: sublog]]
!

nothing
	^nothing
!

objects
	^objects
! !

!ObjectAnalyseStream class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '$Id$'
! !