当前位置: 首页>>代码示例>>C++>>正文


C++ map::empty方法代码示例

本文整理汇总了C++中map::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ map::empty方法的具体用法?C++ map::empty怎么用?C++ map::empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在map的用法示例。


在下文中一共展示了map::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: create

result_t SingleDataField::create(const string id, const unsigned char length,
	const string name, const string comment, const string unit,
	const PartType partType, int divisor, map<unsigned int, string> values,
	const string constantValue, const bool verifyValue, SingleDataField* &returnField)
{
	DataType* dataType = DataTypeList::getInstance()->get(id, length==REMAIN_LEN ? (unsigned char)0 : length);
	if (!dataType) {
		return RESULT_ERR_NOTFOUND;
	}
	unsigned char bitCount = dataType->getBitCount();
	unsigned char byteCount = (unsigned char)((bitCount + 7) / 8);
	if (dataType->isAdjustableLength()) {
		// check length
		if ((bitCount % 8) != 0) {
			if (length == 0) {
				bitCount = 1; // default bit count: 1 bit
			} else if (length <= bitCount) {
				bitCount = length;
			} else {
				return RESULT_ERR_OUT_OF_RANGE; // invalid length
			}
			byteCount = (unsigned char)((bitCount + 7) / 8);
		} else if (length == 0) {
			byteCount = 1; //default byte count: 1 byte
		} else if (length <= byteCount || length == REMAIN_LEN) {
			byteCount = length;
		} else {
			return RESULT_ERR_OUT_OF_RANGE; // invalid length
		}
	}
	if (!constantValue.empty()) {
		returnField = new ConstantDataField(name, comment, unit, dataType, partType, byteCount, constantValue, verifyValue);
		return RESULT_OK;
	}
	if (dataType->isNumeric()) {
		NumberDataType* numType = (NumberDataType*)dataType;
		if (values.empty() && numType->hasFlag(DAY)) {
			for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++)
				values[numType->getMinValue() + i] = dayNames[i];
		}
		result_t result = numType->derive(divisor, bitCount, numType);
		if (result!=RESULT_OK) {
			return result;
		}
		if (values.empty()) {
			returnField = new SingleDataField(name, comment, unit, numType, partType, byteCount);
			return RESULT_OK;
		}
		if (values.begin()->first < numType->getMinValue() || values.rbegin()->first > numType->getMaxValue()) {
			return RESULT_ERR_OUT_OF_RANGE;
		}
		returnField = new ValueListDataField(name, comment, unit, numType, partType, byteCount, values);
		return RESULT_OK;
	}
	if (divisor != 0 || !values.empty()) {
		return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field
	}
	returnField = new SingleDataField(name, comment, unit, (StringDataType*)dataType, partType, byteCount);
	return RESULT_OK;
}
开发者ID:john30,项目名称:ebusd,代码行数:60,代码来源:data.cpp

示例2: work

bool work() {
    int x, y, z;
    scanf("%d", &x);
    if (!x) return false;
    switch(x) {
        case 1:
        scanf("%d%d", &y, &z);
        a.insert(make_pair(z, y));
        break;
        case 3:
        if (a.empty()) {
            printf("%d\n", 0);
        } else {
            it t = a.begin();
            printf("%d\n", t -> second);
            a.erase(t);
        }
        break;
        case 2:
        if (a.empty()) {
            printf("%d\n", 0);
        } else {
            it t = a.end();
            --t;
            printf("%d\n", t -> second);
            a.erase(t);
        }
        break;
    }
    return true;
}
开发者ID:gyf1214,项目名称:OI,代码行数:31,代码来源:main.cpp

示例3: derive

