feisty meow concerns codebase 2.140
base_address.h
Go to the documentation of this file.
1#ifndef BASE_ADDRESS_CLASS
2#define BASE_ADDRESS_CLASS
3
4/*****************************************************************************\
5* *
6* Name : base_address *
7* Author : Chris Koeritz *
8* *
9* Purpose: *
10* *
11* Provides a way to describe an endpoint for communication. *
12* *
13*******************************************************************************
14* Copyright (c) 1995-$now By Author. This program is free software; you can *
15* redistribute it and/or modify it under the terms of the GNU General Public *
16* License as published by the Free Software Foundation; either version 2 of *
17* the License or (at your option) any later version. This is online at: *
18* http://www.fsf.org/copyleft/gpl.html *
19* Please send any updates to: fred@gruntose.com *
20\*****************************************************************************/
21
22#include <basis/astring.h>
23#include <basis/byte_array.h>
24#include <basis/contracts.h>
25
26namespace sockets {
27
28// forward.
29class machine_uid;
30
32: public virtual basis::packable,
33 public virtual basis::nameable
34{
35public:
36 // the packable and nameable responsibilities are forwarded to the derived classes.
37
38 virtual bool same_host(const base_address &to_compare) const = 0;
39 virtual bool same_port(const base_address &to_compare) const = 0;
40 // returns true if the host or port are identical.
41
42 virtual bool shareable(const base_address &to_compare) const = 0;
43 // returns true if the two transports can be shared.
44
45 virtual basis::astring text_form() const = 0;
46 // returns a readable string representing the address.
47
48 // these flip the address into a string and back. this is different from
49 // text_form() because the reversal must be possible.
50 virtual basis::astring tokenize() const = 0;
51 virtual bool detokenize(const basis::astring &info) = 0;
52
53 virtual machine_uid convert() const = 0;
54 // returns the address in the uniquifying format.
55
56 virtual base_address *create_copy() const = 0;
57 // creates a new address that's a copy of this one. note that this
58 // allocates memory that must be deleted by the caller.
59};
60
62
63// these macros assist in tokenizing and detokenizing addresses.
64
65//const char *TOKEN_SEPARATOR();
66//const char *TOKEN_ASSIGN();
67//const char *TOKEN_SEPARATOR() { return ","; }
68//const char *TOKEN_ASSIGN() { return "="; }
69
70// begins operation of a variable_tokenizer for loading. LOADER_EXIT must be called
71// after finishing with the variable_tokenizer.
72#define LOADER_ENTRY \
73 variable_tokenizer addr_parser; \
74 addr_parser.parse(info)
75
76#define LOADER_EXIT
77 // currently no implementation.
78
79// locates a variable in the variable_tokenizer.
80#define FIND(name, value) astring value = addr_parser.find(name)
81
82// locates a variable like FIND, but returns if it couldn't find it.
83#define GRAB(name, value) FIND(name, value); if (!value) return false
84
85// begins operation of a variable_tokenizer for storing. remember to call STORER_EXIT
86// when finished.
87#define STORER_ENTRY \
88 variable_tokenizer addr_parser
89
90#define STORER_EXIT
91 // currently no implementation.
92
93// adds a new entry into the variable_tokenizer.
94#define ADD(name, value) addr_parser.table().add(name, value)
95
96// returns the accumulated tokens in the storing variable_tokenizer.
97#define DUMP_EXIT astring to_return = addr_parser.text_form(); \
98 STORER_EXIT; \
99 return to_return
100
101} //namespace.
102
103#endif
104
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
Root object for any class that knows its own name.
Definition contracts.h:123
A base class for objects that can pack into an array of bytes.
Definition byte_array.h:87
virtual bool detokenize(const basis::astring &info)=0
virtual machine_uid convert() const =0
virtual basis::astring text_form() const =0
virtual bool same_host(const base_address &to_compare) const =0
virtual bool shareable(const base_address &to_compare) const =0
virtual bool same_port(const base_address &to_compare) const =0
virtual base_address * create_copy() const =0
virtual basis::astring tokenize() const =0
Provides access to the operating system's socket methods.