3065 some functions in the tcp module can be static
[unleashed.git] / usr / src / cmd / man / src / util / nsgmls.src / lib / LiteralStorage.cxx
blob392711023835ac5e1365c66d65bd517451ba7fc6
1 // Copyright (c) 1996 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
9 #include "splib.h"
10 #include "LiteralStorage.h"
11 #include "CodingSystem.h"
12 #include <string.h>
14 #ifdef DECLARE_MEMMOVE
15 extern "C" {
16 void *memmove(void *, const void *, size_t);
18 #endif
20 #ifdef SP_NAMESPACE
21 namespace SP_NAMESPACE {
22 #endif
24 class LiteralStorageObject : public StorageObject {
25 public:
26 LiteralStorageObject(const StringC &);
27 Boolean read(char *buf, size_t bufSize, Messenger &, size_t &nread);
28 Boolean rewind(Messenger &);
29 private:
30 LiteralStorageObject(const LiteralStorageObject &); // undefined
31 void operator=(const LiteralStorageObject &); // undefined
33 StringC str_;
34 size_t nBytesRead_;
37 class MemoryInputCodingSystem : public InputCodingSystem {
38 public:
39 Decoder *makeDecoder() const;
42 class MemoryDecoder : public Decoder {
43 public:
44 MemoryDecoder();
45 size_t decode(Char *, const char *, size_t, const char **);
48 LiteralStorageManager::LiteralStorageManager(const char *type)
49 : type_(type)
53 StorageObject *LiteralStorageManager::makeStorageObject(const StringC &id,
54 const StringC &,
55 Boolean,
56 Boolean,
57 Messenger &,
58 StringC &foundId)
60 foundId = id;
61 return new LiteralStorageObject(id);
64 const InputCodingSystem *LiteralStorageManager::requiredCodingSystem() const
66 static MemoryInputCodingSystem cs;
67 return &cs;
70 Boolean LiteralStorageManager::requiresCr() const
72 return 1;
75 const char *LiteralStorageManager::type() const
77 return type_;
80 Boolean LiteralStorageManager::inheritable() const
82 return 0;
85 LiteralStorageObject::LiteralStorageObject(const StringC &str)
86 : str_(str), nBytesRead_(0)
90 Boolean LiteralStorageObject::rewind(Messenger &)
92 nBytesRead_ = 0;
93 return 1;
96 Boolean LiteralStorageObject::read(char *buf, size_t bufSize,
97 Messenger &, size_t &nread)
99 if (nBytesRead_ >= str_.size()*sizeof(Char))
100 return 0;
101 nread = str_.size()*sizeof(Char) - nBytesRead_;
102 if (nread > bufSize)
103 nread = bufSize;
104 memcpy(buf, (char *)str_.data() + nBytesRead_, nread);
105 nBytesRead_ += nread;
106 return 1;
109 Decoder *MemoryInputCodingSystem::makeDecoder() const
111 return new MemoryDecoder;
114 MemoryDecoder::MemoryDecoder()
115 : Decoder(sizeof(Char))
119 size_t MemoryDecoder::decode(Char *to, const char *from, size_t fromLen,
120 const char **rest)
122 size_t nChars = fromLen/sizeof(Char);
123 *rest = from + nChars*sizeof(Char);
124 if (from != (char *)to)
125 memmove(to, from, nChars*sizeof(Char));
126 return nChars;
129 #ifdef SP_NAMESPACE
131 #endif