1 #ifndef BASE_ADDRESS_CLASS
2 #define BASE_ADDRESS_CLASS
4 /*****************************************************************************\
6 * Name : base_address *
7 * Author : Chris Koeritz *
11 * Provides a way to describe an endpoint for communication. *
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 \*****************************************************************************/
22 #include <basis/astring.h>
23 #include <basis/byte_array.h>
24 #include <basis/contracts.h>
32 : public virtual basis::packable,
33 public virtual basis::nameable
36 // the packable and nameable responsibilities are forwarded to the derived classes.
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.
42 virtual bool shareable(const base_address &to_compare) const = 0;
43 // returns true if the two transports can be shared.
45 virtual basis::astring text_form() const = 0;
46 // returns a readable string representing the address.
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;
53 virtual machine_uid convert() const = 0;
54 // returns the address in the uniquifying format.
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.
63 // these macros assist in tokenizing and detokenizing addresses.
65 //const char *TOKEN_SEPARATOR();
66 //const char *TOKEN_ASSIGN();
67 //const char *TOKEN_SEPARATOR() { return ","; }
68 //const char *TOKEN_ASSIGN() { return "="; }
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)
77 // currently no implementation.
79 // locates a variable in the variable_tokenizer.
80 #define FIND(name, value) astring value = addr_parser.find(name)
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
85 // begins operation of a variable_tokenizer for storing. remember to call STORER_EXIT
87 #define STORER_ENTRY \
88 variable_tokenizer addr_parser
91 // currently no implementation.
93 // adds a new entry into the variable_tokenizer.
94 #define ADD(name, value) addr_parser.table().add(name, value)
96 // returns the accumulated tokens in the storing variable_tokenizer.
97 #define DUMP_EXIT astring to_return = addr_parser.text_form(); \