/ / बूस्ट स्ट्रिंग इन स्ट्रक्चर इन बूस्ट स्पिरिट

बूस्ट भावना के साथ संरचना में पार्स स्ट्रिंग - बूस्ट, बूस्ट-स्पिरिट, स्ट्रिंग-पार्सिंग, बूस्ट-स्पिरिट-क्यूई, बूस्ट-फ़्यूज़न

मेरे पास निम्नलिखित कोड हैं जो मुझे एक स्ट्रिंग को पार्स करने की आवश्यकता है और इसे निम्न रूप से परिभाषित संरचना में ले जाना चाहिए:

#include "boostspiritincludeclassic.hpp"
#include "boostspiritincludeqi.hpp"
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/io.hpp>
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#include <regex>
#include <string>
#include <boostchrono.hpp>
#include <ctype.h>
#include <iostream>

struct my_struct
{
std::string s1;
std::string s2;
std::string s3;
std::string s4;
std::string s5;
std::string s6;
std::string s7;
std::string s8;
std::string s9;
std::string s10;
std::string s11;
};

BOOST_FUSION_ADAPT_STRUCT(
my_struct,
(std::string, s1 )
(std::string, s2 )
(std::string, s3 )
(std::string, s4 )
(std::string, s5 )
(std::string, s6 )
(std::string, s7 )
(std::string, s8 )
(std::string, s9 )
(std::string, s10)
(std::string, s11)
)

मेरा व्याकरण यह है:

template <typename Iterator>
struct my_struct_parser : qi::grammar<Iterator, my_struct(), ascii::space_type>
{
my_struct_parser() : my_struct_parser::base_type(start)
{
using ascii::char_;
using qi::digit;
using qi::alpha;

start %=
qi::alpha>>"-"
>>qi::repeat(9)[digit]>>"-"
>>+(digit)>>"-"
>>+(digit)>>"-"
>>+(digit)>>"-"
>>qi::repeat(5)[digit]>>"-"
>>+char_("a-zA-Z")>>"-"
>>qi::repeat(2)[digit]>>"-"
>>+(digit)>>"-"
>>+(digit)>>"-"
>>+(qi::alpha)

>>-("-">>+(char_("a-zA-Z0-9@$")));
}
qi::rule<Iterator, my_struct(), ascii::space_type> start;
};

और फिर मैं कोड की इन पंक्तियों का उपयोग करके अपने तार को पार्स करता हूं:

       my_struct & emp;//this is passed as an argument to a function
typedef my_struct_parser<iterator_type> my_struct_parser_type;
my_struct_parser_type parser;
std::string::const_iterator iter = filename.begin();
std::string::const_iterator end = filename.end();
bool r =
boost::spirit::qi::phrase_parse(iter, end,parser,boost::spirit::ascii::space ,emp);

ठीक है, समस्या मेरी कोड ठीक है जब मेरी संरचना में 10 फ़ील्ड या उससे कम हैं, लेकिन यह त्रुटि देता है जब मेरे पास संरचना में अधिक फ़ील्ड हैं , इसलिए मैंने अनुमान लगाया कि यह पैरामीटर के कारण था SPIRIT_ARGUMENTS_LIMIT क्योंकि इसका डिफ़ॉल्ट मान 10 है।

मैं इस पैरामीटर को उस आकार को परिभाषित करने की कोशिश करता हूं जिसकी मैं इच्छा करता हूं इससे पहले कि मैं स्पिरिट हेडर फाइलें शामिल करूं लेकिन मुझे अभी भी संकलन त्रुटियां हैं

मुझे इस समस्या को कैसे हल करना चाहिए?

उत्तर:

उत्तर № 1 के लिए 7

यदि आप जांचते हैं कि कंपाइलर किस बारे में शिकायत करता है, तो आपको कुछ इस तरह दिखाई देगा:

....
/usr/include/boost/fusion/container/vector/convert.hpp:26:13: error: invalid use of incomplete type ‘struct boost::fusion::detail::as_vector<12>’
....
/usr/include/boost/fusion/container/vector/detail/as_vector.hpp:26:12: error: declaration of ‘struct boost::fusion::detail::as_vector<12>’

मैं कुछ समय पहले भी इस समस्या में भाग गया था। यदि आपकी संरचना में 10 से अधिक फ़ील्ड हैं आपको फिर से परिभाषित करने की आवश्यकता है FUSION_MAX_VECTOR_SIZE साथ ही फ्यूजन कंटेनर (एस) मेल्टेड विशेषताओं को एकत्र करता है।

http://www.boost.org/doc/libs/1_52_0/libs/fusion/doc/html/fusion/container/vector.html http://www.boost.org/doc/libs/1_52_0/libs/spirit/doc/html/spirit/qi/quick_reference/compound_attribute_rules.html

अन्य डिफ़ॉल्ट फ़ाइलों को उनके डिफ़ॉल्ट मानों को ओवरराइड करने के लिए फ़ाइलों को शामिल करने से पहले मैं इन दो परिभाषित का उपयोग करूंगा:

#define FUSION_MAX_VECTOR_SIZE      20
#define SPIRIT_ARGUMENTS_LIMIT      20