evazkj
12/6/2018 - 2:54 PM

BDE

BDE misc

#include <bdlt_date.h>
#include <bdlt_datetz.h>
#include <bdlt_currenttime.h>

const int NY_TZ_OFFSET = -300;   // -5 * 60

int main()
{
    using namespace BloombergLP;
    
    bdlt::Date y2kDate = bdlt::Date(2000, 1, 1);
    bsl::cout << y2kDate << "\n";

    bdlt::DateTz y2kDateTzUtc = bdlt::DateTz(y2kDate, 0);  // UTC timezone
    bsl::cout << y2kDateTzUtc << "\n";

    bdlt::DateTz y2kDateTzNY = bdlt::DateTz(y2kDate, NY_TZ_OFFSET);  // NY timezone, standard time
    bsl::cout << y2kDateTzNY << "\n";

    // Optional
    const bdlt::Datetime nowLN(bdlt::CurrentTime::utc());
    bsl::cout << nowLN << "\n";

    const bdlt::DatetimeTz nowNY(bdlt::CurrentTime::local(), NY_TZ_OFFSET);
    bsl::cout << nowNY << "\n";

    const bdlt::Datetime now(bdlt::CurrentTime::local());

    bsl::cout << now.date().year() << "-"
              << now.date().month() << "-"
              << now.date().day() << " "
              << now.hour() << ":"
              << now.minute() << "\n";


    return 0;
}
  1. get your .xsd file> $bas_codegen -m all --bbenv nano yoursvc.xsd $ metamkmk -t other -f yoursvc.mk $ llcalc --create yoursvc.mk //link loop calculate, add libs to .mk file $ llcalc --run --unbounded yoursvc.mk //simulate link loop $ cplink -d prod yoursvc.mk

$ ./yoursvc.linux.tsk yoursvc.cfg&

Create a request file (getBond.json) to get a bond from the service: { "getBondRequest": { "parseKey" : "AAPL 1.55 08/04/2021" } }

$ basclient -x yoursvc.xsd getBond.json

  • Logging: TRACE, DEBUG, INFO, WARN, ERROR, and FATAL
$ bbsend yoursvc stdoutlevel 4
$ bbsend yoursvc verb 4
$ basclient -x yoursvc.xsd getBonds.json

or you can also change the .cfg file

#include <bsl_iostream.h>
#include <bsl_string.h>

#include <bdlb_tokenizer.h>

int main(int argc, char* argv[])
{
    using namespace BloombergLP;

    bsl::string message = "This is a string";
    const char* delims = " "; // Use " " as the delimiter so each space will initiate a new token

    for (bdlb::Tokenizer tokenIt(message.c_str(), delims); tokenIt.isValid(); ++tokenIt) {
        bsl::cout << tokenIt.token() << "\n";

    }

    return 0;
}
bool boolArg; int numArg; bsl::string textArg;vector<bsl::string> freeArgs;
baea_CommandLineOptionInfo specTable[] = {
    {
        "b|boolArg",                  // tag
        "BoolArg", "A Boolean flag",  // name, description
        baea_CommandLineTypeInfo(&boolArg)
    },
    {
        "n|numArg",                   // tag
        "NumArg", "A integer arg",    // name, description
        baea_CommandLineTypeInfo(&numArg),
        baea_CommandLineOccurrenceInfo::REQUIRED // occurrence info
    },
    {  
        "t|textArg",                  // tag
        "TextArg", "A text arg.",     // name, description
        baea_CommandLineTypeInfo(&textArg)
    },
    {  
        "",                           // non-option
        "FreeArgs",  "List of Text args", 
        baea_CommandLineTypeInfo(&freeArgs),
    }
};
baea_CommandLine cmdLine(specTable);
// parse command line options; if failure, print usage & exit
if (cmdLine.parse(argc, argv)) {
    cmdLine.printUsage(); return -1;
}
bsl::cout << (boolArg ? "true" : "false") << numArg << textArg;
for (size_t i = 0; i != freeArgs.size(); ++i) {
    bsl::cout << freeArgs[i] << '\n';
}
bael_LoggerManagerConfiguration config;
    133     config.setDefaultThresholdLevelsIfValid(
    134                 bael_Severity::OFF,
    135                 bael_Severity::INFO,
    136                 bael_Severity::OFF,
    137                 bael_Severity::OFF);
    138     bael_FileObserver observer(bael_Severity::BAEL_WARN);
    139     observer.enableFileLogging("employee.log", true);
    140     bael_LoggerManagerScopedGuard manager(&observer, config);
    141     BAEL_LOG_SET_CATEGORY("MAIN");
    142
    143     BAEL_LOG_TRACE << "entering main" << BAEL_LOG_END;