コード例 #1
0
ファイル: ObjLoader.cpp プロジェクト: Lexicality/techdemo
bool ObjLoader::ReadVertex(const FaceMode& mode, const VertexData& verts, const size_t index) {
    if (file.fail()) {
        std::cout << "wtf?";
    }
    while(true) {
        char c;
        file.get(c);
        if (whitespace(c))
            continue;
        file.unget();
        if (file.fail()) {
            std::cout << "wtf?";
        }
        if (newline(c))
            return false;
        break;
    }

    verts.positions[index] = readindex(positionCount);
    if (mode.PositionsOnly)
        return true;
    file.ignore(1);
    if (!mode.NoTextures)
        verts.textures[index] = readindex(textureCount);
    if (!mode.NoNormalSlash)
        file.ignore(1);
    if (!mode.NoNormals)
        verts.normals[index] = readindex(normalCount);
    return true;
}
コード例 #2
0
ファイル: readfile.cpp プロジェクト: kevinpamplona/raytracer
// helper function to read input data files
bool readVals(std::stringstream &s, const int numvals, float * values) {
    for (int i = 0 ; i < numvals ; i++) {
        s >> values[i] ;
        if (s.fail()) {
            std::cout << "Failed reading value " << i << " will skip\n" ;
            return false ;
        }
    }
    return true ; 
}
コード例 #3
0
bool readvals(std::stringstream &s, const int numvals, std::vector<float> &values) {
    for (int i = 0; i < numvals; i++) {
        float f;
        s >> f; 
        if (s.fail()) {
            //cout << "Failed reading value " << i << " will skip\n"; 
            return false;
        }
        values.push_back(f);
    }
    return true; 
}
コード例 #4
0
void
print_stderr(std::stringstream& aStr)
{
#if defined(ANDROID)
  // On Android logcat output is truncated to 1024 chars per line, and
  // we usually use std::stringstream to build up giant multi-line gobs
  // of output. So to avoid the truncation we find the newlines and
  // print the lines individually.
  char line[1024];
  while (!aStr.eof()) {
    aStr.getline(line, sizeof(line));
    if (!aStr.eof() || strlen(line) > 0) {
      printf_stderr("%s\n", line);
    }
    if (aStr.fail()) {
      // line was too long, skip to next newline
      aStr.clear();
      aStr.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    }
  }
#else
  printf_stderr("%s", aStr.str().c_str());
#endif
}
コード例 #5
0
ファイル: math_parser.cpp プロジェクト: cubuspl42/romberg
std::vector<Element> parse_expression(std::stringstream &stream) {
    std::vector<Element> out_buffer;
    std::stack<Element> st;
    while(stream.good()) {
        char c = stream.peek();
        assert(!stream.fail());
        if(c == ')' || c == ']') {
            stream.get();
            while (1) {
                assert(!st.empty());
                Element element = st.top();
                st.pop();
                if(element.type == Element::Type::BRACKET) {
                    break;
                } else {
                    out_buffer.push_back(convert_operator(element));
                }
            }
            if(!st.empty() && st.top().type == Element::Type::FUNCTION) {
                out_buffer.push_back(st.top());
                st.pop();
            }
        } else if(c == '(' || c == '[') {
            stream.get();
            Element element { Element::Type::BRACKET };
#ifdef DEBUG_MATH_PARSER
            element.identifier = "(";
#endif
            st.push(element);
        } else if(isalpha(c)) {
            Element element;
            std::string id = parse_identifier(stream);
#ifdef DEBUG_MATH_PARSER
            element.identifier = id;
#endif
            if(function_info.find(id) != function_info.end()) {
                element.type = Element::Type::FUNCTION;
                element.function = function_info[id];
                st.push(element);
            } else {
                assert(id.length() == 1);
                element.type = Element::Type::VARIABLE;
                element.variable = id[0];
                out_buffer.push_back(element);
            }
        } else if(isnumber(c)) {
            Element element { Element::Type::SCALAR };
            stream >> element.scalar;
            out_buffer.push_back(element);
        } else if(operator_info.find(c) != operator_info.end()) {
            Element current { Element::Type::OPERATOR };
#ifdef DEBUG_MATH_PARSER
            current.identifier = std::string(1, c);
#endif
            current.op = operator_info[stream.get()];
            while(!st.empty() && st.top().type == Element::Type::OPERATOR &&
                  st.top().op.precedence + st.top().op.rtl_associativity <= current.op.precedence) {
                out_buffer.push_back(convert_operator(st.top()));
                st.pop();
            }
            st.push(current);
        } else if(isspace(c)) {
            stream.get();
        }
    }