For test

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Print.h Source File

Print.h

00001 /*
00002   Print.h - Base class that provides print() and println()
00003   Copyright (c) 2008 David A. Mellis.  All right reserved.
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the Free Software
00017   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00020 #ifndef __PRINT_H__
00021 #define __PRINT_H__
00022 
00023 #include <inttypes.h>
00024 #include <stdio.h> // for size_t
00025 
00026 #include "WString.h"
00027 
00028 
00029 #define DEC 10
00030 #define HEX 16
00031 #define OCT 8
00032 #define BIN 2
00033 
00034 class Print
00035 {
00036   private:
00037     int write_error;
00038     size_t printNumber(unsigned long, uint8_t);
00039     size_t printFloat(double, uint8_t);
00040   protected:
00041     void setWriteError(int err = 1) { write_error = err; }
00042   public:
00043     Print() : write_error(0) {}
00044   
00045     int getWriteError() { return write_error; }
00046     void clearWriteError() { setWriteError(0); }
00047   
00048     virtual size_t write(uint8_t) = 0;
00049     size_t write(const char *str) {
00050       if (str == NULL) return 0;
00051       return write((const uint8_t *)str, strlen(str));
00052     }
00053     virtual size_t write(const uint8_t *buffer, size_t size);
00054     
00055     size_t print(const String &);
00056     size_t print(const char[]);
00057     size_t print(char);
00058     size_t print(unsigned char, int = DEC);
00059     size_t print(int, int = DEC);
00060     size_t print(unsigned int, int = DEC);
00061     size_t print(long, int = DEC);
00062     size_t print(unsigned long, int = DEC);
00063     size_t print(double, int = 2);
00064 
00065     size_t println(const String &s);
00066     size_t println(const char[]);
00067     size_t println(char);
00068     size_t println(unsigned char, int = DEC);
00069     size_t println(int, int = DEC);
00070     size_t println(unsigned int, int = DEC);
00071     size_t println(long, int = DEC);
00072     size_t println(unsigned long, int = DEC);
00073     size_t println(double, int = 2);
00074     size_t println(void);
00075 };
00076 
00077 #endif /* #ifndef __PRINT_H__ */