<?php

// imports
require_once 'AlarmManagement/DataTypes/HostAddrSel.php';

/**
 * DataType HostAddr
 *
 * @author     WagnerTech UG <mail@wagnertech.de>
 * @package    SysAl.AlarmManagement.DataType
 */

class HostAddr {
	
	/**
	 * selector:
	 * @var        HostAddrSel
	 */
	private $selector;
	
	/**
	 * value
	 * @var        string
	 */
	private $value;

	/**
	 * constructor: checks validity
	 * 
	 * @param strOrSel  both constructions possible: with complete string or by selector/value pair 
	 * @param value     only if selector/value are specified separately
	 */
	function __construct($strOrSel, $value = null){
		$this->init($strOrSel, $value);
	}
	function init($strOrSel, $value = null){
		if ($strOrSel === null) {
			// default value required for gui handling
			$this->selector = new HostAddrSel(4);
			$this->value = "DEFAULT";
			return $this;
		}
		if ($value == null) {
			$aux_arr = explode ('/', $strOrSel);
			if (count($aux_arr) != 2) 
				throw new Exception("Invalid HostAddr string: $strOrSel");
		} else {
			$aux_arr[0] = $strOrSel;
			$aux_arr[1] = $value;
		}
		$this->selector = new HostAddrSel($aux_arr[0]);
		$this->value = $aux_arr[1];
	}
	
	function getSelector(){
		return $this->selector;
	}
	
	function getValue(){
		return $this->value;
	}

	function __toString(){
		return $this->selector . "/" . $this->value;
	}
	
	public function equals(HostAddr $h) {
		return ($this->selector->equals($h->selector) && ($this->value == $h->value));
	}
/*	
	// GUI Representation
	public function getGuiRepr() {
		return $this->__toString();
	}
	public function setGuiRepr($str) {
		return $this->init($str);
	}
*/
}