2013-02-13 16 views
7

का उपयोग करके मैं अपने सिर को बूस्ट वेव के आसपास लाने की कोशिश कर रहा हूं, और अब तक, मुझे बहुत भाग्य नहीं है।बूस्ट वेव

मैंने साइट से नमूना कोड की कोशिश की। यह नीचे है:

#include <iostream> 
#include <iomanip> 
#include <fstream> 
#include <string> 
#include <vector> 

/////////////////////////////////////////////////////////////////////////////// 
// Include Wave itself 
#include <boost/wave.hpp> 

/////////////////////////////////////////////////////////////////////////////// 
// Include the lexer stuff 
#include <boost/wave/cpplexer/cpp_lex_token.hpp> // token class 
#include <boost/wave/cpplexer/cpp_lex_iterator.hpp> // lexer class 

int main() { 
    // The following preprocesses a given input file. 
    // Open the file and read it into a string variable 
    std::ifstream instream("lex_infile"); 
    std::string input(
     std::istreambuf_iterator<char>(instream.rdbuf()), 
     std::istreambuf_iterator<char>()); 

    // The template boost::wave::cpplexer::lex_token<> is the 
    // token type to be used by the Wave library. 
    // This token type is one of the central types throughout 
    // the library, because it is a template parameter to some 
    // of the public classes and templates and it is returned 
    // from the iterators. 
    // The template boost::wave::cpplexer::lex_iterator<> is 
    // the lexer iterator to use as the token source for the 
    // preprocessing engine. In this case this is parametrized 
    // with the token type. 
    typedef boost::wave::cpplexer::lex_iterator< 
      boost::wave::cpplexer::lex_token<> > 
     lex_iterator_type; 
    typedef boost::wave::context< 
      std::string::iterator, lex_iterator_type> 
     context_type; 

    context_type ctx(input.begin(), input.end(), "lex_infile"); 

    // At this point you may want to set the parameters of the 
    // preprocessing as include paths and/or predefined macros. 
     //ctx.add_include_path("..."); 
     //ctx.add_macro_definition(...); 

    // Get the preprocessor iterators and use them to generate 
    // the token sequence. 
    context_type::iterator_type first = ctx.begin(); 
    context_type::iterator_type last = ctx.end(); 

    std::cout << "HERE" << std::endl; 

    // The input stream is preprocessed for you during iteration 
    // over [first, last) 
     while (first != last) { 
      std::cout << (*first).get_value() << std::endl; 
      ++first; 
     } 
} 

ठीक संकलित, लेकिन जब मैं इसे में एक फ़ाइल को खिलाने, मैं निम्नलिखित त्रुटि मिलती है:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl >'
what(): boost::wave::preprocess_exception
Aborted

कोड मैं 'preprocess' के लिए कोशिश कर रहा हूँ एक में है फ़ाइल lex_infile, निम्नलिखित सामग्री के साथ कहा जाता है:

#include <oglre> 
#include <light> 
#include <material> 

in vec3 in_Position; 
in vec2 in_Texture; 
in vec3 in_Normal; 

out vec2 textureCoord; 
out vec4 pass_Color; 




void main() { 
    gl_Position = pvmMatrix * vec4(in_Position, 1.0); 

    textureCoord = in_Texture; 


    vec3 normalDirection = normalize(normalMatrix * in_Normal); 
    vec3 lightDirection = normalize(vec3(lightSources[0].direction)); 

    vec3 diffuseReflection = vec3(lightSources[0].diffuse) * vec3(mymaterial.diffuse) * max(0.0, dot(normalDirection, lightDirection)); 

    /* 
    float bug = 0.0; 
    bvec3 result = equal(diffuseReflection, vec3(0.0, 0.0, 0.0)); 
    if(result[0]) bug = 1.0; 

    diffuseReflection.x += bug; 
    */ 

    pass_Color = vec4(diffuseReflection, 1.0); 
} 

मैं कल्पना मैं स्थानों में शामिल हैं परिभाषित करने की जरूरत .... मैं कैसे भी है कि क्या करेंगे?

क्षमा करें अगर यह आसान सामान है, तो मैं थोड़ा सा खो गया हूं।

उत्तर

7

यह पता लगाया।

मुझे कक्षा public wave::context_policies::default_preprocessing_hooks कक्षा का विस्तार करने की आवश्यकता है, और उसके बाद विधि found_unknown_directive ओवरराइड करें।

एक बार ऐसा करने के बाद, मुझे टेम्पलेट पैरामीटर के रूप में typedef boost::wave::context में अपनी नई प्रीप्रोकैसिंग हुक कक्षा को पास करने की आवश्यकता थी।

यह इस तरह दिखता है:

typedef boost::wave::context< 
       std::string::iterator, 
       lex_iterator_type, 
       load_file_to_string, 
       custom_directives_hooks 
      > context_type; 

और

class custom_directives_hooks 
: public wave::context_policies::default_preprocessing_hooks 
{ 
public: 

    template <typename ContextT, typename ContainerT> 
    bool 
    found_unknown_directive(ContextT const& ctx, ContainerT const& line, 
     ContainerT& pending) 
    { 
     typedef typename ContainerT::const_iterator iterator_type; 
     iterator_type it = line.begin(); 
     wave::token_id id = wave::util::impl::skip_whitespace(it, line.end()); 

     if (id != wave::T_IDENTIFIER) 
      return false;  // nothing we could do 

     if (it->get_value() == "version" || it->get_value() == "extension") { 
      // Handle #version and #extension directives 
      std::copy(line.begin(), line.end(), std::back_inserter(pending)); 
      return true; 
     } 

     if (it->get_value() == "type") { 
      // Handle type directive 
      return true; 
     } 

     // Unknown directive 
     return false; 
    } 
}; 

आशा किसी और इस समस्या हो रही मदद करता है।