Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Say Something...

This thread is locked; no one can reply to it. rss feed Print
 1   2   3   4 
Say Something...
William Labbett
Member #4,486
March 2004
avatar

Pissed.

Not like you mean over in US though.

No, not angry.

You know what I mean.

BTW, save me having to write a new thread.

Where's Trent and the Supreme Loser?

Sirocco
Member #88
April 2000
avatar

Yup.

-->
Graphic file formats used to fascinate me, but now I find them rather satanic.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

jmasterx
Member #11,410
October 2009

I'm giving up on you Armando >:(

MiquelFire
Member #3,110
January 2003
avatar

I'm in a position where I don't have the time to sit in front of the computer as much as I want.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

AMCerasoli
Member #11,955
May 2010
avatar

jmasterx said:

I'm giving up on you Armando

I'll be the one if you want me to

Gideon Weems
Member #3,925
October 2003

Went to a concert tonight at... I guess you would call it a pub. It was basically the Pigeon's Nest from Animal Crossing but with alcohol instead of pigeon milk.

... That's how to be off-topic in Off Topic.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Dennis
Member #1,090
July 2003
avatar

Got bored with WoW a few days ago. Will probably not continue playing it. I only started playing to escape from RL problems anyway but it turns out problems do not always go away when they are ignored (you would be surprised how often it works, despite people saying it does not ;D).

So... blah.

AMCerasoli
Member #11,955
May 2010
avatar

I'm trying to make a class to handle sqlite3 databases like Codeignter does.

Something like this:

    db->select("users.email, users.password");
    db->from("users");
    db->join("games", "games.id = users.id", "LEFT");
    db->join("webs", "webs.id = users.id", "LEFT");
    db->where("user.email", "amcerasoli@hotmail.com");
    db->where("webs.cast", 1);
    db->groupBy("users.id");
    db->get()->row_array();

And I want row_array() to return a std::map like this:

typedef std::map<std::string, boost::variant<int,
                                             double,
                                             std::string> > aArray_t;

but when I do this: int a = myMap["userId"] I get an error telling me that cannot convert and bla bla bla...

If I could get the direct value from a map would be incredible, and that's what I'm trying to do now, but I think it's kind of impossible.

pkrcel
Member #14,001
February 2012

but when I do this: int a = myMap["userId"] I get an error telling me that cannot convert and bla bla bla...

Shouldn't that access grant a return of a boost::variant as per your definition?

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

AMCerasoli
Member #11,955
May 2010
avatar

Yes, that's what gives me. But I'm looking for something that could give me the type directly in this case an integer.

Now I'm trying to use templates in order to do something like:

        Database db;
        db.init();
        db.select("users.email, users.password");
        db.from("peopleProfile");
        Dbres dbr = db.get();
        
        int a = dbr.get(0, "name");

Where 0 is the result row number and "name" the column name. If name is int returns int if it's string, string... and so on and so forth. But I haven't be able to do it so far.

I think it should be possible? :-/

pkrcel
Member #14,001
February 2012

Not with that signature, as far as I know...your asking for a variant return type....I'm unsure there is a technique granting what you want, but I am too a n00b to know for sure.

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

AMCerasoli
Member #11,955
May 2010
avatar

Where will I stop being a n00b? It's not like I have all my life! >:(

jmasterx
Member #11,410
October 2009

I'll be the one if you want me to

Anywhere I, would've followed you (even on Twitter)

AMCerasoli
Member #11,955
May 2010
avatar

jmasterx said:

Anywhere I, would've followed you (even on Twitter)

Ok man I'll say something so you don't give up on me. When programming C++ I feel so small, I have all these dreams over my head, but when I'm programming I know nothing at all. I know I will stumble and fall I'm even still learning PHP :-/ Just starting to crawl.

jmasterx (btw what is your real name?) say something, don't give up on me...

;D;D;D

jmasterx
Member #11,410
October 2009

Armando, I'm sorry that I couldn't get to you before you started feeling this way about your C++ skills. I'll swallow my pride, you're the one that I teach, please don't say goodbye :'(

Josh

Gideon Weems
Member #3,925
October 2003

Is there something wrong with using a void pointer and a typecast? Is that not plus-plussy enough or something? ;)

Donald Knuth convinced me to finally take the hyphen out of "email." I'm currently setting up mutt and offlineimap to work with Gmail. It's a pain in the ass, but that's part of doing things right. Command-line email is the way to go.

I've decided to keep this topic going for as long as socially acceptable.

pkrcel
Member #14,001
February 2012

Is there something wrong with using a void pointer and a typecast? Is that not plus-plussy enough or something?

Well, that would get close (as I initially tought) to what Armando's asking but no cigar, he is askinf to implement a method that automatically detects the type and returns the corresponding item.

I sense come C++11ness in there, as well as something far beyond my reach :P

By the way I could use some teaching as well, are you holding classes? ;D

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

bamccaig
Member #7,536
July 2006
avatar

You might be able to use a template to get the dynamic return value. My C++ is a little bit rusty.

auto x = row.get<int>("column"); // x is implicitly an int.

