tag.cpp
Go to the documentation of this file.00001 /* This file is part of KDevelop 00002 Copyright (C) 2003 Roberto Raggi <roberto@kdevelop.org> 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 License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include "tag.h" 00021 #include <qdatastream.h> 00022 00023 Tag::Tag() 00024 { 00025 data = new TagData(); 00026 data->kind = 0; 00027 data->flags = 0; 00028 data->startLine = 0; 00029 data->startColumn = 0; 00030 data->endLine = 0; 00031 data->endColumn = 0; 00032 } 00033 00034 Tag::Tag( const Tag& source ) 00035 { 00036 data = source.data; 00037 data->ref(); 00038 } 00039 00040 Tag::~Tag() 00041 { 00042 if( data->deref() ){ 00043 delete( data ); 00044 data = 0; 00045 } 00046 } 00047 00048 void Tag::detach() 00049 { 00050 if( data->count != 1 ) 00051 *this = copy(); 00052 } 00053 00054 Tag Tag::copy() 00055 { 00056 Tag t; 00057 00058 t.data->id = data->id; 00059 t.data->kind = data->kind; 00060 t.data->flags = data->flags; 00061 t.data->name = data->name; 00062 t.data->scope = data->scope; 00063 t.data->fileName = data->fileName; 00064 t.data->startLine = data->startLine; 00065 t.data->startColumn = data->startColumn; 00066 t.data->endLine = data->endLine; 00067 t.data->endColumn = data->endColumn; 00068 t.data->attributes = data->attributes; 00069 00070 return t; 00071 } 00072 00073 Tag& Tag::operator = ( const Tag& source ) 00074 { 00075 source.data->ref(); 00076 if ( data->deref() ){ 00077 delete data; 00078 } 00079 data = source.data; 00080 00081 return( *this ); 00082 } 00083 00084 void Tag::load( QDataStream& stream ) 00085 { 00086 stream 00087 >> data->id 00088 >> data->kind 00089 >> data->flags 00090 >> data->name 00091 >> data->scope 00092 >> data->fileName 00093 >> data->startLine 00094 >> data->startColumn 00095 >> data->endLine 00096 >> data->endColumn 00097 >> data->attributes; 00098 } 00099 00100 void Tag::store( QDataStream& stream ) const 00101 { 00102 stream 00103 << data->id 00104 << data->kind 00105 << data->flags 00106 << data->name 00107 << data->scope 00108 << data->fileName 00109 << data->startLine 00110 << data->startColumn 00111 << data->endLine 00112 << data->endColumn 00113 << data->attributes; 00114 } 00115 00116 QDataStream& operator << ( QDataStream& s, const Tag& t) 00117 { 00118 t.store( s ); 00119 return s; 00120 } 00121 00122 QDataStream& operator >> ( QDataStream& s, Tag& t ) 00123 { 00124 t.load( s ); 00125 return s; 00126 } 00127