result_t SingleDataField::derive(string name, string comment,
		string unit, const PartType partType,
		int divisor, map<unsigned int, string> values,
		vector<SingleDataField*>& fields)
{
	if (m_partType != pt_any && partType == pt_any)
		return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
	bool numeric = m_dataType->isNumeric();
	if (!numeric && (divisor != 0 || !values.empty()))
		return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for non-numeric field
	if (name.empty())
		name = m_name;
	if (comment.empty())
		comment = m_comment;
	if (unit.empty())
		unit = m_unit;
	DataType* dataType = m_dataType;
	if (numeric) {
		NumberDataType* numType = (NumberDataType*)m_dataType;
		result_t result = numType->derive(divisor, 0, numType);
		if (result != RESULT_OK)
			return result;
		dataType = numType;
	}
	if (values.empty()) {
		fields.push_back(new SingleDataField(name, comment, unit, dataType, partType, m_length));
	} else {
		fields.push_back(new ValueListDataField(name, comment, unit, (NumberDataType*)dataType, partType, m_length, values));
	}
	return RESULT_OK;
}
开发者ID:john30,项目名称:ebusd,代码行数:31,代码来源:data.cpp

示例4: if

  VecX<T>& operator+=(VecX<T> const &a) {
    if (a.data.empty() && a.px.empty()) return *this;
    rank = rank < a.rank ? a.rank : rank;  
     if (!px.empty() && !a.px.empty()) {
       for (it_cmap it=a.px.begin(); it!=a.px.end(); ++it) {
	 if (px[it->first] + it->second == 0) continue;
	 px[it->first] = px[it->first] + it->second;
       }
    } else if(!px.empty()) {
      data = a.data; 
      for (it_cmap it=px.begin(); it!=px.end(); ++it) 
	data[it->first] = data[it->first] + it->second;
      px.clear(); 
    } else if(!a.px.empty()) {
      if (!data.empty()) {
	for (it_cmap it=a.px.begin(); it!=a.px.end(); ++it)
	  data[it->first] = data[it->first] + it->second; 
      } else {
	px = a.px; 
      }	
    } else {
      if (!data.empty()) {
	for (int i=0; i<rank; ++i)
	  data[i] = data[i] + a.data[i];      
      } else {
	data = a.data; 
      }
    }
    return *this; 
  }
开发者ID:girdap,项目名称:girdap,代码行数:30,代码来源:VecX.hpp

示例5: info

 void info() {
   cout<<endl<<"--------------------------------"<<endl; 
   cout<<"      Rank:\t"<<rank<<endl; 
   cout<<"  Contains:\t"<<(!px.empty()?px.size():data.size())<<endl; 
   cout<<"Size(1 el):\t"<<sizeof(T)<<" bytes"<<endl;
   cout<<"Total size:\t~"<<data.size()*sizeof(typename vector<T>::value_type) + px.size()*sizeof(typename map<int_8,T>::value_type)<<" bytes"<<endl;
   cout<<"Compressed:\t"<<(!px.empty()?"Yes":"No")<<endl; 
   if (!px.empty()) cout<<"     Dense:\t"<<(double)px.size()/rank*100<<"%"<<endl; 
   cout<<"--------------------------------"<<endl; 
 }
开发者ID:girdap,项目名称:girdap,代码行数:10,代码来源:VecX.hpp

示例6: lderr

 ~SharedLRU() {
   contents.clear();
   lru.clear();
   if (!weak_refs.empty()) {
     lderr(cct) << "leaked refs:\n";
     dump_weak_refs(*_dout);
     *_dout << dendl;
     assert(weak_refs.empty());
   }
 }
开发者ID:jinghai,项目名称:ceph,代码行数:10,代码来源:shared_cache.hpp

示例7: main

int main() {
    long long int opern, value, temp, highest;
    char type[10];
    bool homo, hetro;
    cin>>opern;
    while (opern--) {
        scanf("%s %lld", type, &value);
        value += MOD;
        homo = false;
        hetro = false;
        if (type[0] == 'i') {
            data[value]++;
            temp = data[value];
            save[temp * FACT + value] = true;
            if (temp > 1) {
                save.erase((temp - 1) * FACT + value);
            }

        } else {
            if (data[value] > 0) {
                if (data[value] == 1) {
                    save.erase(FACT + value);
                    data.erase(value);
                } else {
                    data[value]--;
                    temp = data[value];
                    save[temp * FACT + value] = true;
                    save.erase((temp + 1) * FACT + value);
                }
            }
        }
        if (!save.empty() && !data.empty()) {
            highest = save.rbegin()->first;
            highest = highest / FACT;
        } else {
            highest = 0;
        }
        if (highest > 1) {
            homo = true;
        }
        if (save.size() > 1 && data.size() > 1) {
            hetro = true;
        }
        if (homo && hetro) {
            printf("both\n"); // << endl;
        } else if (homo && !hetro) {
            printf("homo\n");
        } else if (!homo && hetro) {
            printf("hetero\n");
        } else {
            printf("neither\n");
        }
    }
    return 0;
}
开发者ID:rakeshkaundilya,项目名称:SPOJ,代码行数:55,代码来源:HOMO.cpp

