本文整理汇总了C++中std::invalid_argument方法的典型用法代码示例。如果您正苦于以下问题:C++ std::invalid_argument方法的具体用法?C++ std::invalid_argument怎么用?C++ std::invalid_argument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std
的用法示例。
在下文中一共展示了std::invalid_argument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Load
void CTexture::Load(GLenum iformat, int width, int height, GLubyte *pixels)
{
GLenum format;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //GL_LINEAR
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
if (iformat == GL_RGB8) {
format = GL_RGB;
}
else if (iformat == GL_RGBA8) {
format = GL_RGBA;
}
else {
throw invalid_argument("CTexture::Load - Unknown internal format");
}
//glTexImage2D(GL_TEXTURE_2D, 0, iformat, width, height, 0, format, GL_UNSIGNED_BYTE, pixels);
gluBuild2DMipmaps(GL_TEXTURE_2D, iformat, width, height, format, GL_UNSIGNED_BYTE, pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
w = width;
h = height;
bpp = 4;
}
示例2: invalid_argument
void bmp::bitmap_info_header::read_from_file(ifstream & file) {
file.read(reinterpret_cast<char *>(this), sizeof(bitmap_info_header));
if (header_size != sizeof(bitmap_info_header) || bpp != true_color_bpp_ ||
compression != BI_RGB) {
throw invalid_argument("unsupported file format");
}
}
示例3: set_comp
const void Node::set_comp(const string &comp_type){
if(string_util::starts_with(comp_type,"NONE")){
__comp_type=COMP_NONE;
}else if(string_util::starts_with(comp_type,"LZW")){
__comp_type=COMP_LZW;
}else if(string_util::starts_with(comp_type,"RLE")){
__comp_type=COMP_RLE;
}else if(string_util::starts_with(comp_type,"HUF")){
__comp_type=COMP_HUF;
}else{
throw invalid_argument("Do not understand compression type: "+comp_type);
}
// work with user specified dimension information
vector<string> temp=string_util::split(comp_type,":");
if(temp.size()==2){
__comp_buffer_dims=string_util::str_to_intVec(*(temp.rbegin()));
}
// use default if anything is wrong
if(__comp_buffer_dims.size()!=__dims.size()){
__comp_buffer_dims=__dims;
for( size_t i=0 ; i<__comp_buffer_dims.size()-1 ; ++i ){
__comp_buffer_dims[i]=1;
}
}
}
示例4: get
string HeaderGroup::get(const string& key) const {
auto index = indexOf(key);
if (index == _keys.size()) {
throw invalid_argument("key not found");
}
return _vals[index];
}
示例5: invalid_argument
void
Serial::SerialImpl::open ()
{
if (port_.empty ()) {
throw invalid_argument ("Empty port is invalid.");
}
if (is_open_ == true) {
throw SerialExecption ("Serial port already open.");
}
fd_ = CreateFile(port_.c_str(),
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (fd_ == INVALID_HANDLE_VALUE) {
DWORD errno_ = GetLastError();
stringstream ss;
switch (errno_) {
case ERROR_FILE_NOT_FOUND:
ss << "Specified port, " << port_ << ", does not exist.";
THROW (IOException, ss.str().c_str());
default:
ss << "Unknown error opening the serial port: " << errno;
THROW (IOException, ss.str().c_str());
}
}
reconfigurePort();
is_open_ = true;
}
示例6: setFromBinary
void MacAddress::setFromBinary(ByteRange value) {
if (value.size() != SIZE) {
throw invalid_argument(to<string>("MAC address must be 6 bytes "
"long, got ", value.size()));
}
memcpy(bytes_ + 2, value.begin(), SIZE);
}
示例7: main
int main(int argc, char **argv)
{
using std::invalid_argument;
using std::string;
// Open the log file
printf("Monte Carlo Estimate Pi (with batch QRNG)\n");
printf("=========================================\n\n");
// If help flag is set, display help and exit immediately
if (checkCmdLineFlag(argc, (const char **)argv, "help"))
{
printf("Displaying help on console\n");
showHelp(argc, (const char **)argv);
exit(EXIT_SUCCESS);
}
// Check the precision (checked against the device capability later)
try
{
char *value;
if (getCmdLineArgumentString(argc, (const char **)argv, "precision", &value))
{
// Check requested precision is valid
string prec(value);
if (prec.compare("single") == 0 || prec.compare("\"single\"") == 0)
{
runTest<float>(argc, (const char **)argv);
}
else if (prec.compare("double") == 0 || prec.compare("\"double\"") == 0)
{
runTest<double>(argc, (const char **)argv);
}
else
{
printf("specified precision (%s) is invalid, must be \"single\".\n", value);
throw invalid_argument("precision");
}
}
else
{
runTest<float>(argc, (const char **)argv);
}
}
catch (invalid_argument &e)
{
printf("invalid command line argument (%s)\n", e.what());
}
// Finish
// cudaDeviceReset causes the driver to clean up all state. While
// not mandatory in normal operation, it is good practice. It is also
// needed to ensure correct operation when the application is being
// profiled. Calling cudaDeviceReset causes all profile data to be
// flushed before the application exits
cudaDeviceReset();
exit(EXIT_SUCCESS);
}
示例8: command_parser
/**
* Fuction parses location command from .xml configuration file.
* Command can be of the form letter or letter:variable_name.
* It does all the checkins for correctness of the command. There are
* only three letters allowed "A", "I", "S". Only in case of letter "S"(single label),
* variable_name parameter can be in the location.
* Parameters: input - string location(command)
* output - char* key,
* Returns: 0 in case of A letter, 1 in case of S letter,
* 2 in case of L letter.
* In case of any other labels error will occur.
*/
int command_parser(const string &location, char* key){
int if_label=0; //initialization of flag
int size = location.size(); //check size of command string
//
//location cannot be empty
//
if(size<=0)
throw invalid_argument(" cannot parse empty string ");
//
//label only of the form A(all paramters from header) S:key(value for the given key is saved)
// or I(only image saved)
//
if(location[0]!='A' && location[0]!='S' && location[0]!='I')
throw invalid_argument(" bad location parameter only A , I or S:key are allowed ");
//
//check syntax for All keys and Image location(only letter A or I allowed)
//
if(location[0]=='A' || location[0]=='I'){
if(size!=1)
throw invalid_argument(" for all only A for image only I ");
}
//
//check syntax for Single key location(syntax-> S:key)
//
if(location[0]=='S'){
if(size<3 || location[1]!=DELIMITER)
throw invalid_argument(" Bad syntax. Correct syntax: S:key ");
}
//
//case for Single key
//
if(location[0]=='S'){
for(int i=2; i<size; i++){
key[i-2]=location[i];//subscribe key
}
key[size-2]='\0';
if_label=1;
}
//
//case for Image
//
if(location[0]=='I'){
if_label=2;
}
return if_label; //returns 2 for Image, 1 for Single key, 0 All
}
示例9: Generate
/////////////////////////////////////////////
// You should not need to modify this
/////////////////////////////////////////////
Sampler* SamplerPrototype::Generate(const vector<string>& SamplerString)
{
string type = CLParser::FindArgument<string>(SamplerString, CLArg::SamplerType) ;
map<string, Sampler*>::iterator it = exemplars.find(type) ;
if (it==exemplars.end()) throw invalid_argument("Unknown sampler type") ;
return it->second->GenSampler(SamplerString) ;
}
示例10: make_deal
void Corporation::make_deal(unsigned int day, unsigned int month, unsigned int year, string name, initializer_list<string> numbers) {
if (year >= foundation_year && year <= Corporation::current_year && month >= 2 && month <= 12 && day >= 1 && day <= 31) {
deals.push_back(deal(day, month, year, name, numbers));
}
else {
throw invalid_argument("In Corporation::make_deal(unsigned int, unsigned int, unsigned int, string, initializer_list<string>): wrong data.");
}
}
示例11: operator
double Matrix::operator()( const unsigned int row, const unsigned int column ) const
{
if( row >= rows || column >= columns )
{
throw invalid_argument( "Row/Column exceeds matrix dimensions" );
}
return elements[row][column];
}
示例12: invalid_argument
ContainerType &ParseFrame::prev(size_t idx)
{
LOG_FUNC_ENTRY();
if (idx == 0)
{
throw invalid_argument(string(__FILE__) + ":" + to_string(__LINE__)
+ " idx can't be zero");
}
if (idx >= pse.size())
{
LOG_FMT(LINDPSE, "%s(%d): idx is %zu, size is %zu\n",
__func__, __LINE__, idx, pse.size());
throw invalid_argument(string(__FILE__) + ":" + to_string(__LINE__)
+ " idx can't be >= size()");
}
return(*std::prev(std::end(pse), idx + 1));
}
示例13: invalid_argument
Location::Location(int x, int y, string name, vector<Item const *> items, vector<Character> characters) :
xPosition_(x),
yPosition_(y),
name_(name),
items_(items),
characters_(characters) {
if (x < 0 || y < 0) {
throw invalid_argument("Can't have negative coordinate (Just coz)");
}
}
示例14: int_to_bin
// Converts an integer to a string that represents that integer in binary form.
// len is the length of the string to return.
// Example: int_to_bin(5, 4) = "0101".
string int_to_bin (int n, int len) {
if (n >= pow(2, len)) throw invalid_argument("len is too small");
string str;
for (int i = 0; i < len; i++) {
str += get_bit(n, len - i - 1) + '0';
}
return str;
}
示例15: invalid_argument
QMap<QChar, QString>
PlayerCommandParser::extractArgs( const QString& line )
{
QMap<QChar, QString> map;
// split by single & only, doubles are in fact &
foreach (Pair pair, mxcl::split( line ))
{
if (pair.key == QChar())
throw invalid_argument( "Invalid pair: " + pair.key.toAscii() + '=' + std::string(pair.value.toUtf8().data()) );
if (map.contains( pair.key ))
throw invalid_argument( "Field identifier occurred twice in request: " + pair.key.toAscii() );
map[pair.key] = pair.value.trimmed();
}
return map;
}