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 // Object.h: interface for the Object class. 00024 // 00025 ////////////////////////////////////////////////////////////////////// 00026 00027 #if !defined(AFX_OBJECT_H__D0E87E36_5CA6_4DB2_B512_46D23CDE9966__INCLUDED_) 00028 #define AFX_OBJECT_H__D0E87E36_5CA6_4DB2_B512_46D23CDE9966__INCLUDED_ 00029 00030 #if _MSC_VER > 1000 00031 #pragma once 00032 #endif // _MSC_VER > 1000 00033 00034 #include "clversion.h" 00035 #include "standard.h" 00036 00037 namespace cmlabs { 00038 00039 class Dictionary; 00040 class JString; 00041 class XMLNode; 00042 class SysInfo; 00043 00044 00045 //! Base object for all other objects 00046 class Object 00047 { 00048 public: 00049 Object(); 00050 virtual ~Object(); 00051 00052 static double getRandomNumber(); 00053 static JString getCoreLibraryVersion(); 00054 00055 static JString createUniqueID(); 00056 static JString createUniqueID(const JString& title); 00057 static JString extractIDLabel(const JString& id); 00058 00059 //! Try to create an object by analysing the XML 00060 static Object* createObjectFromXML(const JString& xml); 00061 static Object* createObjectFromXML(XMLNode* node); 00062 00063 static SysInfo getSystemInfo(); 00064 static bool wait(long ms); 00065 00066 virtual bool unitTest(); 00067 // virtual bool unitTest() = 0; 00068 virtual bool equals(const Object* o2) const; 00069 virtual int compare(const Object* o2) const; 00070 // virtual bool equals(Object* o2) = 0; 00071 virtual JString print(); 00072 virtual JString toHTML(); 00073 virtual JString toXML(); 00074 virtual bool fromXML(const JString& xml); 00075 virtual bool fromXML(XMLNode* node); 00076 virtual Object* clone() const = 0; 00077 // bool wait(long ms) const; 00078 //! Get total size of payload 00079 virtual unsigned long getPayloadSize() const; 00080 00081 void addUnitTestLog(const JString& str); 00082 JString getUnitTestLog(); 00083 00084 //! Get the class name 00085 virtual JString getClass() const; 00086 virtual bool isSameClass(const Object* o2) const; 00087 virtual bool isCollection() const; 00088 virtual unsigned long getHash() const; 00089 00090 //! Get the size of binary data chunk, -1 for all chunks 00091 virtual long getBinarySize(int chunk); 00092 //! Get the number of data chunks 00093 virtual int getBinaryChunkCount(); 00094 //! Write binary data to buffer at chunk number 'chunk' 00095 virtual long toBinaryBuffer(int chunk, char* buffer, int maxlen); 00096 //! Set the data after separate reception 00097 virtual bool fromBinaryBuffer(int chunk, char* buffer, long len); 00098 00099 //! Get the OS process ID 00100 int getProcID(); 00101 char* unitTestLog; 00102 00103 private: 00104 // JString generateUUID() const; 00105 // char* classname; 00106 // JString unitTestLog; 00107 }; 00108 00109 class ObjectLink : public Object { 00110 public: 00111 ObjectLink(); 00112 ~ObjectLink(); 00113 Object* clone() const; 00114 JString toXML(); 00115 bool isValid(); 00116 Object* object; 00117 bool stopUsing; 00118 bool* active; 00119 }; 00120 00121 class ObjectLinkProvider : public Object { 00122 public: 00123 ObjectLinkProvider(ObjectLink* link, Object* object); 00124 ~ObjectLinkProvider(); 00125 Object* clone() const; 00126 bool isInUse(); 00127 bool stopUsingMe(); 00128 ObjectLink* link; 00129 bool active; 00130 }; 00131 00132 00133 #define INDEX_TYPE 6 00134 #define INDEX_VARIATION 8 00135 #define TYPE_RANDOM_BASED 4 00136 00137 } // namespace cmlabs 00138 00139 #include "JString.h" 00140 00141 00142 #endif // !defined(AFX_OBJECT_H__D0E87E36_5CA6_4DB2_B512_46D23CDE9966__INCLUDED_)