~ubuntu-branches/ubuntu/trusty/aria2/trusty-proposed

« back to all changes in this revision

Viewing changes to src/Option.cc

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2013-12-16 18:41:03 UTC
  • mfrom: (2.5.21 sid)
  • Revision ID: package-import@ubuntu.com-20131216184103-xzah3019zwut429g
Tags: 1.18.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <cstdlib>
38
38
#include <cstring>
39
39
 
40
 
#include "prefs.h"
41
40
#include "bitfield.h"
42
41
 
43
42
namespace aria2 {
68
67
namespace {
69
68
 
70
69
template<typename V>
71
 
void setBit(V& b, const Pref* pref)
 
70
void setBit(V& b, PrefPtr pref)
72
71
{
73
72
  b[pref->i/8] |= 128 >> (pref->i%8);
74
73
}
75
74
 
76
75
template<typename V>
77
 
void unsetBit(V& b, const Pref* pref)
 
76
void unsetBit(V& b, PrefPtr pref)
78
77
{
79
78
  b[pref->i/8] &= ~(128 >> (pref->i%8));
80
79
}
81
80
 
82
81
} // namespace
83
82
 
84
 
void Option::put(const Pref* pref, const std::string& value) {
 
83
void Option::put(PrefPtr pref, const std::string& value) {
85
84
  setBit(use_, pref);
86
85
  table_[pref->i] = value;
87
86
}
88
87
 
89
 
bool Option::defined(const Pref* pref) const
 
88
bool Option::defined(PrefPtr pref) const
90
89
{
91
90
  return bitfield::test(use_, use_.size()*8, pref->i) ||
92
91
    (parent_ && parent_->defined(pref));
93
92
}
94
93
 
95
 
bool Option::definedLocal(const Pref* pref) const
 
94
bool Option::definedLocal(PrefPtr pref) const
96
95
{
97
96
  return bitfield::test(use_, use_.size()*8, pref->i);
98
97
}
99
98
 
100
 
bool Option::blank(const Pref* pref) const
 
99
bool Option::blank(PrefPtr pref) const
101
100
{
102
101
  if(bitfield::test(use_, use_.size()*8, pref->i)) {
103
102
    return table_[pref->i].empty();
106
105
  }
107
106
}
108
107
 
109
 
const std::string& Option::get(const Pref* pref) const
 
108
const std::string& Option::get(PrefPtr pref) const
110
109
{
111
110
  if(bitfield::test(use_, use_.size()*8, pref->i)) {
112
111
    return table_[pref->i];
117
116
  }
118
117
}
119
118
 
120
 
int32_t Option::getAsInt(const Pref* pref) const {
 
119
int32_t Option::getAsInt(PrefPtr pref) const {
121
120
  const std::string& value = get(pref);
122
121
  if(value.empty()) {
123
122
    return 0;
126
125
  }
127
126
}
128
127
 
129
 
int64_t Option::getAsLLInt(const Pref* pref) const {
 
128
int64_t Option::getAsLLInt(PrefPtr pref) const {
130
129
  const std::string& value = get(pref);
131
130
  if(value.empty()) {
132
131
    return 0;
135
134
  }
136
135
}
137
136
 
138
 
bool Option::getAsBool(const Pref* pref) const {
 
137
bool Option::getAsBool(PrefPtr pref) const {
139
138
  return get(pref) == A2_V_TRUE;
140
139
}
141
140
 
142
 
double Option::getAsDouble(const Pref* pref) const {
 
141
double Option::getAsDouble(PrefPtr pref) const {
143
142
  const std::string& value = get(pref);
144
143
  if(value.empty()) {
145
144
    return 0.0;
148
147
  }
149
148
}
150
149
 
151
 
void Option::remove(const Pref* pref)
 
150
void Option::remove(PrefPtr pref)
152
151
{
153
152
  unsetBit(use_, pref);
154
153
  table_[pref->i].clear();