cstool/objectcomment.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2012 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSTOOL_OBJECTCOMMENT_H__ 00020 #define __CS_CSTOOL_OBJECTCOMMENT_H__ 00021 00026 #include "csutil/scf.h" 00027 #include "csutil/scfstr.h" 00028 #include "csutil/csobject.h" 00029 #include "iutil/document.h" 00030 #include "iutil/objreg.h" 00031 #include "imap/objectcomment.h" 00032 #include "iengine/engine.h" 00033 00034 namespace CS 00035 { 00036 namespace Persistence 00037 { 00038 00042 class ObjectComment : public scfImplementationExt1< 00043 ObjectComment,csObject,iObjectComment> 00044 { 00045 private: 00046 csRef<scfString> comment; 00047 00048 public: 00049 ObjectComment () : scfImplementationType (this) 00050 { 00051 comment.AttachNew (new scfString ()); 00052 } 00053 virtual ~ObjectComment () { } 00054 00055 virtual iString* GetComment () { return comment; } 00056 virtual iObject* QueryObject () { return (csObject*)this; } 00057 }; 00058 00064 inline bool SaveComment (iEngine* engine, iObject* obj, iDocumentNode* parentNode) 00065 { 00066 if (!engine->GetSaveableFlag ()) return false; 00067 csRef<iObjectComment> comment = CS::GetChildObject<iObjectComment> (obj); 00068 if (comment) 00069 { 00070 csRef<iDocumentNode> commentNode = parentNode->CreateNodeBefore (CS_NODE_COMMENT, 0); 00071 commentNode->SetValue (comment->GetComment ()->GetData ()); 00072 return true; 00073 } 00074 return false; 00075 } 00076 00082 inline bool SaveComment (iObjectRegistry* object_reg, iObject* obj, iDocumentNode* parentNode) 00083 { 00084 csRef<iEngine> engine = csQueryRegistry<iEngine> (object_reg); 00085 return SaveComment (engine, obj, parentNode); 00086 } 00087 00096 inline bool LoadComment (iEngine* engine, iObject* object, iDocumentNode* node, 00097 bool replace = false) 00098 { 00099 if (!engine) return false; 00100 if (!engine->GetSaveableFlag ()) return false; 00101 csRef<iObjectComment> comment = CS::GetChildObject<iObjectComment> (object); 00102 if (comment && replace) 00103 { 00104 comment->GetComment ()->Replace (node->GetValue ()); 00105 return true; 00106 } 00107 else if (!comment) 00108 { 00109 comment.AttachNew (new CS::Persistence::ObjectComment ()); 00110 object->ObjAdd (comment->QueryObject ()); 00111 comment->GetComment ()->Replace (node->GetValue ()); 00112 return true; 00113 } 00114 return false; 00115 } 00116 00125 inline bool LoadComment (iObjectRegistry* object_reg, iObject* object, 00126 iDocumentNode* node, bool replace = false) 00127 { 00128 csRef<iEngine> engine = csQueryRegistry<iEngine> (object_reg); 00129 return LoadComment (engine, object, node, replace); 00130 } 00131 00132 } 00133 } 00134 00135 #endif // __CS_CSTOOL_OBJECTCOMMENT_H__ 00136
Generated for Crystal Space 2.1 by doxygen 1.6.1
