casacore
Loading...
Searching...
No Matches
ObjectID.h
Go to the documentation of this file.
1// # ObjectID.h: A unique identifier for distributed and other objects
2// # Copyright (C) 1996,1998,1999,2000,2001,2003
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_OBJECTID_H
27#define CASA_OBJECTID_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/BasicSL/String.h>
32#include <casacore/casa/iosfwd.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward declarations
37template <class T>
38class Block;
39
40// <summary>
41// ObjectID: A unique identifier for distributed and other objects.
42// </summary>
43
44// <use visibility=export>
45
46// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tObjectID.cc" demos="">
47
48// <prerequisite>
49// <li> none
50// </prerequisite>
51//
52// <etymology>
53// The ObjectID class name reflects its role as the single identifier for
54// distributed and other user-level objects.
55// </etymology>
56//
57// <synopsis>
58// The ObjectID class is used to give a unique identifier to ``high-level''
59// objects in the system. Internally the ObjectID consists of a sequence number
60// (unique within the creating process), a process id, a creation time, and a
61// host id. Pragmatically the ObjectID should be unique with no dangers of
62// collisions.
63//
64// A special ``Null'' ObjectID is available.
65// </synopsis>
66//
67// <motivation>
68// The fundamental purpose for an ObjectID is to provide a unique identifier
69// for persistent objects, or for objects that might be accessed outside the
70// creating processes address space.
71// </motivation>
72//
73// <todo asof="1997/09/23">
74// <li> Nothing (hostid -> hostname on this date).
75// </todo>
76
77class ObjectID {
78 public:
79 // If <src>makeNull</src> is True, make the null ObjectID, otherwise create
80 // a unique ObjectID.
81 ObjectID(Bool makeNull = False);
82 // Create explicitly from the provided constituents.
83 ObjectID(Int sequence, Int pid, Int time, const String &hostname);
84
85 // Copy <src>other</src>. Note that if the ObjectID is embedded inside an
86 // object, the enclosing object probably does not want to copy the ObjectID
87 // since generally speaking the identity of the enclosing object should be
88 // immutable.
89 // <group>
90 ObjectID(const ObjectID &other);
91 ObjectID &operator=(const ObjectID &other);
92 // </group>
93
94 // Is this ObjectID set?
95 Bool isNull() const;
96
97 // Compare two ObjectID's for (in)equality.
98 // <group>
99 Bool operator==(const ObjectID &other) const;
100 Bool operator!=(const ObjectID &other) const;
101 // </group>
102
103 // It is useful to interconvert between strings and ObjecID's, e.g. when
104 // saving to FITS or writing to a table. The form of the string is:
105 // <srcblock>
106 // sequence=123 host=hostname pid=pid time=time
107 // </srcblock>
108 // with an optional comma between the fields.
109 // However, in general user code should not depend on the exact form of
110 // the string.
111 // <group>
112 // If this fails, an error message is set and the ObjectID is the null
113 // ObjectID.
114 Bool fromString(String &error, const String &in);
115 // Note that <src>out</src> is zero'd before it is set.
116 void toString(String &out) const;
117 // </group>
118
119 // Ordinarily the user does not need to get at the exact state of the,
120 // ObjectID, however it is available for those times when it is necessary.
121 // <group>
122 Int sequence() const;
123 Int pid() const;
124 Int creationTime() const;
125 const String &hostName() const;
126 // </group>
127
128 // Extract objectID strings (as set by glish script substitute.g) from
129 // a command, convert them to ObjectID objects, store those in the
130 // Block, and replace the strings by their Block indices as
131 // <src>$OBJ#n#O</src> where n is the index.
132 static String extractIDs(Block<ObjectID> &objectIDs, const String &command);
133
134 private:
139
140 // Make a unique sequence number, returns 0 on first call, 1 on next, ...
142};
143
145
146ostream &operator<<(ostream &os, const ObjectID &id);
147
148// # Inlines
149
150inline Int ObjectID::sequence() const { return sequence_number_p; }
151
152inline Int ObjectID::pid() const { return process_id_p; }
153
155
156inline const String &ObjectID::hostName() const { return hostname_p; }
157
158} // namespace casacore
159
160#endif
ObjectID & operator=(const ObjectID &other)
const String & hostName() const
Definition ObjectID.h:156
static String extractIDs(Block< ObjectID > &objectIDs, const String &command)
Extract objectID strings (as set by glish script substitute.g) from a command, convert them to Object...
static Int sequence_number()
Make a unique sequence number, returns 0 on first call, 1 on next,...
Bool isNull() const
Is this ObjectID set?
Int pid() const
Definition ObjectID.h:152
ObjectID(Bool makeNull=False)
If makeNull is True, make the null ObjectID, otherwise create a unique ObjectID.
Bool fromString(String &error, const String &in)
It is useful to interconvert between strings and ObjecID's, e.g.
ObjectID(const ObjectID &other)
Copy other.
ObjectID(Int sequence, Int pid, Int time, const String &hostname)
Create explicitly from the provided constituents.
void toString(String &out) const
Note that out is zero'd before it is set.
Int sequence() const
Ordinarily the user does not need to get at the exact state of the, ObjectID, however it is available...
Definition ObjectID.h:150
Bool operator!=(const ObjectID &other) const
Int creationTime() const
Definition ObjectID.h:154
Bool operator==(const ObjectID &other) const
Compare two ObjectID's for (in)equality.
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
TableExprNode time(const TableExprNode &node)
Definition ExprNode.h:1368
uInt hashFunc(const ObjectID &)
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40