~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/cppduchain/macroset.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
   Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
 
3
***************************************************************************/
 
4
 
 
5
/***************************************************************************
 
6
 *                                                                         *
 
7
 *   This program is free software; you can redistribute it and/or modify  *
 
8
 *   it under the terms of the GNU General Public License as published by  *
 
9
 *   the Free Software Foundation; either version 2 of the License, or     *
 
10
 *   (at your option) any later version.                                   *
 
11
 *                                                                         *
 
12
 ***************************************************************************/
 
13
 
 
14
#include "macroset.h"
 
15
#include <QDataStream>
 
16
 
 
17
#include <language/editor/hashedstring.h>
 
18
 
 
19
using namespace Cpp;
 
20
using namespace KDevelop;
 
21
 
 
22
void MacroSet::read( QDataStream& stream )  {
 
23
  Q_ASSERT(0); ///@todo reimplement
 
24
  Q_UNUSED(stream)
 
25
/*    m_idHashValid = false;
 
26
    m_valueHashValid = false;
 
27
    int cnt;
 
28
    stream >> cnt;
 
29
    m_usedMacros.clear();
 
30
    rpp::pp_macro m;
 
31
    for( int a = 0; a < cnt; a++ ) {
 
32
        m.read( stream );
 
33
        m_usedMacros.insert( m );
 
34
    }*/
 
35
}
 
36
 
 
37
void MacroSet::write( QDataStream& stream ) const {
 
38
  Q_ASSERT(0); ///@todo reimplement
 
39
  Q_UNUSED(stream)
 
40
/*    stream << int( m_usedMacros.size() );
 
41
    for( Macros::const_iterator it = m_usedMacros.begin(); it != m_usedMacros.end(); ++it ) {
 
42
        (*it).write( stream );
 
43
    }*/
 
44
}
 
45
 
 
46
void MacroSet::addMacro( const rpp::pp_macro& macro ) {
 
47
  std::pair<Macros::iterator, bool> r = m_usedMacros.insert( macro );
 
48
  if( !r.second ) {
 
49
    //Make sure the macro added later will be used
 
50
    m_usedMacros.erase( r.first );
 
51
    m_usedMacros.insert( macro );
 
52
  }
 
53
 
 
54
  m_idHashValid = m_valueHashValid = false;
 
55
}
 
56
 
 
57
void MacroSet::merge( const MacroSet& macros ) {
 
58
  Macros m = macros.m_usedMacros; //Swap is needed so the merged macros take precedence
 
59
  m.insert( m_usedMacros.begin(), m_usedMacros.end() );
 
60
  m_usedMacros = m;
 
61
  m_idHashValid = m_valueHashValid = false;
 
62
}
 
63
 
 
64
 
 
65
size_t MacroSet::idHash() const {
 
66
    if( !m_idHashValid ) computeHash();
 
67
    return m_idHash;
 
68
}
 
69
 
 
70
size_t MacroSet::valueHash() const {
 
71
    if( !m_valueHashValid ) computeHash();
 
72
    return m_valueHash;
 
73
}
 
74
 
 
75
int MacroSet::size() const {
 
76
  return m_usedMacros.size();
 
77
}
 
78
 
 
79
void MacroSet::computeHash() const {
 
80
    m_idHash = 0;
 
81
    m_valueHash = 0;
 
82
    int mult = 1;
 
83
    for( Macros::const_iterator it = m_usedMacros.begin(); it != m_usedMacros.end(); ++it ) {
 
84
        mult *= 31;
 
85
        m_idHash += (*it).idHash();
 
86
        m_valueHash += (*it).valueHash();
 
87
    }
 
88
}
 
89
 
 
90
bool MacroSet::hasMacro( const QString& name ) const {
 
91
    Macros::const_iterator it = m_usedMacros.find( rpp::pp_macro( name ) );
 
92
    if( it != m_usedMacros.end() ) {
 
93
        return true;
 
94
    } else {
 
95
        return false;
 
96
    }
 
97
}
 
98
 
 
99
bool MacroSet::hasMacro( const HashedString& name ) const {
 
100
    Macros::const_iterator it = m_usedMacros.find( rpp::pp_macro( name.str() ) );
 
101
    if( it != m_usedMacros.end() ) {
 
102
        return true;
 
103
    } else {
 
104
        return false;
 
105
    }
 
106
}
 
107
 
 
108
rpp::pp_macro MacroSet::macro( const HashedString& name ) const {
 
109
    Macros::const_iterator it = m_usedMacros.find( rpp::pp_macro( name ) );
 
110
 
 
111
    if( it != m_usedMacros.end() ) {
 
112
        return *it;
 
113
    } else {
 
114
        return rpp::pp_macro();
 
115
    }
 
116
}
 
117