SLLIB – Script-Like C-Language Library Basic User Reference Guide
Total Page:16
File Type:pdf, Size:1020Kb
Simple and Light Interfaces for C and C++ users SLLIB – Script-Like C-language library Basic User Reference Guide Version 1.4.2[not finished] 2013-05-19 CREDITS SOFTWARE DEVELOPMENT: Chisato Yamauchi QUALITY ASSURANCE: SEC Co.,LTD. MANUAL DOCUMENT: Chisato Yamauchi, Sachimi Fujishima AND SEC Co.,LTD. MANUAL TRANSLATION: KOYOSHOUJI CO.,LTD., Space Engineering Development Co.,LTD. AND Sakura Academia Corporation SPECIAL THANKS: Daisuke Ishihara, Hajime Baba, Iku Shinohara, Keiichi Matsuzaki, Michitaro Koike, Sergio Pascual ANDYukioYamamoto Web page: http://www.ir.isas.jaxa.jp/~cyamauch/sli/ 2 SLLIB Basic User Reference Guide Contents 1 Introduction 11 1.1 What is SLLIB? ...................................... 11 1.2 The Reason why SLLIB was created .......................... 14 1.3 Development policies for SLLIB — Following the manner of the libc and leveraging the advantages of the libc ................................ 14 1.4 All you need is the knowledge of the C language ................... 15 1.5 What is object-orientation for end-users? ....................... 15 1.5.1 Object-orientation is nothing special ...................... 16 1.5.2 Benefits of object-orientation .......................... 17 1.5.3 Definitions of the terms and conception on codes ............... 18 2 Installation 19 2.1 Supported operating systems .............................. 19 2.2 Building and installing SLLIB .............................. 19 2.2.1 Method 1—A method using just only make .................. 19 2.2.2 Method 2—A method using configure and make ............... 20 3 Tutorial 21 3.1 Hello World ........................................ 21 3.2 Opening and reading files ................................ 21 3.2.1 When standard streams are used ........................ 21 3.2.2 When the most powerful “versatile” streams are used (Strongly recommended) 22 3.2.3 Correspondence relationships with the functions of the libc ......... 24 3.2.4 Endianness conversion of complex binary data ................ 25 3.2.5 Collaborations with GNUPLOT ........................ 25 3.3 Operating strings .................................... 26 3.3.1 Basics ....................................... 26 3.3.2 Accessing characters one by one ........................ 27 3.3.3 Applications for reading text files from a stream ............... 27 3.3.4 Editing strings .................................. 28 3.3.5 Leveraging strings ................................ 28 3.3.6 Applications of the extended regular expressions (Back reference is also avail- able) ........................................ 29 3.4 Operating string arrays ................................. 29 3.4.1 Immediate assignment .............................. 30 3.4.2 Using dprint() for debugging .......................... 30 3.4.3 Swiftly passing on to execv() and execvp() .................. 31 3.4.4 Editing strings on all the elements ....................... 31 3.4.5 Editing arrays .................................. 31 3.4.6 Making arguments for main() easy to use ................... 32 3.4.7 Splitting white space-delimited and CSV-format strings to put into an array— split() member function ............................. 32 3.4.8 Storing the result of regular expression matches ................ 33 3.5 Operating associative arrays ............................... 34 3.5.1 Immediate assignment .............................. 34 3.5.2 Using dprint() for debugging .......................... 34 3.5.3 Editing strings on all the elements ....................... 34 3.5.4 Editing ...................................... 35 Ver. 1.4.2 3 3.5.5 Easily accessing data files using split keys() and split values() ........ 35 3.6 Handling multidimensional arrays without effort ................... 36 3.6.1 Immediate assignment (Auto-resizing mode: One-dimensional arrays through three-dimensional arrays) ............................ 36 3.6.2 Updating number of dimension and elements ................. 37 3.6.3 Resizing for each dimension ........................... 37 3.6.4 Operations on arrays ............................... 37 3.6.5 Non-auto resizing mode (For image buffers) .................. 38 3.6.6 Fastest access to array elements ......................... 38 3.6.7 Copy and operation of images using IDL/Python-like expression ...... 39 3.6.8 Statistics for array elements ........................... 40 3.6.9 Combine images ................................. 41 3.6.10 Conversion of endianness ............................ 41 4 Assumptions that users should comprehend before using SLLIB 43 4.1 NAMESPACE ...................................... 43 4.2 NULL and 0 ........................................ 43 4.3 const char *, char *const *, const char *const * .................... 44 4.4 References ......................................... 44 4.5 Pointer variables for an object and arguments/return values for a function ..... 45 5 FAQ 46 5.1 Frequent warnings and errors in compiling ....................... 46 5.1.1 warning: cannot pass objects of non-POD type ................ 46 5.1.2 error: ‘xxx’ was not declared in this scope ................... 46 5.1.3 error: call of overloaded ‘xxx’ is ambiguous .................. 46 5.1.4 error: invalid conversion from ‘const char*’ to ‘char*’ ............. 46 5.1.5 error: passing ‘xxx’ as ‘yyy’ argument of ‘zzz’ discards qualifiers ...... 46 6 Information for advanced users 47 6.1 Instructions for creating objects in the heap ...................... 47 6.2 When you want to create an array of objects in the heap ............... 47 6.3 Collaborations between structures and classes ..................... 47 6.4 Handling of the exceptions, try {} & catch () ..................... 48 7 The CSTREAMIO class and a summary of its inherited classes 49 7.1 A summary of the inherited classes ........................... 49 7.2 Overview of the implementation of the member functions for the base classes and inherited classes ...................................... 49 8 References for the CSTREAMIO class and its inherited classes 51 8.1 Member functions for the CSTREAMIO class ..................... 51 8.1.1 open(), openf(), vopenf() ............................ 51 8.1.2 close() ....................................... 53 8.1.3 read(), write() .................................. 54 8.1.4 bread() ...................................... 55 8.1.5 bwrite() ...................................... 57 8.1.6 rskip() ....................................... 58 8.1.7 wskip() ...................................... 59 8.1.8 getchr() ...................................... 59 8.1.9 getstr() ...................................... 60 4 SLLIB Basic User Reference Guide 8.1.10 getline() ...................................... 61 8.1.11 scanf(), vscanf() ................................. 62 8.1.12 putchr() ...................................... 65 8.1.13 putstr() ...................................... 65 8.1.14 printf(), vprintf() ................................. 66 8.1.15 flush() ....................................... 69 8.1.16 eof(), error(), reseterr() ............................. 69 8.1.17 seek(), rewind() .................................. 70 8.1.18 tell() ........................................ 71 8.1.19 is seekable() .................................... 71 8.2 The STDSTREAMIO class ............................... 73 8.2.1 How to create an object ............................. 73 8.2.2 open(), openf(), vopenf() ............................ 74 8.2.3 eprintf(), veprintf() ................................ 75 8.2.4 eflush() ...................................... 76 8.2.5 seek(), rewind() .................................. 76 8.2.6 tell() ........................................ 77 8.2.7 content length() ................................. 78 8.3 GZSTREAMIO class ................................... 79 8.3.1 open(), openf(), vopenf() ............................ 79 8.3.2 sync() ....................................... 82 8.4 The BZSTREAMIO class ................................ 83 8.4.1 open(), openf(), vopenf() ............................ 83 8.5 The HTTPSTREAMIO class .............................. 86 8.5.1 open(), openf(), vopenf() ............................ 86 8.5.2 content length() ................................. 87 8.5.3 user agent().assign() ............................... 88 8.6 The FTPSTREAMIO class ............................... 89 8.6.1 open(), openf(), vopenf() ............................ 89 8.6.2 content length() ................................. 91 8.6.3 username().assign() ............................... 92 8.6.4 password().assign() ................................ 92 8.7 The PIPESTREAMIO class ............................... 93 8.7.1 open(), openf(), vopenf() ............................ 93 8.8 The DIGESTSTREAMIO class ............................. 97 8.8.1 open(), openf(), vopenf() ............................ 98 8.8.2 openp(), openpf(), vopenpf() .......................... 99 8.8.3 is write mode() .................................. 101 8.8.4 content length() ................................. 102 8.8.5 user agent().assign() ............................... 102 8.8.6 username().assign() ............................... 103 8.8.7 password().assign() ................................ 103 8.9 The TERMLINEIO class ................................ 104 8.9.1 open() ....................................... 105 8.9.2 set prompt(), setf prompt(), vsetf prompt() .................. 106 8.9.3 automate history() ................................ 107 8.9.4 add history() ................................... 108 8.9.5 clear history() .................................