00001 /***************************** License ********************************** 00002 00003 Copyright (C) 2008 by Communicative Machines 00004 http://www.cmlabs.com All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 ************************************************************************/ 00021 00022 00023 #if !defined(_INFOITEM_) 00024 #define _INFOITEM_ 00025 00026 #include "Object.h" 00027 #include <stdlib.h> 00028 #include <stdio.h> 00029 #include <time.h> 00030 #include "JString.h" 00031 #include "Collections.h" 00032 #include "JTime.h" 00033 #include "DotString.h" 00034 #include "XMLParser.h" 00035 00036 namespace cmlabs { 00037 00038 class InfoItem : public Object { 00039 public: 00040 //! to create empty InfoItem 00041 InfoItem(); 00042 //! to create from XML 00043 InfoItem(const JString& xml); 00044 //! to create from XML node 00045 InfoItem(XMLNode* node); 00046 //! to create from other InfoItem 00047 InfoItem(const InfoItem &item); 00048 ~InfoItem(); 00049 00050 bool unitTest(); 00051 Object* clone() const; 00052 InfoItem* cloneDataOnly() const; 00053 InfoItem& operator=(const InfoItem &item); 00054 //! Get total size of payload 00055 virtual unsigned long getPayloadSize() const; 00056 00057 // *************************************************************** 00058 // File Functions 00059 // *************************************************************** 00060 00061 bool loadFromFile(const JString& filename); 00062 bool writeToFile(const JString& filename); 00063 00064 // *************************************************************** 00065 // XML/HTML/Text Functions 00066 // *************************************************************** 00067 00068 //! Read XML node into this InfoItem... 00069 bool fromXML(XMLNode* xmlNode); 00070 //! Convert InfoItem to XML... 00071 JString toXML(); 00072 00073 //! Nicely formatted text print 00074 JString print(); 00075 //! One line text print 00076 JString printShort(); 00077 //! Generate HTML... 00078 JString printHTML(JString htmlTemplate = ""); 00079 JString toHTML(); 00080 00081 // *************************************************************** 00082 // Binary Functions 00083 // *************************************************************** 00084 00085 //! Get the size of binary data chunk, -1 for all chunks 00086 long getBinarySize(int chunk); 00087 //! Get the number of data chunks 00088 int getBinaryChunkCount(); 00089 //! Write binary data to buffer at chunk number 'chunk' 00090 long toBinaryBuffer(int chunk, char* buffer, int maxlen); 00091 //! Set the data after separate reception 00092 bool fromBinaryBuffer(int chunk, char* buffer, long len); 00093 00094 // *************************************************************** 00095 // Global Setters and Getters 00096 // *************************************************************** 00097 00098 //! Set the attached Object for the InfoItem 00099 bool setObject(Object* obj); 00100 //! Get the attached Object for the InfoItem or NULL 00101 Object* getObject(); 00102 //! Get the attached Object type (Class name) for the InfoItem 00103 JString getObjectType(); 00104 //! Delete the attached Object; NB: Will destroy object 00105 bool deleteObject(); 00106 //! Takes away the attached object 00107 Object* takeObject(); 00108 00109 // Getters 00110 00111 //! Get a copy of ID 00112 JString getID(); 00113 JTime getCreatedTime(); 00114 JString getEntry(const JString& name); 00115 JTime getTime(const JString& name); 00116 00117 // Setters 00118 00119 //! Set InfoItem ID, autogenerated if not set 00120 bool setID(const JString& id); 00121 bool setCreatedTime(const JTime& time); 00122 bool setEntry(const JString& name, const JString& value); 00123 bool setTime(const JString& name, const JTime& t); 00124 00125 00126 00127 JString id; 00128 JTime createdTime; 00129 //! Dictionary of generic text entries 00130 Dictionary auxDict; 00131 //! Dictionary of Timestamps 00132 ObjectDictionary timeDict; 00133 Object* object; 00134 00135 00136 }; 00137 00138 } // namespace cmlabs 00139 00140 #endif 00141