コード例 #1
1
ファイル: Texture.cpp プロジェクト: AntonBogomolov/Models
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
0
ファイル: bmp.cpp プロジェクト: cwang100/class-projects
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
0
ファイル: node.cpp プロジェクト: Acidburn0zzz/code
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
0
ファイル: header_group.cpp プロジェクト: idgetto/rah-milk
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
0
ファイル: win.cpp プロジェクト: byteman/finger
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
0
ファイル: MacAddress.cpp プロジェクト: lamoreauxdy/coral
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
0
ファイル: main.cpp プロジェクト: chengli1986/571e
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
0
ファイル: edf_retriever.cpp プロジェクト: Acidburn0zzz/code
/** 
* 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
0
ファイル: sampler.cpp プロジェクト: karticsubr/FAS2016
/////////////////////////////////////////////
// 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
0
ファイル: Corporation.cpp プロジェクト: a-pinch/andrewtroyan
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
0
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
0
ファイル: ParseFrame.cpp プロジェクト: paolodedios/uncrustify
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
0
ファイル: location.cpp プロジェクト: JoeCrouch/TextAdventure
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
0
ファイル: util.cpp プロジェクト: carriercomm/quantum-2
// 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
0
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;
}
コード例 #16
0
ファイル: ListAsArray.cpp プロジェクト: lbaby/codeGarden
Object& ListAsArray::operator [] (Position const& arg) const
{
    Pos const& position = dynamic_cast<Pos const&> (arg);
    #ifdef DPRINT
    std::cerr<< "pos @ operator [] (pos) : " << position.offset << std::endl;
    #endif
    if (&position.list != this || position.offset >= count)
	throw invalid_argument ("invalid position");
    return *array [position.offset];
}
コード例 #17
0
ファイル: scanner.cpp プロジェクト: sirjaren/utsushi
scanner::info::info (const std::string& udi)
  : udi_(udi)
{
  if (!is_valid (udi_))
    {
      BOOST_THROW_EXCEPTION
        (invalid_argument
         ((format (_("syntax error: invalid UDI '%1%'")) % udi_).str ()));
    }
}
コード例 #18
0
ファイル: bmp.cpp プロジェクト: clei5/CS233
bmp::bmp(int32_t width, int32_t height) {
	if (width < 0 || height < 0) {
		throw invalid_argument("width and height cannot be negative");
	}

	dib_header_.init(width, height);
	file_header_.init(dib_header_.data_size);
	pixel white = { 255, 255, 255 };
	pixels_.resize(width * height, white);
}
コード例 #19
0
void TrainableSvmClassifier::train() {
	param->weight[0] = getPositiveCount();
	param->weight[1] = getNegativeCount() + staticNegativeExamples.size();
	problem = move(createProblem());
	const char* message = svm_check_parameter(problem.get(), param.get());
	if (message != 0)
		throw invalid_argument(string("invalid SVM parameters: ") + message);
	model.reset(svm_train(problem.get(), param.get()));
	updateSvmParameters();
}
コード例 #20
0
OpcodeOnlyMessage::OpcodeOnlyMessage ( char* msg, int size, struct sockaddr_in& addr )
{
	if (msg == 0)
		throw invalid_argument("Null message was passed");

	this->size = size;
	this->rawMsg = msg;	// first byte of the message is the opcode
	this->addr = addr;
	this->opcode = (int)rawMsg[0];
}
コード例 #21
0
ファイル: retriever.cpp プロジェクト: Acidburn0zzz/code
/**
 * The factory will call the constructor with a string. The string
 * specifies where to locate the data (e.g. a filename), but
 * interpreting the string is left up to the implementing code.
 */
