nsprpub/pr/src/cplus/rcascii.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/src/cplus/rcascii.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,143 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 +** Class definitions to format ASCII data.
    1.11 +*/
    1.12 +
    1.13 +#if defined(_RCASCII_H)
    1.14 +#else
    1.15 +#define _RCASCII_H
    1.16 +
    1.17 +/*
    1.18 +** RCFormatStuff
    1.19 +**  This class maintains no state - that is the responsibility of
    1.20 +**  the class' client. For each call to Sx_printf(), the StuffFunction
    1.21 +**  will be called for each embedded "%" in the 'fmt' string and once
    1.22 +**  for each interveaning literal.
    1.23 +*/
    1.24 +class PR_IMPLEMENT(RCFormatStuff)
    1.25 +{
    1.26 +public:
    1.27 +    RCFormatStuff();
    1.28 +    virtual ~RCFormatStuff();
    1.29 +
    1.30 +    /*
    1.31 +    ** Process the arbitrary argument list using as indicated by
    1.32 +    ** the 'fmt' string. Each segment of the processing the stuff
    1.33 +    ** function is called with the relavent translation.
    1.34 +    */
    1.35 +    virtual PRInt32 Sx_printf(void *state, const char *fmt, ...);
    1.36 +
    1.37 +    /*
    1.38 +    ** The 'state' argument is not processed by the runtime. It
    1.39 +    ** is merely passed from the Sx_printf() call. It is intended
    1.40 +    ** to be used by the client to figure out what to do with the
    1.41 +    ** new string.
    1.42 +    **
    1.43 +    ** The new string ('stuff') is ASCII translation driven by the
    1.44 +    ** Sx_printf()'s 'fmt' string. It is not guaranteed to be a null
    1.45 +    ** terminated string.
    1.46 +    **
    1.47 +    ** The return value is the number of bytes copied from the 'stuff'
    1.48 +    ** string. It is accumulated for each of the calls to the stuff
    1.49 +    ** function and returned from the original caller of Sx_printf().
    1.50 +    */
    1.51 +    virtual PRSize StuffFunction(
    1.52 +        void *state, const char *stuff, PRSize stufflen) = 0;
    1.53 +};  /* RCFormatStuff */
    1.54 +
    1.55 +
    1.56 +/*
    1.57 +** RCFormatBuffer
    1.58 +**  The caller is supplying the buffer, the runtime is doing all
    1.59 +**  the conversion. The object contains no state, so is reusable
    1.60 +**  and reentrant.
    1.61 +*/
    1.62 +class PR_IMPLEMENT(RCFormatBuffer): public RCFormatStuff
    1.63 +{
    1.64 +public:
    1.65 +    RCFormatBuffer();
    1.66 +    virtual ~RCFormatBuffer();
    1.67 +
    1.68 +    /*
    1.69 +    ** Format the trailing arguments as indicated by the 'fmt'
    1.70 +    ** string. Put the result in 'buffer'. Return the number
    1.71 +    ** of bytes moved into 'buffer'. 'buffer' will always be
    1.72 +    ** a properly terminated string even if the convresion fails.
    1.73 +    */
    1.74 +    virtual PRSize Sn_printf(
    1.75 +        char *buffer, PRSize length, const char *fmt, ...);
    1.76 +
    1.77 +    virtual char *Sm_append(char *buffer, const char *fmt, ...);
    1.78 +
    1.79 +private:
    1.80 +    /*
    1.81 +    ** This class overrides the stuff function, does not preserve
    1.82 +    ** its virtual-ness and no longer allows the clients to call
    1.83 +    ** it in the clear. In other words, it is now the implementation
    1.84 +    ** for this class.
    1.85 +    */
    1.86 +    PRSize StuffFunction(void*, const char*, PRSize);
    1.87 +        
    1.88 +};  /* RCFormatBuffer */
    1.89 +
    1.90 +/*
    1.91 +** RCFormat
    1.92 +**  The runtime is supplying the buffer. The object has state - the
    1.93 +**  buffer. Each operation must run to completion before the object
    1.94 +**  can be reused. When it is, the buffer is reset (whatever that
    1.95 +**  means). The result of a conversion is available via the extractor.
    1.96 +**  After extracted, the memory still belongs to the class - if the
    1.97 +**  caller wants to retain or modify, it must first be copied.
    1.98 +*/
    1.99 +class PR_IMPLEMENT(RCFormat): pubic RCFormatBuffer
   1.100 +{
   1.101 +public:
   1.102 +    RCFormat();
   1.103 +    virtual ~RCFormat();
   1.104 +
   1.105 +    /*
   1.106 +    ** Translate the trailing arguments according to the 'fmt'
   1.107 +    ** string and store the results in the object.
   1.108 +    */
   1.109 +    virtual PRSize Sm_printf(const char *fmt, ...);
   1.110 +
   1.111 +    /*
   1.112 +    ** Extract the latest translation.
   1.113 +    ** The object does not surrender the memory occupied by
   1.114 +    ** the string. If the caller wishes to modify the data,
   1.115 +    ** it must first be copied.
   1.116 +    */
   1.117 +    const char*();
   1.118 +
   1.119 +private:
   1.120 +    char *buffer;
   1.121 +
   1.122 +    RCFormat(const RCFormat&);
   1.123 +    RCFormat& operator=(const RCFormat&);
   1.124 +}; /* RCFormat */
   1.125 +
   1.126 +/*
   1.127 +** RCPrint
   1.128 +**  The output is formatted and then written to an associated file
   1.129 +**  descriptor. The client can provide a suitable file descriptor
   1.130 +**  or can indicate that the output should be directed to one of
   1.131 +**  the well-known "console" devices.
   1.132 +*/
   1.133 +class PR_IMPLEMENT(RCPrint): public RCFormat
   1.134 +{
   1.135 +    virtual ~RCPrint();
   1.136 +    RCPrint(RCIO* output);
   1.137 +    RCPrint(RCFileIO::SpecialFile output);
   1.138 +
   1.139 +    virtual PRSize Printf(const char *fmt, ...);
   1.140 +private:
   1.141 +    RCPrint();
   1.142 +};  /* RCPrint */
   1.143 +
   1.144 +#endif /* defined(_RCASCII_H) */
   1.145 +
   1.146 +/* RCAscii.h */

mercurial