2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: LiteralStorage.C /main/1 1996/07/29 16:56:08 cde-hp $ */
24 // Copyright (c) 1996 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
32 #include "LiteralStorage.h"
33 #include "CodingSystem.h"
36 #ifdef DECLARE_MEMMOVE
38 void *memmove(void *, const void *, size_t);
43 namespace SP_NAMESPACE {
46 class LiteralStorageObject : public StorageObject {
48 LiteralStorageObject(const StringC &);
49 Boolean read(char *buf, size_t bufSize, Messenger &, size_t &nread);
50 Boolean rewind(Messenger &);
52 LiteralStorageObject(const LiteralStorageObject &); // undefined
53 void operator=(const LiteralStorageObject &); // undefined
59 class MemoryInputCodingSystem : public InputCodingSystem {
61 Decoder *makeDecoder() const;
64 class MemoryDecoder : public Decoder {
67 size_t decode(Char *, const char *, size_t, const char **);
70 LiteralStorageManager::LiteralStorageManager(const char *type)
75 StorageObject *LiteralStorageManager::makeStorageObject(const StringC &id,
83 return new LiteralStorageObject(id);
86 const InputCodingSystem *LiteralStorageManager::requiredCodingSystem() const
88 static MemoryInputCodingSystem cs;
92 Boolean LiteralStorageManager::requiresCr() const
97 const char *LiteralStorageManager::type() const
102 Boolean LiteralStorageManager::inheritable() const
107 LiteralStorageObject::LiteralStorageObject(const StringC &str)
108 : str_(str), nBytesRead_(0)
112 Boolean LiteralStorageObject::rewind(Messenger &)
118 Boolean LiteralStorageObject::read(char *buf, size_t bufSize,
119 Messenger &, size_t &nread)
121 if (nBytesRead_ >= str_.size()*sizeof(Char))
123 nread = str_.size()*sizeof(Char) - nBytesRead_;
126 memcpy(buf, (char *)str_.data() + nBytesRead_, nread);
127 nBytesRead_ += nread;
131 Decoder *MemoryInputCodingSystem::makeDecoder() const
133 return new MemoryDecoder;
136 MemoryDecoder::MemoryDecoder()
137 : Decoder(sizeof(Char))
141 size_t MemoryDecoder::decode(Char *to, const char *from, size_t fromLen,
144 size_t nChars = fromLen/sizeof(Char);
145 *rest = from + nChars*sizeof(Char);
146 if (from != (char *)to)
147 memmove(to, from, nChars*sizeof(Char));