<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Weiqi Gao&#039;s Observations - boost tag</title>
  <link>http://www.weiqigao.com/blog/tags/boost/</link>
  <description>Sharing My Experience...</description>
  <language>en</language>
  <copyright>Weiqi Gao</copyright>
  <lastBuildDate>Fri, 11 May 2012 12:48:36 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  <image>
    <url>http://pebble.sourceforge.net/common/images/powered-by-pebble.gif</url>
    <title>Weiqi Gao&#039;s Observations</title>
    <link>http://www.weiqigao.com/blog/</link>
  </image>
  
  
  <item>
    <title>A Little C++ To Boost Your Spirit</title>
    <link>http://www.weiqigao.com/blog/2008/03/26/a_little_c_to_boost_your_spirit.html</link>
    
      
        <description>
          &lt;p&gt;Take a look at the following snippet of valid C++ code ...&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;&lt;span style=&#034;color:purple&#034;&gt;group&lt;/span&gt; = &lt;span style=&#034;color:green&#034;&gt;&#039;(&#039;&lt;/span&gt; &lt;span style=&#034;color:lightgray&#034;&gt;&gt;&gt;&lt;/span&gt; &lt;span style=&#034;color:purple&#034;&gt;expr&lt;/span&gt; &lt;span style=&#034;color:lightgray&#034;&gt;&gt;&gt;&lt;/span&gt; &lt;span style=&#034;color:green&#034;&gt;&#039;)&#039;&lt;/span&gt;;
&lt;span style=&#034;color:purple&#034;&gt;fact&lt;/span&gt; = &lt;span style=&#034;color:purple&#034;&gt;integer&lt;/span&gt; &lt;span style=&#034;color:red&#034;&gt;|&lt;/span&gt; &lt;span style=&#034;color:purple&#034;&gt;group&lt;/span&gt;;
&lt;span style=&#034;color:purple&#034;&gt;term&lt;/span&gt; = &lt;span style=&#034;color:purple&#034;&gt;fact&lt;/span&gt; &lt;span style=&#034;color:lightgray&#034;&gt;&gt;&gt;&lt;/span&gt; &lt;span style=&#034;color:red&#034;&gt;*( (&lt;/span&gt;&lt;span style=&#034;color:green&#034;&gt;&#039;*&#039;&lt;/span&gt; &lt;span style=&#034;color:lightgray&#034;&gt;&gt;&gt;&lt;/span&gt; &lt;span style=&#034;color:purple&#034;&gt;fact&lt;/span&gt;&lt;span style=&#034;color:red&#034;&gt;) | (&lt;/span&gt;&lt;span style=&#034;color:green&#034;&gt;&#039;/&#039;&lt;/span&gt; &lt;span style=&#034;color:lightgray&#034;&gt;&gt;&gt;&lt;/span&gt; &lt;span style=&#034;color:purple&#034;&gt;fact&lt;/span&gt;&lt;span style=&#034;color:red&#034;&gt;) )&lt;/span&gt;;
&lt;span style=&#034;color:purple&#034;&gt;expr&lt;/span&gt; = &lt;span style=&#034;color:purple&#034;&gt;term&lt;/span&gt; &lt;span style=&#034;color:lightgray&#034;&gt;&gt;&gt;&lt;/span&gt; &lt;span style=&#034;color:red&#034;&gt;*( (&lt;/span&gt;&lt;span style=&#034;color:green&#034;&gt;&#039;+&#039;&lt;/span&gt; &lt;span style=&#034;color:lightgray&#034;&gt;&gt;&gt;&lt;/span&gt; &lt;span style=&#034;color:purple&#034;&gt;term&lt;/span&gt;&lt;span style=&#034;color:red&#034;&gt;) | (&lt;/span&gt;&lt;span style=&#034;color:green&#034;&gt;&#039;-&#039;&lt;/span&gt; &lt;span style=&#034;color:lightgray&#034;&gt;&gt;&gt;&lt;/span&gt; &lt;span style=&#034;color:purple&#034;&gt;term&lt;/span&gt;&lt;span style=&#034;color:red&#034;&gt;) )&lt;/span&gt;;
&lt;/pre&gt;

&lt;p&gt;... and tell me C++ is not the perfect language for DSLs!  &lt;tt&gt;;=)&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Seriously, I copied down the above from Adam Mitz&#039;s OCI internal C++ lunch talk about &lt;a href= &#034;http://spirit.sourceforge.net/&#034; &gt;Boost.Spirit&lt;/a&gt; yesterday.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href= &#034;http://www.boost.org/libs/spirit/doc/introduction.html&#034; &gt;Boost.Spirit documentation&lt;/a&gt;: Spirit is an object-oriented recursive-descent parser generator framework implemented using template meta-programming techniques. Expression templates allow us to approximate the syntax of Extended Backus-Normal Form (EBNF) completely in C++.&lt;/p&gt;