That's probably the closest you'll get. That said, I really think that SQL is the best tool for the job, and you should keep your C++ API scoped to just be capable of handing off SQL requests and getting at the results as efficiently as possible (so don't bother trying to create a query language in C++). Let SQL do what SQL was designed to do. Use C++ to make the request and consume the data in as few keystrokes as possible.

I'm currently setting up mutt and offlineimap to work with Gmail.

I'd appreciate it if you publish the result. :) fetchmail + mutt is becoming unmanageable given my current situation behind a Microsoft proxy. It worked fine when a server-side mutt became my primary MUA, but since I most often don't have access to my server during work hours I am stuck managing multiple copies of my mailbox and trying to manually keep them in sync.

I haven't had the time to try to set up my own UNIX-friendly proxy, but I suspect that I'd get in trouble if I got caught anyway. At least if I could access G-mail via IMAP then I'd be able to get the best of both worlds. In theory. I think that the way that G-mail does IMAP is actually not very good... I digress. The alternative would be setting up my own E-mail service, which would be a lot of work and would result in less reliable service. :-[

Command-line email is the way to go.

Hear, hear!

AMCerasoli
Member #11,955
May 2010
avatar

jmasterx said:

Josh

Oh cool! like Yoshi? ;D

{"name":"Yoshi_MP8_Artwork.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/9\/996b3f57af61aed7ee6df0b2798eccac.jpg","w":1244,"h":2480,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/9\/996b3f57af61aed7ee6df0b2798eccac"}Yoshi_MP8_Artwork.jpg

Is there something wrong with using a void pointer and a typecast? Is that not plus-plussy enough or something?

That's so C-- :o

Java uses specific methods and type checking to get information out of a result set. my_int_column = results.getInt(index);

Weeeeelll... But it is not so cool. :P

bamccaig said:

That's probably the closest you'll get.

NO! THERE SHOULD BE SOMETHING BETTER!! MUCH BETTER!!

Quote:

That said, I really think that SQL is the best tool for the job, and you should keep your C++ API scoped to just be capable of handing off SQL requests and getting at the results as efficiently as possible (so don't bother trying to create a query language in C++). Let SQL do what SQL was designed to do. Use C++ to make the request and consume the data in as few keystrokes as possible.

He... What do you mean? making queries manually like:

std::string query = 
"SELECT apple.syrup"
"FROM Canada"
"WHERE apple.isAtPoint = 1 AND apple.isGreen = 1"
;
db.query(query);

Because that will be also possible. But I'm trying to simplify that process.

Gideon Weems
Member #3,925
October 2003

bamccaig said:

... I am stuck managing multiple copies of my mailbox and trying to manually keep them in sync.

I think that's the very problem OfflineIMAP was designed to fix. Admittedly, I've mostly been configuring the Mutt side of things, but an ideal set-up would have a one-for-one offline backup on the main machine, with smaller, filtered versions on portable devices. OfflineIMAP synchronizes everything to Gmail and even includes a dedicated Gmail protocol, as apparently Google's IMAP isn't 100% pure ;).

Mutt can handle IMAP out of the box, though, and Mutt configuration alone has kept me tied up for a bit. Here are a few observations for anyone interested in emailing like a boss:

  • The mail_check variable can slow down Mutt when set too low. To be honest, I'd rather disable automatic checking altogether--though this will become moot when using OfflineIMAP.

  • HTML email is not supported out of the box. Set up a reader (w3m, lynx, etc.) and add an entry to mailcap. This does not require a helper script, as one source suggests. The bare command suffices.

  • Straight from the manual (concerning MIME types in .mailcap): "Entries with the copiousoutput tag should always be specified as the last one per type."

bamccaig
Member #7,536
July 2006
avatar

NO! THERE SHOULD BE SOMETHING BETTER!! MUCH BETTER!!

You should be able to define user-defined conversions for a particular invariant class so that it will automatically convert to e.g., int or std::string or whatever. I'm not familiar with boost::variant so I don't know if it does this or not. It looks like not based on a skim of the documentation. I'm not sure why that is (e.g., technical or logical). In any case, you might be able to implement your own variant class that does.

He... What do you mean? making queries manually like:

std::string query = 
"SELECT apple.syrup"
"FROM Canada"
"WHERE apple.isAtPoint = 1 AND apple.isGreen = 1"
;
db.query(query);

Because that will be also possible. But I'm trying to simplify that process.

Sure, but the API that you've defined above is more verbose and more difficult to read than the raw SQL is. It's also less functional. At least be careful not to introduce SQL injection vulnerabilities in your API.

Thomas Fjellstrom
Member #476
June 2000
avatar

I use template structs/classes to get "Variant" return values:

template<>
struct stack<int> {
  static int get(LuaGlueBase *, lua_State *s, int idx)
  {
    return luaL_checkint(s, idx);
  }
  
  static void put(LuaGlueBase *, lua_State *s, int v)
  {
    lua_pushinteger(s, v);
  }
};

And to use such a thing:

   int foo = stack<int>::get(glue, glue->state(), 0);

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

 1   2   3   4 


Go to: