Exemplo n.º 1
0
/*
** This function registered all of the above C functions as SQL
** functions.  This should be the only routine in this file with
** external linkage.
*/
void sqlite3RegisterDateTimeFunctions(void){
  static SQLITE_WSD FuncDef aDateTimeFuncs[] = {
#ifndef SQLITE_OMIT_DATETIME_FUNCS
    DFUNCTION(julianday,        -1, 0, 0, juliandayFunc ),
    DFUNCTION(date,             -1, 0, 0, dateFunc      ),
    DFUNCTION(time,             -1, 0, 0, timeFunc      ),
    DFUNCTION(datetime,         -1, 0, 0, datetimeFunc  ),
    DFUNCTION(strftime,         -1, 0, 0, strftimeFunc  ),
    DFUNCTION(current_time,      0, 0, 0, ctimeFunc     ),
    DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
    DFUNCTION(current_date,      0, 0, 0, cdateFunc     ),
#else
    STR_FUNCTION(current_time,      0, "%H:%M:%S",          0, currentTimeFunc),
    STR_FUNCTION(current_date,      0, "%Y-%m-%d",          0, currentTimeFunc),
    STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc),
#endif
  };
  int i;
  FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
  FuncDef *aFunc = (FuncDef*)&GLOBAL(FuncDef, aDateTimeFuncs);

  for(i=0; i<ArraySize(aDateTimeFuncs); i++){
    sqlite3FuncDefInsert(pHash, &aFunc[i]);
  }
}
Exemplo n.º 2
0
//==================================================================
bool FileManagerAndroid::SaveFile(const char* pFileName, const U8 *pInData, size_t dataSize, const char* pMode)
{
    DFUNCTION();
    DLOG("Saving file: %s", pFileName);

#if defined(ANDROID)
	bool prefs = isPrefsMode( pMode );

    bool result = false;

    if (prefs)
    {
        char *base64 = ToBase64(pInData, dataSize);
        if (0 == base64)
        {
            DLOG("Failed to convert to base64");
            return false;
        }

        DLOG("Data: %s", pInData);
        DLOG("Base64: %s", base64);
        result = ::DoWritePrefs(pFileName, base64);
        free(base64);
    }
    else
    {
        result = FileWrite(pFileName, pInData, dataSize);
    }

    DLOG("Returning: %s", (result)?("true"):("false"));
    return result;
#endif

	return true;
}
Exemplo n.º 3
0
/*
** This function registered all of the above C functions as SQL
** functions.  This should be the only routine in this file with
** external linkage.
*/
void sqlite3RegisterDateTimeFunctions(void){
  static FuncDef aDateTimeFuncs[] = {
#ifndef SQLITE_OMIT_DATETIME_FUNCS
    DFUNCTION(julianday,        -1, 0, 0, juliandayFunc ),
    DFUNCTION(date,             -1, 0, 0, dateFunc      ),
    DFUNCTION(time,             -1, 0, 0, timeFunc      ),
    DFUNCTION(datetime,         -1, 0, 0, datetimeFunc  ),
    DFUNCTION(strftime,         -1, 0, 0, strftimeFunc  ),
    DFUNCTION(current_time,      0, 0, 0, ctimeFunc     ),
    DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
    DFUNCTION(current_date,      0, 0, 0, cdateFunc     ),
#else
    STR_FUNCTION(current_time,      0, "%H:%M:%S",          0, currentTimeFunc),
    STR_FUNCTION(current_date,      0, "%Y-%m-%d",          0, currentTimeFunc),
    STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc),
#endif
  };
  sqlite3InsertBuiltinFuncs(aDateTimeFuncs, ArraySize(aDateTimeFuncs));
}
Exemplo n.º 4
0
//==================================================================
bool FileManagerAndroid::GrabFile(const char* pFileName, DVec<U8> &out_data, const char* pMode)
{
    DFUNCTION();
    DLOG("File: %s", pFileName);

#if defined(ANDROID)
	bool prefs = isPrefsMode( pMode );

    if (prefs)
    {
        // Read from the prefs storage

        DLOG("Grabbing file (prefs): %s", pFileName);
        char *contents = ::DoReadPrefs(pFileName);
        if (0 == contents)
        {
            DLOG("Failed to open the file");
            return false;
        }

        // Decode into binary

        size_t binLength = 0;
        void *binData = FromBase64(contents, &binLength);
        free(contents);
        if (binData == 0)
        {
            DPRINT("!! File '%s' was not base64 format.  Rejecting.", pFileName);
            return false;
        }

        // Copy into output array and free original

        // TODO: Could be sped up by pre-calculating length and not
        // copying.

        out_data.resize(binLength);
        memcpy(&out_data[0], binData, binLength);
        free(binData);

        DLOG("copied %d bytes", binLength);
        return true;
    }

    ::FileLoad(pFileName);
    int datasize;
    void *data;
    if (!FileGetData(pFileName, &data, &datasize))
    {
        //DASSTHROW(0, ("failed loading file '%s'", pFileName));
        return false;
    }

    out_data.resize(datasize);

    DVERBOSE("GrabFile: memcpy-ing '%s', %d bytes", pFileName, datasize);
    memcpy(&out_data[0], data, datasize);

    FileRemove(pFileName);
    DVERBOSE("GrabFile: released");
#endif

	return true;
}
Exemplo n.º 5
0
int main(int argc, char** argv)
{
  double ri = 0.0;
  double rf = 1.0;
  int npts = 101;
  const double nk=2;
  const double twopi = 8.0*atan(1.0)*nk;
  LinearGrid<double> agrid;
  agrid.set(ri,rf,npts);
#if defined(USE_PBC)
  typedef OneDimCubicSplinePBC<double> OrbitalType;
#else
  typedef OneDimCubicSplineFirst<double> OrbitalType;
#endif
  OrbitalType aorb(&agrid);
  aorb.resize(agrid.size());
  for(int i=0; i<agrid.size(); i++)
  {
    aorb(i)=FUNCTION(twopi*agrid(i));
  }
  aorb.spline(0,twopi*DFUNCTION(twopi*agrid.rmin()),agrid.size()-1, twopi*DFUNCTION(twopi*agrid.rmax()));
  string fname("testpbc.dat");
  std::ofstream dfile(fname.c_str());
  dfile.setf(ios::scientific, ios::floatfield);
  dfile.setf(ios::left,ios::adjustfield);
  dfile.precision(15);
  const double c1=1.0/twopi;
  const double c2=c1*c1;
  double du,d2u,_r,_rinv,y;
#if defined(USE_PBC)
  for(int ig=agrid.size()/2; ig<agrid.size() ; ig++)
  {
    _r = agrid(ig)+0.5*agrid.dr(ig)-agrid.rmax();
    _rinv = 1.0/_r;
    //aorb.setgrid(_r);
    y=aorb.evaluate(_r,_rinv,du,d2u);
    dfile << setw(30) << _r << setw(30) << FUNCTION(twopi*_r) << setw(30) << y << setw(30) << du*c1 << setw(3) << d2u*c2 << endl;
  }
#endif
  for(int ig=0; ig<agrid.size()-1; ig++)
  {
    _r = agrid(ig)+0.5*agrid.dr(ig);
    _rinv = 1.0/_r;
    //aorb.setgrid(_r);
    y=aorb.evaluate(_r,_rinv,du,d2u);
    dfile << setw(30) << _r << setw(30) << FUNCTION(twopi*_r) << setw(30) << y
          << setw(30) << du*c1 << setw(3) << d2u*c2 << endl;
  }
#if defined(USE_PBC)
  for(int ig=0; ig<agrid.size()/2; ig++)
  {
    _r = agrid(ig)+0.5*agrid.dr(ig)+agrid.rmax();
    _rinv = 1.0/_r;
    //aorb.setgrid(_r);
    y=aorb.evaluate(_r,_rinv,du,d2u);
    dfile << setw(30) << _r << setw(30) << FUNCTION(twopi*_r) << setw(30) << y << setw(30) << du*c1 << setw(3) << d2u*c2 << endl;
  }
#endif
  dfile << endl;
  return 0;
}