當前位置: 首頁>>代碼示例>>C++>>正文


C++ std::invalid_argument方法代碼示例

本文整理匯總了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;
}
開發者ID:AntonBogomolov,項目名稱:Models,代碼行數:25,代碼來源:Texture.cpp

示例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");
	}
}
開發者ID:cwang100,項目名稱:class-projects,代碼行數:7,代碼來源:bmp.cpp

示例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;
    }
  }
}
開發者ID:Acidburn0zzz,項目名稱:code,代碼行數:27,代碼來源:node.cpp

示例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];
}
開發者ID:idgetto,項目名稱:rah-milk,代碼行數:7,代碼來源:header_group.cpp

示例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;
}
開發者ID:byteman,項目名稱:finger,代碼行數:34,代碼來源:win.cpp

示例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);
}
開發者ID:lamoreauxdy,項目名稱:coral,代碼行數:7,代碼來源:MacAddress.cpp

示例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);
}
開發者ID:chengli1986,項目名稱:571e,代碼行數:60,代碼來源:main.cpp

示例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
}
開發者ID:Acidburn0zzz,項目名稱:code,代碼行數:59,代碼來源:edf_retriever.cpp

示例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) ;
}
開發者ID:karticsubr,項目名稱:FAS2016,代碼行數:11,代碼來源:sampler.cpp

示例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.");
    }
}
開發者ID:a-pinch,項目名稱:andrewtroyan,代碼行數:8,代碼來源:Corporation.cpp

示例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];
}
開發者ID:MrScottOliver,項目名稱:canned-engine,代碼行數:9,代碼來源:Matrix.cpp

示例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));
}
開發者ID:paolodedios,項目名稱:uncrustify,代碼行數:18,代碼來源:ParseFrame.cpp

示例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)");
    }
}
開發者ID:JoeCrouch,項目名稱:TextAdventure,代碼行數:10,代碼來源:location.cpp

示例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; 
}
開發者ID:carriercomm,項目名稱:quantum-2,代碼行數:13,代碼來源:util.cpp

示例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;
}
開發者ID:FerrerTNH,項目名稱:lastfm-desktop,代碼行數:19,代碼來源:PlayerCommandParser.cpp


注:本文中的std::invalid_argument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。