&lt;p&gt;The Spirit framework enables a target grammar to be written exclusively in C++. Inline EBNF grammar specifications can mix freely with other C++ code and, thanks to the generative power of C++ templates, are immediately executable. In retrospect, conventional compiler-compilers or parser-generators have to perform an additional translation step from the source EBNF code to C or C++ code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As parser generators go, Boost.Spirit is pretty powerful stuff.  As an example, Adam redid Mark Volkmann&#039;s Math example from the &lt;a href= &#034;http://ociweb.com/mark/programming/ANTLR3.html&#034; &gt;ANTLR 3 talk&lt;/a&gt;, ASTs and all.&lt;/p&gt;

&lt;p&gt;Geeky as Boost.Spirit may seem,  can think of one occasion in past projects where we could have used it instead of coding a recursive descent parser by hand.&lt;/p&gt; 
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2008/03/26/a_little_c_to_boost_your_spirit.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2008/03/26/a_little_c_to_boost_your_spirit.html</guid>
    <pubDate>Wed, 26 Mar 2008 16:08:21 GMT</pubDate>
  </item>
  
  <item>
    <title>Quote Of The Day</title>
    <link>http://www.weiqigao.com/blog/2007/06/27/quote_of_the_day.html</link>
    
      
        <description>
          &lt;blockquote&gt;
&lt;p&gt;&lt;a href= &#034;http://www.artima.com/cppsource/boost_con_07.html&#034; &gt;Eric Niebler&lt;/a&gt;: [...] I drift back into the real world and hear this gem from Jeff as he compares ASIO to the popular ACE library: &#034;ACE is an open source project, so you’re free to download it, look at the source code, and be horrified.&#034;&lt;/p&gt;
&lt;/blockquote&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2007/06/27/quote_of_the_day.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2007/06/27/quote_of_the_day.html</guid>
    <pubDate>Wed, 27 Jun 2007 14:31:50 GMT</pubDate>
  </item>
  
  <item>
    <title>Boost Multi-index Container</title>
    <link>http://www.weiqigao.com/blog/2006/03/28/boost_multi_index_container.html</link>
    
      
        <description>
          &lt;p&gt;This is my second attempt at &lt;a href= &#034;http://www.weiqigao.com/blog/2006/02/28/c_c_interoperability_via_iiop_net_and_tao.html&#034; &gt;live blogging&lt;/a&gt;.  I&#039;m at the OCI internal C++ lunch presentation.  Today&#039;s speaker is Jonathan Pollack and he&#039;s talking about the &lt;a href= &#034;http://boost.org/&#034; &gt;Boost&lt;/a&gt; &lt;a href= &#034;http://boost.org/libs/multi_index/doc/index.html&#034; &gt;multi-index container&lt;/a&gt;, a C++ library that solves the &#034;data&#034; problem in certain situations:&lt;/p&gt;

&lt;p style=&#034;margin-left:3em&#034;&gt;You have a set of data, and you would like to find them by different sets of attributes.  Find Customer by SSN, by name, etc.&lt;/p&gt;

&lt;p&gt;I&#039;ll try something different this time.  I&#039;ll try to write some code as I follow the presentation.&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;struct Customer {
  std::string ssn_;
  std::string name_;
};
struct SSN { /* tag for an index */ };
struct Name { /* tag for an index */ };

typedef boost::multi_index_container&lt;
  Customer,
  boost::multi_index::indexed_by&lt;
    boost::multi_index::ordered_unique&lt;
      boost::multi_index::tag&amp;lt;SSN&gt;,
      boost::multi_index::member&amp;lt;Customer, std::string, &amp;Customer::ssn_&gt;
    &gt;,
    boost::multi_index::ordered_non_unique&lt;
      boost::multi_index::tag&amp;lt;Name&gt;,
      boost::multi_index::member&amp;lt;Customer, std::string, &amp;Customer::name_&gt;
  &gt;
MyCustomerDB;

typedef MyCustomerDB::index&amp;lt;SSN&gt;::type SSNIndex;
typedef MyCustomerDB::index&amp;lt;Name&gt;::type NameIndex;
typedef SSNIndex::iterator SSNIterator;
typedef NameIndex::iterator NameIterator;

MyCustomerDB db;
SSNIndex&amp; ssnIndex = db.index&amp;lt;SSN&gt;();
NameIndex&amp; nameIndex = db.index&amp;lt;Name&gt;();

Customer c1(&#034;333-44-5555&#034;, &#034;John Smith&#034;);
Customer c2(&#034;666-77-8888&#034;, &#034;Robert Brown&#034;);

db.insert(c1);
db.insert(c2);

SSNIterator ssnIter = ssnIndex.find(&#034;333-44-5555&#034;);
c1.ssn = &#034;999-00-1111&#034;;
indexBy.replace(ssnIter, c1);&lt;/pre&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2006/03/28/boost_multi_index_container.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2006/03/28/boost_multi_index_container.html</guid>
    <pubDate>Tue, 28 Mar 2006 19:07:05 GMT</pubDate>
  </item>
  
  </channel>
</rss>