示例8: adjust

 void adjust(map<int, int>& small, int& ns, map<int, int>& large, int& nl) {
     if(small.empty() || large.empty()) return;
     int s = small.rbegin()->first;
     int l = large.begin()->first;
     if(s > l) {
         del(small, s);
         del(large, l);
         small[l]++;
         large[s]++;
     }
 }
开发者ID:HaochenLiu,项目名称:My-LintCode-CPP,代码行数:11,代码来源:360-map.cpp

示例9: write

void CsvWriter::write(ostream & output, map<int, list<Rule> > rules) {
    // write header
	if (rules.empty()) return;
	map<string, string>::iterator at;
	for (at=rules.begin()->second.front().attributes.begin(); at!=rules.begin()->second.front().attributes.end(); ++at) {
		output << at->first << ";";		
	}
	output << rules.begin()->second.front().class_attribute.second << endl;

	map<int, list<Rule> >::iterator im;
	for (im=rules.begin(); im!=rules.end(); ++im) {
		list<Rule>::iterator ir;
		for (ir=im->second.begin(); ir!=im->second.end(); ++ir) {
            map<string, string>::iterator ia;
			for (ia=ir->attributes.begin(); ia!=ir->attributes.end(); ++ia) {
				if (ia->second!="") {
					output << ia->second;
				}
				output << ";";
			}
			output << ir->decision;
			output << endl;
		}
	}
    
    output.flush();
}
开发者ID:piotrdubiel,项目名称:c-charm,代码行数:27,代码来源:csv_writer.cpp

示例10: initIconCodePoints

const vector<std::string> &TulipMaterialDesignIcons::getSupportedIcons() {
  if (iconCodePoint.empty()) {
    initIconCodePoints();
  }

  return iconsNames;
}
开发者ID:tulip5,项目名称:tulip,代码行数:7,代码来源:TulipMaterialDesignIcons.cpp

示例11: ParseAttachment

GLenum LuaFBOs::ParseAttachment(const string& name)
{
	static map<string, GLenum> attachMap;
	if (attachMap.empty()) {
		attachMap["depth"]   = GL_DEPTH_ATTACHMENT_EXT; 
		attachMap["stencil"] = GL_STENCIL_ATTACHMENT_EXT;
		attachMap["color0"]  = GL_COLOR_ATTACHMENT0_EXT;
		attachMap["color1"]  = GL_COLOR_ATTACHMENT1_EXT;
		attachMap["color2"]  = GL_COLOR_ATTACHMENT2_EXT;
		attachMap["color3"]  = GL_COLOR_ATTACHMENT3_EXT;
		attachMap["color4"]  = GL_COLOR_ATTACHMENT4_EXT;
		attachMap["color5"]  = GL_COLOR_ATTACHMENT5_EXT;
		attachMap["color6"]  = GL_COLOR_ATTACHMENT6_EXT;
		attachMap["color7"]  = GL_COLOR_ATTACHMENT7_EXT;
		attachMap["color8"]  = GL_COLOR_ATTACHMENT8_EXT;
		attachMap["color9"]  = GL_COLOR_ATTACHMENT9_EXT;
		attachMap["color10"] = GL_COLOR_ATTACHMENT10_EXT;
		attachMap["color11"] = GL_COLOR_ATTACHMENT11_EXT;
		attachMap["color12"] = GL_COLOR_ATTACHMENT12_EXT;
		attachMap["color13"] = GL_COLOR_ATTACHMENT13_EXT;
		attachMap["color14"] = GL_COLOR_ATTACHMENT14_EXT;
		attachMap["color15"] = GL_COLOR_ATTACHMENT15_EXT;
	}
	map<string, GLenum>::const_iterator it = attachMap.find(name);
	if (it != attachMap.end()) {
		return it->second;
	}
	return 0;
}
开发者ID:9heart,项目名称:spring,代码行数:29,代码来源:LuaFBOs.cpp

示例12: labelYOrderedPoints

void Grapher::labelYOrderedPoints(map<float, float> const& _data, int _maxCount, float _minFactor) const
{
	int ly = active.top() + 6;
	int pc = 0;
	if (_data.empty())
		return;
	float smallestAllowed = prev(_data.end())->first * _minFactor;
	BOOST_REVERSE_FOREACH (auto peak, _data)
		if ((peak.first > smallestAllowed || _minFactor == 0) && pc < _maxCount)
		{
			int x = xTP(peak.second);
			int y = yTP(peak.first);
			p->setPen(QColor::fromHsvF(float(pc) / _maxCount, 1.f, 0.5f, 0.5f));
			p->drawEllipse(QPoint(x, y), 4, 4);
			p->drawLine(x, y - 4, x, ly + 6);
			QString f = QString::fromStdString(pLabel(xT(peak.second), yT(peak.first)));
			int fw = p->fontMetrics().width(f);
			p->drawLine(x + 16 + fw + 2, ly + 6, x, ly + 6);
			p->setPen(QColor::fromHsvF(0, 0.f, .35f));
			p->fillRect(QRect(x+12, ly-6, fw + 8, 12), QBrush(QColor(255, 255, 255, 160)));
			p->drawText(QRect(x+16, ly-6, 160, 12), Qt::AlignVCenter, f);
			ly += 14;
			++pc;
		}
}
开发者ID:LancasterLogRes,项目名称:Noted,代码行数:25,代码来源:Grapher.cpp

示例13: isIconSupported

bool TulipMaterialDesignIcons::isIconSupported(const std::string &iconName) {
  if (iconCodePoint.empty()) {
    initIconCodePoints();
  }

  return iconCodePoint.find(iconName.c_str()) != iconCodePoint.end();
}
开发者ID:tulip5,项目名称:tulip,代码行数:7,代码来源:TulipMaterialDesignIcons.cpp

示例14: forbidden

ll forbidden(ll n) {
    if (n <  4) return 0;
    if (n <  9) return 1;
    if (n < 13) return 2;
    static map<ll,ll> memo;
    if (memo.empty()) {
        ll p = 1;
        ll q = 0;
        while (0 < p) {
            memo[p] = q;
            q = 8*q + 2*p;
            p *= 10;
        }
    }
    if (memo.count(n)) return memo[n];
    ll m = floor_log(n);
    ll a = n / m;
    ll b = n - a * m;
    ll result = 0;
    for (auto i : range(a)) {
        result += (i == 4 or i == 9) ? m : forbidden(m);
    }
    result += (a == 4 or a == 9) ? b+1 : forbidden(b);
    return memo[n] = result;
}
开发者ID:kmyk,项目名称:competitive-programming-workspace,代码行数:25,代码来源:a.cpp

示例15: InitEntities

static void InitEntities()
{
	if( !g_mapEntitiesToChars.empty() )
		return;

	static struct Entity
	{
		char c;
		const char *pEntity;
	}
	const EntityTable[] =
	{
		{ '&',  "amp", },
		{ '\"', "quot", },
		{ '\'', "apos", },
		{ '<',  "lt", },
		{ '>',  "gt", } 
	};

	for( unsigned i = 0; i < ARRAYLEN(EntityTable); ++i )
	{
		const Entity &ent = EntityTable[i];
		g_mapEntitiesToChars[ent.pEntity] = RString(1, ent.c);
		g_mapCharsToEntities[ent.c] = ent.pEntity;
	}
}
开发者ID:AratnitY,项目名称:stepmania,代码行数:26,代码来源:XmlFileUtil.cpp


注:本文中的map::empty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。