[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fossil-users
Subject:    [fossil-users] Brief demo of the libfossil C++ API
From:       Stephan Beal <sgbeal () googlemail ! com>
Date:       2014-03-31 18:39:57
Message-ID: CAKd4nAgSBAw_m1DWWmeA0WvuewumAAMb1r02SXX-szPWf9Z7Tw () mail ! gmail ! com
[Download RAW message or body]

Hi, all,

the libfossil C++ bindings have been moving along nicely and i just wanted
to make a very brief demo showing how easy they are to use:


// Initialize a "Fossil Context":
fsl::Context f;

// Open a repo or checkout/repo combination:
f.openRepo("/path/to/my/repo.fossil");
// or:
f.openCheckout(); // optionally pass a dir name. Default behaviour is like
fossil(1)'s

// Load all metadata for a given checkin:
fsl::Deck d(f);
d.load( f.symToRid("trunk") );
std::cout << "Loaded RID " << d.rid() << ' ' << d.uuid() << '\n';
std::cout << d; // dumps out the manifest's contents

It throws exceptions for all but the most trivial of errors, which
simplifies client code considerably over using the plain C API (where every
single allocation can fail and must be checked).

C++ operator overloading allows us to do some interesting things in terms
of mixing C++ objects with the C API, such as wrapping scope-based memory
management around C types holding dynamic memory and conversion of C-level
API errors to C++ exceptions:

  Deck const & Deck::output( fsl_output_f f, void * outState ) const{
    Exception ex;
    int const rc = fsl_deck_output( *this, f, outState, ex );
 // a C function ^^^^^^ we're passing it 2 C++ objects "converted" via
operator overloading
    if(rc) throw ex; // holds error info set by the C function
    else return *this;
  }


There's a slightly longer demo in the obligatory test program:

http://fossil.wanderinghorse.net/repos/libfossil/index.cgi/finfo?name=cpp/test.cpp

Happy Hacking!

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf

[Attachment #3 (text/html)]

<div dir="ltr">Hi, all,<div><br></div><div>the libfossil C++ bindings have been \
moving along nicely and i just wanted to make a very brief demo showing how easy they \
are to use:</div><div><br></div><div><br></div><div>// Initialize a &quot;Fossil \
Context&quot;:</div> <div>fsl::Context f;<br></div><div><br></div><div>// Open a repo \
or checkout/repo combination:</div><div><div>f.openRepo(&quot;/path/to/my/repo.fossil&quot;);</div></div><div>// \
or:</div><div>f.openCheckout(); // optionally pass a dir name. Default behaviour is \
like fossil(1)&#39;s</div> <div><br></div><div>// Load all metadata for a given \
checkin:</div><div>fsl::Deck d(f);<br></div><div>d.load( \
f.symToRid(&quot;trunk&quot;) );</div><div>std::cout &lt;&lt; &quot;Loaded RID &quot; \
&lt;&lt; d.rid() &lt;&lt; &#39; &#39; &lt;&lt; d.uuid() &lt;&lt; &#39;\n&#39;;<br \
clear="all"> <div>std::cout &lt;&lt; d; // dumps out the manifest&#39;s \
contents</div><div><br></div><div>It throws exceptions for all but the most trivial \
of errors, which simplifies client code considerably over using the plain C API \
(where every single allocation can fail and must be checked).<br> \
</div><div><br></div><div>C++ operator overloading allows us to do some interesting \
things in terms of mixing C++ objects with the C API, such as wrapping scope-based \
memory management around C types holding dynamic memory and conversion of C-level API \
errors to C++ exceptions:</div> <div><br></div><div><div>  Deck const &amp; \
Deck::output( fsl_output_f f, void * outState ) const{</div><div>    Exception \
ex;</div><div>    int const rc = fsl_deck_output( *this, f, outState, ex \
);</div><div> // a C function ^^^^^^ we&#39;re passing it 2 C++ objects \
&quot;converted&quot; via operator overloading</div> <div>    if(rc) throw ex; // \
holds error info set by the C function</div><div>    else return *this;</div><div>  \
}</div></div><div><br></div><div><br></div><div>There&#39;s a slightly longer demo in \
the obligatory test program:</div> <div><br></div><div><a \
href="http://fossil.wanderinghorse.net/repos/libfossil/index.cgi/finfo?name=cpp/test.c \
pp">http://fossil.wanderinghorse.net/repos/libfossil/index.cgi/finfo?name=cpp/test.cpp</a><br></div><div><br></div>
 <div>Happy Hacking!</div><div><br></div>-- <br><div dir="ltr">----- stephan \
beal<br><a href="http://wanderinghorse.net/home/stephan/" \
target="_blank">http://wanderinghorse.net/home/stephan/</a><div><a \
href="http://gplus.to/sgbeal" target="_blank">http://gplus.to/sgbeal</a></div> \
<div>&quot;Freedom is sloppy. But since tyranny&#39;s the only guaranteed byproduct \
of those who insist on a perfect world, freedom will have to do.&quot; -- Bigby \
Wolf</div></div> </div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic