1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident	"%Z%%M%	%I%	%E% SMI"
4 
5 #ifndef ShortReferenceMap_INCLUDED
6 #define ShortReferenceMap_INCLUDED 1
7 #ifdef __GNUG__
8 #pragma interface
9 #endif
10 
11 #include "Vector.h"
12 #include "Vector.h"
13 #include "StringC.h"
14 #include "Named.h"
15 #include "Boolean.h"
16 #include "Entity.h"
17 #include "Ptr.h"
18 
19 #ifdef SP_NAMESPACE
20 namespace SP_NAMESPACE {
21 #endif
22 
23 class SP_API ShortReferenceMap : public Named {
24 public:
25   ShortReferenceMap();
26   ShortReferenceMap(const StringC &);
27   Boolean defined() const;
28   void setNameMap(Vector<StringC> &map);
29   void setEntityMap(Vector<ConstPtr<Entity> > &map);
30   Boolean lookup(int i, const StringC *&) const;
31   const StringC *entityName(size_t i) const;
32   const ConstPtr<Entity> &entity(size_t i) const;
33   Boolean used() const;
34   void setUsed();
35   const Location &defLocation() const;
36   void setDefLocation(const Location &);
37 private:
38   ShortReferenceMap(const ShortReferenceMap &);	// undefined
39   void operator=(const ShortReferenceMap &);	// undefined
40   Vector<StringC> nameMap_;
41   Vector<ConstPtr<Entity> > entityMap_;
42   ConstPtr<Entity> nullEntity_;
43   Boolean used_;
44   Location defLocation_;
45 };
46 
47 inline
defined()48 Boolean ShortReferenceMap::defined() const
49 {
50   return nameMap_.size() > 0;
51 }
52 
53 inline
entityName(size_t i)54 const StringC *ShortReferenceMap::entityName(size_t i) const
55 {
56   if (i < nameMap_.size() && nameMap_[i].size() != 0)
57     return &nameMap_[i];
58   else
59     return 0;
60 }
61 
62 inline
entity(size_t i)63 const ConstPtr<Entity> &ShortReferenceMap::entity(size_t i) const
64 {
65   if (i < entityMap_.size())
66     return entityMap_[i];
67   else
68     return nullEntity_;
69 }
70 
71 inline
setEntityMap(Vector<ConstPtr<Entity>> & map)72 void ShortReferenceMap::setEntityMap(Vector<ConstPtr<Entity> > &map)
73 {
74   map.swap(entityMap_);
75 }
76 
77 inline
used()78 Boolean ShortReferenceMap::used() const
79 {
80   return used_;
81 }
82 
83 inline
setUsed()84 void ShortReferenceMap::setUsed()
85 {
86   used_ = 1;
87 }
88 
89 inline
setDefLocation(const Location & loc)90 void ShortReferenceMap::setDefLocation(const Location &loc)
91 {
92   defLocation_ = loc;
93 }
94 
95 inline
defLocation()96 const Location &ShortReferenceMap::defLocation() const
97 {
98   return defLocation_;
99 }
100 
101 #ifdef SP_NAMESPACE
102 }
103 #endif
104 
105 #endif /* not ShortReferenceMap_INCLUDED */
106