Jamoma API  0.6.0.a19
TTTextHandler.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularLibrary
4  *
5  * @brief TTObjectBase to handle text file reading and writing to be able to store / recall state of an object into/from text files.
6  *
7  * @details Write / Read mecanism
8 
9  writeAs<Format> / readFrom<Format> methods are not directly called using the classic message system. We should prefer use one of the exported TT<Format>Reader / TT<Format>Writer method which have :
10  - an Object attribute : the TTObjectBase you want it reads / writes a file
11  or
12  - the data structure to pass in order to read / write depending on the selected <Format>
13 
14  This allow us to use the same method to start reading / writing and even to ask to other objects to / write recursively on the same data stucture.
15 
16  Example :
17 
18  If you want to read in Xml format you set the Object attribute as myTopObject then you call the Read message with aValueContainingFullPathToaFile. Then this method (as a friend of your TTTopObject class) will automatically create an XmlReader data structure and call ReadFromXml(aValueContainingAnXmlReader) on your myTopObject.
19 
20  Because your TTTopObject class used TTLowerObject to describe himself (and have to extract their xml description from the xml file to set them up) the ReadFromXml method sets recursively the Object Attribute with aLowerObject and then calls the Read message with an empty value : this would calls the ReadFromXml(aValueContainingAnXmlReader) on your TTLowerObject.
21  *
22  * @authors Théo de la Hogue
23  *
24  * @copyright © 2010, Théo de la Hogue @n
25  * This code is licensed under the terms of the "New BSD License" @n
26  * http://creativecommons.org/licenses/BSD/
27  */
28 
29 
30 #ifndef __TT_TEXT_HANDLER_H__
31 #define __TT_TEXT_HANDLER_H__
32 
33 #include "TTModularIncludes.h"
34 
35 /**
36  */
37 
38 class TTMODULAR_EXPORT TTTextHandler : public TTObjectBase
39 {
40  TTCLASS_SETUP(TTTextHandler)
41 
42 public: // use public for recursive access
43 
44  TTObject mObject; ///< the last handled object
45  TTSymbol mFilePath; ///< the path to the last writen/read file
46 
47  TTString *mWriter; ///< the text where to write
48  TTString *mReader; ///< the text to read
49 
50  TTValuePtr mLine; ///< the line being read by the Reader
51  TTUInt8 mTabCount; ///< count the number of tabulation at the beginning of the line
52  TTUInt8 mSpaceNumberForTab; ///< ATTRIBUTE : depending on the text editor a tab can be equal to 4, 5, 8 white space
53 
54  TTBoolean mFirstLine; ///< a flag to know if it is the first line
55  TTBoolean mLastLine; ///< a flag to know if it is the last line
56 
57  /** TTTextWriter could takes a file path or a string buffer pointer. */
58  TTErr Write(const TTValue& args, TTValue& outputValue);
59  TTErr WriteAgain();
60 
61  /** TTTextReader could takes a file path or a string buffer pointer. */
62  TTErr Read(const TTValue& args, TTValue& outputValue);
63  TTErr ReadAgain();
64 
65 private :
66 
67  TTBoolean mIsWriting; ///< a flag to know if it is writing
68  TTBoolean mIsReading; ///< a flag to know if it is reading
69 
70 };
71 
72 typedef TTTextHandler* TTTextHandlerPtr;
73 
74 
75 #endif // __TT_TEXT_HANDLER_H__
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTModular Library.
Create and use Jamoma object instances.
Definition: TTObject.h:29
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
The TTString class is used to represent a string.
Definition: TTString.h:34
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174