TextPlainRetriever::TextPlainRetriever(const string &str): source(str),current_line(0){
  //cout << "TextPlainRetriever(" << source << ")" << endl; // REMOVE

  // open the file
  infile.open(source.c_str());

  // check that open was successful
  if(!infile.is_open())
    throw invalid_argument("Could not open file: "+source);
}
コード例 #22
0
ファイル: main.cpp プロジェクト: Mandar-Shinde/Cuda
int main(int argc, char **argv)
{
    using std::invalid_argument;
    using std::string;

    // Open the log file
    printf("Monte Carlo Estimate Pi (with inline 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\" or \"double\".\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();
    exit(EXIT_SUCCESS);
}
コード例 #23
0
    merPredD::merPredD(SEXP X, SEXP Lambdat, SEXP LamtUt, SEXP Lind,
                       SEXP RZX, SEXP Ut, SEXP Utr, SEXP V, SEXP VtV,
                       SEXP Vtr, SEXP Xwts, SEXP Zt, SEXP beta0,
                       SEXP delb, SEXP delu, SEXP theta, SEXP u0)
        : d_X(       as<MMat>(X)),
          d_RZX(     as<MMat>(RZX)),
          d_V(       as<MMat>(V)),
          d_VtV(     as<MMat>(VtV)),
          d_Zt(      as<MSpMatrixd>(Zt)),
          d_Ut(      as<MSpMatrixd>(Ut)),
          d_LamtUt(  as<MSpMatrixd>(LamtUt)),
          d_Lambdat( as<MSpMatrixd>(Lambdat)),
          d_theta(   as<MVec>(theta)),
          d_Vtr(     as<MVec>(Vtr)),
          d_Utr(     as<MVec>(Utr)),
          d_Xwts(    as<MVec>(Xwts)),
          d_beta0(   as<MVec>(beta0)),
          d_delb(    as<MVec>(delb)),
          d_delu(    as<MVec>(delu)),
          d_u0(      as<MVec>(u0)),
          d_Lind(    as<MiVec>(Lind)),
          d_N(       d_X.rows()),
          d_p(       d_X.cols()),
          d_q(       d_Zt.rows()),
          d_RX(      d_p)
    {                           // Check consistency of dimensions
        if (d_N != d_Zt.cols())
            throw invalid_argument("Z dimension mismatch");
        if (d_Lind.size() != d_Lambdat.nonZeros())
            throw invalid_argument("size of Lind does not match nonzeros in Lambda");
        // checking of the range of Lind is now done in R code for reference class
                                // initialize beta0, u0, delb, delu and VtV
        d_VtV.setZero().selfadjointView<Eigen::Upper>().rankUpdate(d_V.adjoint());
        d_RX.compute(d_VtV);    // ensure d_RX is initialized even in the 0-column X case

        setTheta(d_theta);          // starting values into Lambda
        d_L.cholmod().final_ll = 1; // force an LL' decomposition
        updateLamtUt();
        d_L.analyzePattern(d_LamtUt * d_LamtUt.transpose()); // perform symbolic analysis
        if (d_L.info() != Eigen::Success)
            throw runtime_error("CholeskyDecomposition.analyzePattern failed");
    }
コード例 #24
0
// @include
string normalized_path_names(const string& path) {
  vector<string> s;  // Use vector as a stack.
  // Special case: starts with "/", which is an absolute path.
  if (path.front() == '/') {
    s.emplace_back("/");
  }

  stringstream ss(path);
  string token;
  while (getline(ss, token, '/')) {
    if (token == "..") {
      if (s.empty() || s.back() == "..") {
        s.emplace_back(token);
      } else {
        if (s.back() == "/") {
          throw invalid_argument("Path error");
        }
        s.pop_back();
      }
    } else if (token != "." && token != "") {  // name.
      for (const char& c : token) {
        if (c != '.' && !isalnum(c)) {
          throw invalid_argument("Invalid directory name");
        }
      }
      s.emplace_back(token);
    }
  }

  string normalized_path("");
  if (!s.empty()) {
    auto it = s.cbegin();
    normalized_path += *it++;
    while (it != s.cend()) {
      if (*(it - 1) != "/") {  // previous one is not an absolute path.
        normalized_path += "/";
      }
      normalized_path += *it++;
    }
  }
  return normalized_path;
}
コード例 #25
0
int main(int argc, char **argv)
{
    using std::invalid_argument;
    using std::string;

    // Open the log file
	shrQAStart(argc, argv);
    shrSetLogFileName(shrLogFile);
    shrLog("Monte Carlo Estimate Pi (with batch QRNG)\n");
    shrLog("=========================================\n\n");

    // If help flag is set, display help and exit immediately
    if (shrCheckCmdLineFlag(argc, (const char **)argv, "help"))
    {
        shrLog("Displaying help on console\n");
        showHelp(argc, (const char **)argv);
        shrQAFinishExit(argc, (const char **)argv, QA_PASSED);
    }

    // Check the precision (checked against the device capability later)
    try
    {
        char *value;
        if (shrGetCmdLineArgumentstr(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
            {
                shrLogEx(LOGBOTH | ERRORMSG, 0, "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)
    {
        shrLogEx(LOGBOTH | ERRORMSG, 0, "invalid command line argument (%s)\n", e.what());
        shrCheckErrorEX(false, true, NULL);
    }
    
    // Finish
    cutilDeviceReset();
    shrQAFinishExit(argc, (const char **)argv, QA_PASSED);
}
コード例 #26
0
const FilmActor& FilmsActors::GetRecord(int IDFilm, int IDActor) const
{
  FilmActor temp(IDFilm, 0);
  vector<FilmActor*> tmpfilms = _data.getAll<FilmActor*>(temp);
  for(auto i=0;i<tmpfilms.size();++i)
  {
    if(tmpfilms[i]->IDActor() == IDActor)
     return *(tmpfilms[i]); 
  }
  throw invalid_argument("Record does not exist.");
}
コード例 #27
0
double MatrixDeterminant( const Matrix& mat )
{
    if( !( mat.IsSquare() ) )
    {
        throw invalid_argument( "Matrix is not square" );
    }
    
    if( mat.rows == 1 )
    {
        //If matrix is 1x1, return the only value in the matrix;
        return mat( 0, 0 );
    }
    
    double det = 0.0f;
    int sign = 1;
    
    for( unsigned int i = 0; i < mat.columns; i++ )
    {
        double cofactor = ( mat( 0, i ) * sign );
        
        sign *= -1;
        
        //Build minor - (n-1)x(n-1) matrix
        Matrix _minor( ( mat.rows - 1 ), ( mat.columns - 1 ) );
        
        unsigned int rowIndex = 0, colIndex = 0; //These need better names
        
        for( unsigned int j = 0; j < mat.rows; j++ )
        {
            colIndex = 0;
            
            for( unsigned int k = 0; k < mat.columns; k++ )
            {   
                if( ( j != 0 ) && ( k != i ) )
                {
                    _minor( rowIndex, colIndex ) = mat( j, k );
                    colIndex++;
                    
                    if( colIndex >= _minor.columns )
                    {
                        rowIndex++;
                    }
                }
            }
        }
        
        //Get determinant of minor
        double detMinor = MatrixDeterminant( _minor );
        
        det += ( cofactor * detMinor );
    }
    
    return det;
}
コード例 #28
0
ファイル: ParseFrame.cpp プロジェクト: paolodedios/uncrustify
const ContainerType &ParseFrame::prev(size_t idx) const
{
   LOG_FUNC_ENTRY();

   if (idx == 0 || idx >= pse.size())
   {
      throw invalid_argument(string(__FILE__) + ":" + to_string(__LINE__)
                             + " idx can't be zero or >= size()");
   }
   return(*std::prev(std::end(pse), idx + 1));
}
コード例 #29
0
ファイル: bmp.cpp プロジェクト: clei5/CS233
void bmp::write_to_file(const string & file_name) {
	ofstream file(file_name.c_str(), ofstream::binary | ofstream::trunc);
	if (!file.is_open()) {
		throw invalid_argument("could not write to file " + file_name);
	}

	file.exceptions(ofstream::badbit | ofstream::failbit | ofstream::eofbit);
	file_header_.write_to_file(file);
	dib_header_.write_to_file(file);
	write_pixels_(file);
}
コード例 #30
0
ファイル: util.cpp プロジェクト: carriercomm/quantum-2
// Tests whether n is prime.
// This uses a naive algorithm that would be useless for numbers of substantial
// size, but is fine for the purposes of QAS, which are understanding and 
// simulating the use of quantum computing rather than actually solving 
// difficult problem instances. 
bool is_prime (int n) {
	if (n <= 1) throw invalid_argument("n must be greater than 1");

	// trial division
	for (int k = 2; k <= floor(sqrt(n)); k++) { 
		if (n % k == 0) { 
			return false; 
		}
	}
	return true; 
}