Delight

Aug 2009, Thomas Leonard

The Delight Standard Library

This is very basic at the moment, and likely to change. The modules are:

dlt.core

This is automatically imported into every file:

# Asserts that o is not null and then returns it.
# Use this if you're sure o can't be null, but the
# static type checker doesn't realise.
T notnull(T)(T? o)

# Call o.toString(). If o is null, return "(null)".
string str(Object? o)

# General exception to throw if your function is called
# with invalid arguments.
class IllegalArgumentException extends Exception:
	this(string msg)

_externals.XXX

Do not import these modules. They are used to supply arguments to Main. These are objects that correspond to the world outside the program. Available objects are:

# Used to configure the logging system (e.g. levels, formats)
dlt.log.LogManager logManager

# Standard streams
dlt.io.InputStream stdin
dlt.io.Printer stdout
dlt.io.Printer stderr

# Access to the filesystem
dlt.io.FileSystem fs

# The current time and time-zone
dlt.time.Clock systemClock

# Access to the network
dlt.net.Network network

dlt.io

public import std.stream: OutputStream, InputStream

public alias Layout!(char).convert format

# Wraps an output stream with text formatting
class Printer:
	in OutputStream sink

	# Write a formatted string
	void format(string fmt, ...)

	# Write a formatted string and add a newline
	void formatln(string fmt, ...)

	# Non-varargs version
	void vformat(TypeInfo[] arguments, ArgList args, string fmt)

	# Write all characters in buffer to sink
	# Returns the length of the buffer
	uint write(const(char)[] buffer)

	# Flushes sink
	void flush()

dlt.fs

interface FileSystem:
	FilePath path(string pathname)

	FilePath cwd()
	void cwd(FilePath)

# Mostly based on GIO
interface FilePath:
	string loadContents()
	OutputStream create(CreateFlags flags = CreateFlags.None)
	InputStream read()
	void move(FilePath destination, CopyFlags flags)
	void copy(FilePath destination, CopyFlags flags)
	void makeDirectory()
	void remove()
	FilePathEnumerator children(string attributes,
				    QueryInfoFlags flags)

dlt.log

Use the logManager external object to configure the logging system.

enum Level: Trace, Info, Warn, Error

interface Appender:
	void log(int level, string src, string msg, TypeInfo[] arguments, va_list args)

class StreamAppender implements Appender:
	in Printer printer
	in Clock clock

class LogManager:
	Level level = Level.Warn
	Appender[] appenders

dlt.math

public import std.math: *

dlt.net

public import std.socket:
	AddressFamily, SocketType, ProtocolType
	SocketShutdown, SocketFlags, SocketOption, SocketOptionLevel

class Address:
	in string address
	AddressFamily addressFamily

	this()
	this(AddressFamily af)

class InternetHost:
	string name
	string[] aliases
	Address[] addrList

interface Socket:
	Address localAddress()
	int getOption(SocketOptionLevel level, SocketOption option, void[] result)
	void setOption(SocketOptionLevel level, SocketOption option, void[] value)

	bool isAlive()
	void shutdown(SocketShutdown how)
	void close()

interface ClientSocket extends Socket:
	Address remoteAddress()
	int send(const(void)[] buf, SocketFlags flags = SocketFlags.NONE)
	int receive(void[] buf, SocketFlags flags = SocketFlags.NONE)

interface ServerSocket extends Socket:
	ClientSocket accept()

interface ServerSocketFactory:
	ServerSocket create(const Address address,
			     int backlog = 32,
			     bool reuse = false)

interface ClientSocketFactory:
	ClientSocket create(const Address address,
			     SocketType type,
			     ProtocolType protocol)

interface NameResolver:
	const(InternetHost) getHostByName(string name)
	const(InternetHost) getHostByAddr(string addr)

interface Network:
	ServerSocketFactory server()
	ClientSocketFactory client()
	NameResolver resolver()
	string hostname()

dlt.time

Mostly uses the tango.time types.

interface Clock:
	Date now()
	TimeSpan zone()
	DateTime toLocalTime(Time utc)