Previous: , Up: Classes   [Index]


Vector

Vector Class

Objects of Vector class refer to blocks of memory of arbitrary length. The memory area that the Vector object points to may contain any data, including NULL bytes.

Whenever a program or method assigns a Vector object a new area of memory, the program or method also sets the Vector object’s length instance variable; for example, the method readVec (class ReadFileStream) records the memory area’s size in the length instance variable after it has read a chunk of data from a disk file. See ReadFileStream.

Here’s an example program that writes a copy of a JPEG image file.


int main () {
  ReadFileStream new readF;
  WriteFileStream new writeF;
  FileStream new f;
  Vector new vec;
  LongInteger new size;

  readF openOn "original.jpeg";
  readF statStream;
  size = readF streamSize;
  
  vec = readF readVec size;

  writeF openOn "copy.jpeg";
  writeF writeVec vec;

  writeF closeStream ;
  readF closeStream;
}

Instance Variables

length

An Integer that contains the size in bytes of the memory area that the Vector object points to.

Instance Methods

+ (Vector v)

Return a Vector object that is the concatenation of the receiver and the argument.

+= (Vector v)

Concatenate the receiver with the vector given as the argument.

asString (void)

Returns the value of the receiver as a String object terminated with a NUL byte to the value of the receiver’s length instance variable. Does not check for NULs or non-printing characters in the value, so the returned String may still be truncated to less than the receiver’s length.

basicNew (char *name, char *value, int value_length
basicNew (char *name, char *classname, char *superclassname, char *value, int value_length)

Create a new Vector object with the name, contents, length, and, optionally, class name and superclass name given as the arguments.

For the five-argument form of basicNew, the class should be Vector and the superclassname should be Symbol, unless the program has subclassed Vector.

In the three-argument form, the receiver must be a member of Vector class or its subclasses, in which case the method takes the class and superclass from the receiver, as in this example.


myBuf = Vector basicNew "memorybuf", memory_buf_ptr, memory_buf_length;

The value argument may be any memory address that points to data of arbitrary size, and may contain any data, including NULL bytes.

The value_length argument supplies the length of the memory segment in bytes, which the returned Vector object stores in its length instance variable.

Most of the internal work of setting the values and attributes of the returned object, and registering the memory area, is performed by __ctalkSetObjectValueAddr, which each of these methods call. See ctalkSetObjectValueAddr.

It’s also necessary that these methods take care of other initialization tasks which are necessary for all classes of objects. They’re described in general in the description of basicNew (Object class). See ObjectbasicNew.

contains (String pattern)
contains (String pattern, Integer start_offset)

With one argument, returns an Integer with the byte offset of the first occurence of pattern in the receiver, starting from the beginning of the receiver’s value, or -1 if the pattern is not found.

If a second argument is given, it contains the Integer offset into the buffer where the method begins its search. That allows programs to find multiple matches of the same pattern in the receiver’s value.


Previous: , Up: Classes   [Index]