# Address

<a id="address-13"></a>

# Address

```cpp
#include <icy/symple/address.h>

struct Address
```

[Defined in src/symple/include/icy/symple/address.h:28](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L28)

The [Address](#address-13) structure is an endpoint identifier for a peer on the network. The format is like so: user|id

## Friends

| Name | Description |
|------|-------------|
| [`operator<<`](#operator-243) `inline` |  |

---

<a id="operator-243"></a>

### operator<<

`inline`

```cpp
friend inline std::ostream & operator<<(std::ostream & os, const Address & addr)
```

[Defined in src/symple/include/icy/symple/address.h:71](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L71)

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::string` | [`user`](#user)  |  |
| `std::string` | [`id`](#id-10)  |  |

---

<a id="user"></a>

### user

```cpp
std::string user
```

[Defined in src/symple/include/icy/symple/address.h:77](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L77)

---

<a id="id-10"></a>

### id

```cpp
std::string id
```

[Defined in src/symple/include/icy/symple/address.h:79](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L79)

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Address`](#address-14)  | Constructs an empty (invalid) address. |
|  | [`Address`](#address-15)  | Parses an address string of the form `user\|id`. |
|  | [`Address`](#address-16)  | Constructs an address from explicit user and session ID components. |
|  | [`~Address`](#address-17) `virtual` |  |
| `bool` | [`parse`](#parse-6)  | Parses an address string of the form `user\|id`. Populates the `user` and `id` fields. |
| `bool` | [`valid`](#valid-10) `const` | Returns true if at least one of `user` or `id` is non-empty. |
| `void` | [`print`](#print-17) `const` | Writes the address in `user\|id` format to the given stream. |
| `std::string` | [`toString`](#tostring-12) `const` | Returns the address as a string in `user\|id` format. |
| `bool` | [`operator==`](#operator-244) `const` | Compares two addresses for equality (both user and id must match). |
| `bool` | [`operator==`](#operator-245) `const` | Compares this address against a string in `user\|id` format without allocating. |

---

<a id="address-14"></a>

### Address

```cpp
Address()
```

[Defined in src/symple/include/icy/symple/address.h:32](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L32)

Constructs an empty (invalid) address.

---

<a id="address-15"></a>

### Address

```cpp
Address(std::string_view addr)
```

[Defined in src/symple/include/icy/symple/address.h:36](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L36)

Parses an address string of the form `user|id`.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `addr` | `std::string_view` | [Address](#address-13) string to parse. |

---

<a id="address-16"></a>

### Address

```cpp
Address(const std::string & user, const std::string & id)
```

[Defined in src/symple/include/icy/symple/address.h:41](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L41)

Constructs an address from explicit user and session ID components.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `user` | `const std::string &` | User identifier. |
| `id` | `const std::string &` | Session ID. |

---

<a id="address-17"></a>

### ~Address

`virtual`

```cpp
virtual ~Address()
```

[Defined in src/symple/include/icy/symple/address.h:44](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L44)

---

<a id="parse-6"></a>

### parse

```cpp
bool parse(std::string_view addr)
```

[Defined in src/symple/include/icy/symple/address.h:50](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L50)

Parses an address string of the form `user|id`. Populates the `user` and `id` fields. 
#### Returns
True if the result is a valid address.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `addr` | `std::string_view` | [Address](#address-13) string to parse. |

---

<a id="valid-10"></a>

### valid

`const`

```cpp
bool valid() const
```

[Defined in src/symple/include/icy/symple/address.h:53](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L53)

Returns true if at least one of `user` or `id` is non-empty.

---

<a id="print-17"></a>

### print

`const`

```cpp
void print(std::ostream & os) const
```

[Defined in src/symple/include/icy/symple/address.h:57](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L57)

Writes the address in `user|id` format to the given stream.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `os` | `std::ostream &` | Output stream. |

---

<a id="tostring-12"></a>

### toString

`const`

```cpp
std::string toString() const
```

[Defined in src/symple/include/icy/symple/address.h:61](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L61)

Returns the address as a string in `user|id` format. 
#### Returns
Serialised address string.

---

<a id="operator-244"></a>

### operator==

`const`

```cpp
bool operator==(const Address & r) const
```

[Defined in src/symple/include/icy/symple/address.h:65](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L65)

Compares two addresses for equality (both user and id must match).

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `r` | const [`Address`](#address-13) & | [Address](#address-13) to compare against. |

---

<a id="operator-245"></a>

### operator==

`const`

```cpp
bool operator==(const std::string & r) const
```

[Defined in src/symple/include/icy/symple/address.h:69](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/address.h#L69)

Compares this address against a string in `user|id` format without allocating.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `r` | `const std::string &` | String to compare against. |
