Пример #1
0
std::string
JSONNode::ToString(const std::string &indent) const
{
    //char buf[1024];
    std::ostringstream ostr;
    if(type == JSONNULLVALUE)
        return "null";

    if(type == JSONBOOL)
        return GetBool() ? "true" : "false";

    if(type == JSONSTRING)
    {
        std::string str = "\"" + EscapeString(json.str) + "\"";
        return str;
    }

//    if(type == JSONINTEGER)
//    {
//        ostr << GetInt();
//        return ostr.str();
//    }
    if(type == JSONLONG)
    {
        ostr << GetLong();
        return ostr.str();
    }
//    if(type == JSONFLOAT)
//    {
//        ostr << GetFloat();
//        return ostr.str();
//    }
    if(type == JSONDOUBLE)
    {
        ostr << GetDouble();
        return ostr.str();
    }

    if(type == JSONARRAY)
    {
        std::string output = "[";
        for(size_t i = 0; i < json.array.size(); ++i)
        {
            output += json.array[i].ToString();

            if(i != json.array.size() - 1)
                output += ",";
        }
        output += "]";

        return output;
    }

    if(type == JSONOBJECT)
    {
        std::string output = "{";

        size_t index = 0;
        for(JSONObject::const_iterator itr = json.object.begin();
              itr != json.object.end(); ++itr)
        {
            std::string pair = "\"" + itr->first + "\"";
            pair += ":";
            pair += itr->second.ToString();

            output += pair;

            if(index != json.object.size() - 1)
                output += ",";

            ++index;
        }

        output += "}";
        return output;
    }

    /// default returns nothing..
    return "";
}
Пример #2
0
// Read a double value from the ini file, increase it then write it back
BOOL CIni::IncreaseDouble(LPCTSTR lpSection, LPCTSTR lpKey, double fIncrease, int nPrecision) const
{
	double f = GetDouble(lpSection, lpKey, 0.0);
	f += fIncrease;
	return WriteDouble(lpSection, lpKey, f, nPrecision);
}
Пример #3
0
void JSONValue::GetVariantValue(Variant& variant, VariantType type) const
{
    switch (type)
    {
    case VAR_BOOL:
        variant = GetBool();
        return;

    case VAR_INT:
        variant = GetInt();
        return;

    case VAR_FLOAT:
        variant = GetFloat();
        return;

    case VAR_DOUBLE:
        variant = GetDouble();
        return;

    case VAR_STRING:
        variant = GetString();
        return;

    case VAR_VARIANTVECTOR:
        {
            VariantVector vector;
            GetVariantVector(vector);
            variant = vector;
        }
        return;

    case VAR_VARIANTMAP:
        {
            VariantMap map;
            GetVariantMap(map);
            variant = map;
        }
        return;

    case VAR_RESOURCEREF:
        {
            ResourceRef ref;
            Vector<String> values = GetString().Split(';');
            if (values.Size() == 2)
            {
                ref.type_ = values[0];
                ref.name_ = values[1];
            }
            variant = ref;
        }
        return;

    case VAR_RESOURCEREFLIST:
        {
            ResourceRefList refList;
            Vector<String> values = GetString().Split(';');
            if (values.Size() >= 1)
            {
                refList.type_ = values[0];
                refList.names_.Resize(values.Size() - 1);
                for (unsigned i = 1; i < values.Size(); ++i)
                    refList.names_[i - 1] = values[i];
            }
            variant = refList;
        }
        return;

    case VAR_STRINGVECTOR:
        {
            StringVector vector;
            for (unsigned i = 0; i < Size(); ++i)
                vector.Push((*this)[i].GetString());
            variant = vector;
        }
        return;

    default:
        variant.FromString(type, GetString());
        return;
    }
}
Пример #4
0
float Cx_XmlSection::GetFloat(const wchar_t* name, float defValue)
{
    return static_cast<float>(GetDouble(name, defValue));
}
Пример #5
0
bool SelectCommand::Apply(CommandExecutionContext context)
{
    wxString mode = GetString(wxT("Mode"));
    if (mode.IsSameAs(wxT("None")))
    {
        // select none
        context.proj->OnSelectNone();
    }
    else if (mode.IsSameAs(wxT("All")))
    {
        // select all
        context.proj->OnSelectAll();
    }
    else if (mode.IsSameAs(wxT("Range")))
    {
        // select range
        double t0 = GetDouble(wxT("StartTime"));
        double t1 = GetDouble(wxT("EndTime"));

        TrackList *tracks = context.proj->GetTracks();

        if (t0 < context.proj->GetTracks()->GetMinOffset())
        {
            Error(wxT("Start time is before start of track!"));
            return false;
        }
        if (t1 > context.proj->GetTracks()->GetEndTime())
        {
            Error(wxT("End time is after end of track!"));
            return false;
        }
        context.proj->mViewInfo.sel0 = t0;
        context.proj->mViewInfo.sel1 = t1;

        // select specified tracks
        long firstTrack = GetLong(wxT("FirstTrack"));
        long lastTrack = GetLong(wxT("LastTrack"));

        if (firstTrack < 0)
        {
            Error(wxT("Trying to select a negatively numbered track!"));
            return false;
        }
        if (lastTrack >= tracks->GetCount())
        {
            Error(wxT("Trying to select higher number track than exists!"));
            return false;
        }

        int index = 0;
        TrackListIterator iter(tracks);
        Track *t = iter.First();
        while (t) {
            bool sel = firstTrack <= index && index <= lastTrack;
            t->SetSelected(sel);

            if (sel)
                Status(wxT("Selected track '") + t->GetName() + wxT("'"));

            t = iter.Next();
            ++index;
        }
        wxASSERT(index >= lastTrack);
    }
    else if (mode.IsSameAs(wxT("Name")))
    {
        wxString name = GetString(wxT("TrackName"));
        TrackList *tracks = context.proj->GetTracks();
        TrackListIterator iter(tracks);
        Track *t = iter.First();
        while (t) {
            bool sel = t->GetName().IsSameAs(name);
            t->SetSelected(sel);

            if (sel)
                Status(wxT("Selected track '") + t->GetName() + wxT("'"));

            t = iter.Next();
        }
    }
    else
    {
        Error(wxT("Invalid selection mode!"));
        return false;
    }
    return true;
}
Пример #6
0
string CVariant::GetString(void) const
{
    string s("");

    if( IsNull() )
    {
        switch( GetType() ) {
            case eDB_TinyInt:
            case eDB_SmallInt:
            case eDB_Int:
            case eDB_BigInt:
            case eDB_Numeric:
                s = "0";
                break;
            case eDB_Float:
            case eDB_Double:
                s = "0.0";
                break;
            default:
                break;
        }
    }
    else
    {
        switch( GetType() ) {
            case eDB_Char:
            case eDB_VarChar:
            case eDB_LongChar:
                s = ((CDB_String*)GetData())->Value();
                break;
            case eDB_Binary:
                {
                    CDB_Binary *b = (CDB_Binary*)GetData();
                    s = string((char*)b->Value(), b->Size());
                    break;
                }
            case eDB_LongBinary:
                {
                    CDB_LongBinary *vb = (CDB_LongBinary*)GetData();
                    s = string((char*)vb->Value(), vb->DataSize());
                    break;
                }
            case eDB_VarBinary:
                {
                    CDB_VarBinary *vb = (CDB_VarBinary*)GetData();
                    s = string((char*)vb->Value(), vb->Size());
                    break;
                }
            case eDB_TinyInt:
                s = NStr::IntToString(GetByte());
                break;
            case eDB_SmallInt:
                s = NStr::IntToString(GetInt2());
                break;
            case eDB_Int:
                s = NStr::IntToString(GetInt4());
                break;
            case eDB_BigInt:
                s = NStr::Int8ToString(GetInt8());
                break;
            case eDB_Float:
                s = NStr::DoubleToString(GetFloat());
                break;
            case eDB_Double:
                s = NStr::DoubleToString(GetDouble());
                break;
            case eDB_Bit:
                s = NStr::BoolToString(GetBit());
                break;
            case eDB_Numeric:
                s = ((CDB_Numeric*)GetData())->Value();
                break;
            case eDB_DateTime:
            case eDB_SmallDateTime:
                s = GetCTime().AsString();
                break;
            case eDB_Text:
            case eDB_Image:
                {
                    CDB_Stream* stream = (CDB_Stream*)GetData();
                    char* buff[4096];
                    size_t read_bytes = 0;
                
                    s.reserve(stream->Size());
                    while ((read_bytes = stream->Read(buff, sizeof(buff))) != 0) {
                        s.append((const char*) buff, read_bytes);

                        if (read_bytes < sizeof(buff)) {
                            break;
                        }
                    }
                }
                break;
            default:
                x_Verify_AssignType(eDB_UnsupportedType, "string");
                break;
        }
    }

    return s;
}
Пример #7
0
double OdbcStatement::GetDouble(unsigned int column)
{
  double val = 0;
  GetDouble(column, &val);
  return val;
}
Пример #8
0
float Variant::GetFloat() const
{
  return static_cast<float>(GetDouble());
}
Пример #9
0
//FlashCS5extension.WriteDynamic(라이브러리 다이나믹들)
JSBool WriteDynamic(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval) {
    
    writelog("begin");
    
    if(argc != 1)
        return JS_FALSE;
    
    writelog("check arg count");
	
	if(pObjectFile) {
		JSObject* dynamicObjs;
		if(JS_ValueToObject(cx, argv[0], &dynamicObjs) == JS_FALSE)
			return ReturnString(cx, "q _ 1", rval);
        
        writelog("get dynamic objects from argv[0]");
		
		unsigned int dynamicLen = (unsigned int)JS_GetArrayLength(cx, dynamicObjs);
		if(dynamicLen == -1)
			return ReturnString(cx, "q _ 2", rval);
        
        writelog("get dynamic length = %u", dynamicLen);
		
		fwrite(&dynamicLen, sizeof(unsigned int), 1, pObjectFile);
		
		for(int i = 0; i < dynamicLen; i++) {
			jsval posDynamic;
			if(JS_GetElement(cx, dynamicObjs, i, &posDynamic) == JS_FALSE)
				return ReturnString(cx, "q _ 3", rval);
            
            writelog("==================================");
            writelog("get dynamic element %d", i);
			
			JSObject* dynamicObj;
			if(JS_ValueToObject(cx, posDynamic, &dynamicObj) == JS_FALSE)
				return ReturnString(cx, "q _ 4", rval);
            
            writelog("get dynamic object %d", i);
			
			//라이브러리 네임
            char *libName = GetString(cx, dynamicObj, 0);
            if(libName == 0)
                return ReturnString(cx, "q _ 5", rval);
            
            //library ID
			unsigned int libID = PushLibraryName(libName);
			fwrite(&libID, sizeof(unsigned int), 1, pObjectFile);
            writelog("libName = %s, libID = %u", libName, libID);
			free(libName);
            
            //library Type
            long libType;
            if(GetInteger(cx, dynamicObj, 4, &libType) == JS_FALSE)
                return ReturnString(cx, "q _ 51", rval);
            
            writelog("lib type = %d", libType);
            fwrite(&libType, sizeof(long), 1, pObjectFile);
            
            //frame Length
            long frameLength;
            if(GetInteger(cx, dynamicObj, 5, &frameLength) == JS_FALSE)
                return ReturnString(cx, "q _ 51", rval);
            
            writelog("frame length = %d", frameLength);
            fwrite(&frameLength, sizeof(long), 1, pObjectFile);
            
//            //인스턴스 
//            {
//                JSObject* instanceObj;
//                if(GetObject(cx, dynamicObj, 3, &instanceObj) == JS_FALSE)
//                    return ReturnString(cx, "instance  _ 1", rval);
//                
//                //인스턴스 개수
//                int insLen = (int)JS_GetArrayLength(cx, instanceObj);
//                if(insLen == -1)
//                    return ReturnString(cx, "instance  _ 2", rval);
//                
//                fwrite(&insLen, sizeof(int), 1, pObjectFile);
//                
//                writelog("instance length = %d", insLen);
//                
//                for(int m = 0; m < insLen; m++) {
//                    //instance obj
//                    JSObject* insObj;
//                    if(GetObject(cx, instanceObj, m, &insObj) == JS_FALSE)
//                        return ReturnString(cx, "instance  _ 3", rval);
//                    
//                    //instance id
//                    long insid;
//                    if(GetInteger(cx, insObj, 1, &insid) == JS_FALSE)
//                        return ReturnString(cx, "instance  _ 4", rval);
//                    
//                    //instance name
//                    char* insName = GetString(cx, insObj, 0);
//                    //instnace name length
//                    int insNameLen = strlen(insName);
//                    
//                    fwrite(&insNameLen, sizeof(int), 1, pObjectFile);
//                    
//                    writelog("instance name length = %d", insNameLen);
//                    
//                    fwrite(insName, sizeof(char), insNameLen, pObjectFile);
//                    
//                    writelog("instance name = %s", insName);
//                    
//                    fwrite(&insid, sizeof(int), 1, pObjectFile);
//                    
//                    writelog("instance id = %d", insid);
//                    
//                    free(insName);
//                }
//            }
            
            //레퍼런스
            {
                JSObject* referenceObj;
                if(GetObject(cx, dynamicObj, 1, &referenceObj) == JS_FALSE)
                    return ReturnString(cx, "q _ 6", rval);
                
                writelog("--------------------------------");
                writelog("get reference obj");
                
                
                
                //reference count
                int refLen = (int)JS_GetArrayLength(cx, referenceObj);
                if(refLen == -1)
                    return ReturnString(cx, "q _ 7", rval);
                
                writelog("reference length = %ld", refLen);
                
                fwrite(&refLen, sizeof(int), 1, pObjectFile);
                
                for(int j = 0; j < refLen; ++j) {
                    writelog("--------------------------------");
                    
                    //ref info obj
                    JSObject* refObj;
                    if(GetObject(cx, referenceObj, j, &refObj) == JS_FALSE)
                        return ReturnString(cx, "q _ 71", rval);
                    
                    int refMemberIndex = 0;
                    
                    int refinfoLen = (int)JS_GetArrayLength(cx, refObj);
                    if(refinfoLen == -1)
                        return ReturnString(cx, "q _ 72", rval);
                    
                    //reference ID
                    long refid;
                    if(GetInteger(cx, refObj, refMemberIndex++, &refid) == JS_FALSE)
                        return ReturnString(cx, "q _ 8", rval);
                    
                    //type
                    long type;
                    if(GetInteger(cx, refObj, refMemberIndex++, &type) == JS_FALSE)
                        return ReturnString(cx, "q _ 11", rval);
                    
                    writelog("type = %d", type);
                    
                    fwrite(&type, sizeof(long), 1, pObjectFile);
                    
                    //lib ID
                    char* libName = GetString(cx, refObj, refMemberIndex++);

                    //read Depth
                    
                    //read StartFrame
                    long startFrame;
                    if(GetInteger(cx, refObj, refMemberIndex++, &startFrame) == JS_FALSE)
                        return ReturnString(cx, "q _ 11", rval);
                    
                    //read End Frame
                    long endFrame;
                    if(GetInteger(cx, refObj, refMemberIndex++, &endFrame) == JS_FALSE)
                        return ReturnString(cx, "q _ 42", rval);
                    
                    //read next reference ID
                    long nextrefid;
                    if(GetInteger(cx, refObj, refMemberIndex++, &nextrefid) == JS_FALSE)
                        return ReturnString(cx, "q _ 8", rval);
                    
                    //read depth
                    long depth;
                    if(GetInteger(cx, refObj, refMemberIndex++, &depth) == JS_FALSE)
                        return ReturnString(cx, "q _ 8", rval);
                    
                                        
                    if(type == _TYPE_BITMAP_) {
                        //lib Path                    
                        char* libPath = GetString(cx, refObj, refMemberIndex++);
                        unsigned int libID = PushLibraryName(libPath);
                        fwrite(&libID, sizeof(unsigned int), 1, pObjectFile);
                        writelog("lib path = %s, lib = %u", libPath, libID);
                        free(libPath);
                    } else if(type == _TYPE_GRAPHIC_) {
                        //get lib name
                        unsigned int libID = PushLibraryName(libName);
                        fwrite(&libID, sizeof(unsigned int), 1, pObjectFile);
                        writelog("lib name = %s, lib = %u", libName, libID);
                        free(libName); 
                    } else {
                        //get lib name
                        unsigned int libID = PushLibraryName(libName);
                        fwrite(&libID, sizeof(unsigned int), 1, pObjectFile);
                        writelog("lib name = %s, lib = %u", libName, libID);
                        free(libName);    
                        
                        //instance ID
                        long insLen;
                        char* insName = GetString(cx, refObj, refMemberIndex++);
                        insLen = strlen(insName);
                        fwrite(&insLen, sizeof(long), 1, pObjectFile);
                        fwrite(insName, insLen, 1, pObjectFile);
                        writelog("instnace name = %s", insName);
                    }
                    
                    //write depth
                    writelog("depth = %d", depth);
                    fwrite(&depth, sizeof(long), 1, pObjectFile);
                    
                    //write Start Frame
                    writelog("startFrame = %d", startFrame);
                    
                    fwrite(&startFrame, sizeof(long), 1, pObjectFile);
                    
                    //write End Frame
                    writelog("end frame = %d", endFrame);
                    
                    fwrite(&endFrame, sizeof(long), 1, pObjectFile);

                    if(type == _TYPE_BITMAP_ || type == _TYPE_GRAPHIC_ || type == _TYPE_MOVIECLIP_) {
                        
                        
                        writelog("ref id = %d", refid);
                        
                        fwrite(&refid, sizeof(long), 1, pObjectFile);
                        
                        //write next reference ID
                        writelog("next ref id = %d", nextrefid);
                        
                        fwrite(&nextrefid, sizeof(long), 1, pObjectFile);
                        
                        //Start Position
                        double startX;
                        double startY;
                        if(GetDouble(cx, refObj, refMemberIndex++, &startX) == JS_FALSE)
                            return ReturnString(cx, "q _ 12", rval);
                        
                        if(GetDouble(cx, refObj, refMemberIndex++, &startY) == JS_FALSE)
                            return ReturnString(cx, "q _ 13", rval);
                        
                        float startXf, startYf;
                        startXf = (float)startX;
                        startYf = (float)startY;
                        fwrite(&startXf, sizeof(float), 1, pObjectFile);
                        fwrite(&startYf, sizeof(float), 1, pObjectFile);
                        
                        writelog("startX = %f, startY = %f", startX, startY);
                        
                        //Anchor
                        double anchorX;
                        double anchorY;
                        if(GetDouble(cx, refObj, refMemberIndex++, &anchorX) == JS_FALSE)
                            return ReturnString(cx, "q _ 14", rval);
                        
                        if(GetDouble(cx, refObj, refMemberIndex++, &anchorY) == JS_FALSE)
                            return ReturnString(cx, "q _ 15", rval);
                        
                        float anchorXf, anchorYf;
                        anchorXf = (float)anchorX;
                        anchorYf = (float)anchorY;
                        fwrite(&anchorXf, sizeof(float), 1, pObjectFile);
                        fwrite(&anchorYf, sizeof(float), 1, pObjectFile);
                        
                        writelog("anchorX = %f, anchorY = %f", anchorX, anchorY);
                        
                        //Start Rotation
                        double startRotation;
                        if(GetDouble(cx, refObj, refMemberIndex++, &startRotation) == JS_FALSE)
                            return ReturnString(cx, "q _ 16", rval);
                        
                        float rotf = (float)startRotation;
                        fwrite(&rotf, sizeof(float), 1, pObjectFile);
                        
                        writelog("rotation = %f", startRotation);
                        
                        //Start Scale
                        double scaleX;
                        double scaleY;
                        if(GetDouble(cx, refObj, refMemberIndex++, &scaleX) == JS_FALSE)
                            return ReturnString(cx, "q _ 17", rval);
                        if(GetDouble(cx, refObj, refMemberIndex++, &scaleY) == JS_FALSE)
                            return ReturnString(cx, "q _ 18", rval);
                        
                        float scaleXf, scaleYf;
                        scaleXf = (float)scaleX;
                        scaleYf = (float)scaleY;
                        fwrite(&scaleXf, sizeof(float), 1, pObjectFile);
                        fwrite(&scaleYf, sizeof(float), 1, pObjectFile);
                        
                        writelog("scale x = %f, y = %f", scaleX, scaleY);
                        
                        //Start Skew
                        double startSkewX;
                        double startSkewY;
                        if(GetDouble(cx, refObj, refMemberIndex++, &startSkewX) == JS_FALSE)
                            return ReturnString(cx, "q _ 19", rval);
                        if(GetDouble(cx, refObj, refMemberIndex++, &startSkewY) == JS_FALSE)
                            return ReturnString(cx, "q _ 20", rval);
                        
                        float skewXf, skewYf;
                        skewXf = (float)startSkewX;
                        skewYf = (float)startSkewY;
                        fwrite(&skewXf, sizeof(float), 1, pObjectFile);
                        fwrite(&skewYf, sizeof(float), 1, pObjectFile);
                        
                        writelog("skew x = %f, y = %f", startSkewX, startSkewY);
                        
                        if(type == _TYPE_GRAPHIC_ || type == _TYPE_MOVIECLIP_) {
                            //Start Color Style
                            long startColorAlphaPercent;
                            long startColorRedPercent;
                            long startColorGreenPercent;
                            long startColorBluePercent;
                            long startColorAlphaAmount;
                            long startColorRedAmount;
                            long startColorGreenAmount;
                            long startColorBlueAmount;
                            
                            if(GetInteger(cx, refObj, refMemberIndex++, &startColorAlphaPercent) == JS_FALSE)
                                return ReturnString(cx, "q _ 22", rval);
                            if(GetInteger(cx, refObj, refMemberIndex++, &startColorRedPercent) == JS_FALSE)
                                return ReturnString(cx, "q _ 23", rval);
                            if(GetInteger(cx, refObj, refMemberIndex++, &startColorGreenPercent) == JS_FALSE)
                                return ReturnString(cx, "q _ 24", rval);
                            if(GetInteger(cx, refObj, refMemberIndex++, &startColorBluePercent) == JS_FALSE)
                                return ReturnString(cx, "q _ 25", rval);
                            if(GetInteger(cx, refObj, refMemberIndex++, &startColorAlphaAmount) == JS_FALSE)
                                return ReturnString(cx, "q _ 26", rval);
                            if(GetInteger(cx, refObj, refMemberIndex++, &startColorRedAmount) == JS_FALSE)
                                return ReturnString(cx, "q _ 27", rval);
                            if(GetInteger(cx, refObj, refMemberIndex++, &startColorGreenAmount) == JS_FALSE)
                                return ReturnString(cx, "q _ 28", rval);
                            if(GetInteger(cx, refObj, refMemberIndex++, &startColorBlueAmount) == JS_FALSE)
                                return ReturnString(cx, "q _ 29", rval);
                            
                            char alphaPercent = (char)startColorAlphaPercent;
                            char redPercent = (char)startColorRedPercent;
                            char greenPercent = (char)startColorGreenPercent;
                            char bluePercent = (char)startColorBluePercent;
                            short alphaAmount = (short)startColorAlphaAmount;
                            short redAmount = (short)startColorRedAmount;
                            short greenAmount = (short)startColorGreenAmount;
                            short blueAmount = (short)startColorBlueAmount;                            
                            fwrite(&redPercent, sizeof(char), 1, pObjectFile);
                            fwrite(&greenPercent, sizeof(char), 1, pObjectFile);
                            fwrite(&bluePercent, sizeof(char), 1, pObjectFile);
                            fwrite(&alphaPercent, sizeof(char), 1, pObjectFile);                            
                            fwrite(&redAmount, sizeof(short), 1, pObjectFile);
                            fwrite(&greenAmount, sizeof(short), 1, pObjectFile);
                            fwrite(&blueAmount, sizeof(short), 1, pObjectFile);
                            fwrite(&alphaAmount, sizeof(short), 1, pObjectFile);
                            
                            writelog("alpha percent = %d", startColorAlphaPercent);
                            writelog("red percent = %d", startColorRedPercent);
                            writelog("green percent = %d", startColorGreenPercent);
                            writelog("blue percent = %d", startColorBluePercent);
                            writelog("alpha amount = %d", startColorAlphaAmount);
                            writelog("red amount = %d", startColorRedAmount);
                            writelog("green amount = %d", startColorGreenAmount);
                            writelog("blue amount = %d", startColorBlueAmount);
                        }
                        
                        if(type == _TYPE_GRAPHIC_ || type == _TYPE_MOVIECLIP_)  {
                            long startColorBlendMode;
                            if(GetInteger(cx, refObj, refMemberIndex++, &startColorBlendMode) == JS_FALSE)
                                return ReturnString(cx, "q _ 30", rval);
                            
                            unsigned char blendMode = (unsigned char)startColorBlendMode;
                            fwrite(&blendMode, sizeof(blendMode), 1, pObjectFile);
                            writelog("blend mode = %d", startColorBlendMode);
                            
                            //Ease
                            long easeType;
                            if(GetInteger(cx, refObj, refMemberIndex++, &easeType) == JS_FALSE)
                                return ReturnString(cx, "q _ 31", rval);
                            
                            writelog("ease type = %d", easeType);
                            
                            unsigned char easeTypeuc = (unsigned char)easeType;
                            fwrite(&easeTypeuc, sizeof(easeTypeuc), 1, pObjectFile);
                            
                            if(easeType == 2) {  //멀티 타입일 경우(Position, Rotation, Scale, Color, Filters)
                                for(int l = 0; l < 4; ++l)
                                {
                                    JSObject* easeObj;
                                    if(GetObject(cx, refObj, refMemberIndex++, &easeObj) == JS_FALSE)
                                        return ReturnString(cx, "q _ 32", rval);
                                    
                                    writelog("get multi ease obj");
                                    
                                    int easeCount = JS_GetArrayLength(cx, easeObj);
                                    if(easeCount == -1)
                                        return ReturnString(cx, "q _ 33", rval);
                                    
                                    writelog("get ease length = %d", easeCount);
                                    
                                    fwrite(&easeCount, sizeof(int), 1, pObjectFile);
                                    
                                    for(int k = 0; k < easeCount; ++k) {
                                        JSObject* posObj;
                                        if(GetObject(cx, easeObj, k, &posObj) == JS_FALSE)
                                            return ReturnString(cx, "q _ 34", rval);
                                        
                                        writelog("get pos obj");
                                        
                                        double x, y;
                                        if(GetDouble(cx, posObj, 0, &x) == JS_FALSE)
                                            return ReturnString(cx, "q _ 35", rval);
                                        if(GetDouble(cx, posObj, 1, &y) == JS_FALSE)
                                            return ReturnString(cx, "q _ 36", rval);
                                        
                                        float fx, fy;
                                        fx = (float)x;
                                        fy = (float)y;
                                        fwrite(&fx, sizeof(float), 1, pObjectFile);
                                        fwrite(&fy, sizeof(float), 1, pObjectFile);
                                        
                                        writelog("x = %f, y = %f", x, y);
                                    }
                                }
                            } else if(easeType == 1) {        //싱글이나 심플일 경우
                                JSObject* easeObj;
                                if(GetObject(cx, refObj, refMemberIndex++, &easeObj) == JS_FALSE)
                                    return ReturnString(cx, "q _ 37", rval);
                                
                                writelog("get ease obj");
                                
                                int easeCount = JS_GetArrayLength(cx, easeObj);
                                if(easeCount == -1)
                                    return ReturnString(cx, "q _ 38", rval);
                                
                                writelog("get ease length = %d", easeCount);
                                
                                fwrite(&easeCount, sizeof(int), 1, pObjectFile);
                                
                                for(int k = 0; k < easeCount; ++k) {
                                    JSObject* posObj;
                                    if(GetObject(cx, easeObj, k, &posObj) == JS_FALSE)
                                        return ReturnString(cx, "q _ 39", rval);
                                    
                                    writelog("get pos obj");
                                    
                                    double x, y;
                                    if(GetDouble(cx, posObj, 0, &x) == JS_FALSE)
                                        return ReturnString(cx, "q _ 40", rval);
                                    if(GetDouble(cx, posObj, 1, &y) == JS_FALSE)
                                        return ReturnString(cx, "q _ 41", rval);
                                    
                                    float fx, fy;
                                    fx = (float)x;
                                    fy = (float)y;
                                    fwrite(&fx, sizeof(float), 1, pObjectFile);
                                    fwrite(&fy, sizeof(float), 1, pObjectFile);
                                    
                                    writelog("x = %f, y = %f", x, y);
                                }
                            }
                        }    
                    }
                }                
            }
            
//			//프레임
//            {
//                JSObject* frameObj;
//                if(GetObject(cx, dynamicObj, 2, &frameObj) == JS_FALSE)
//                    return ReturnString(cx, "q _ 60", rval);
//                
//                writelog("get frame obj");
//                
//                //프레임 개수
//                int frameCount;
//                frameCount = JS_GetArrayLength(cx, frameObj);
//                if(frameCount == -1)
//                    return ReturnString(cx, "q _ 61", rval);
//                
//                writelog("get frame count = %d", frameCount);
//                
//                fwrite(&frameCount, sizeof(int), 1, pObjectFile);
//                
//                for(int j = 0; j < frameCount; ++j) {
//                    //레퍼런스 아이디 배열
//                    JSObject* refObj;
//                    if(GetObject(cx, frameObj, j, &refObj) == JS_FALSE)
//                        return ReturnString(cx, "q _ 62", rval);
//                    
//                    fwrite(&j, sizeof(int), 1, pObjectFile);
//                    
//                    writelog("frame = %d", j);
//                    
//                    //레퍼런스 개수
//                    int refCount = JS_GetArrayLength(cx, refObj);
//                    if(refCount == -1)
//                        return ReturnString(cx, "q _ 63", rval);
//                    
//                    fwrite(&refCount, sizeof(int), 1, pObjectFile);
//                    
//                    writelog("ref count = %d", refCount);
//                    
//                    for(int k = 0; k < refCount; ++k) {
//                        //레퍼런스 번호
//                        long refid;
//                        if(GetInteger(cx, refObj, k, &refid) == JS_FALSE)
//                            return ReturnString(cx, "q _ 64", rval);
//                        
//                        fwrite(&refid, sizeof(long), 1, pObjectFile);
//                        
//                        writelog("ref id = %d", refid);
//                    }
//                }
//            }
		}
        
		*rval = JS_BooleanToValue(JS_TRUE);
		
		return JS_TRUE; 
	} else {
		return ReturnString(cx, "a _ 17", rval);
	}
}
Пример #10
0
Waifu2x::eWaifu2xError Waifu2x::LoadParameterFromJson(boost::shared_ptr<caffe::Net<float>> &net, const boost::filesystem::path &model_path, const boost::filesystem::path &param_path
	, const boost::filesystem::path &modelbin_path, const boost::filesystem::path &caffemodel_path, const std::string &process)
{
	Waifu2x::eWaifu2xError ret;

	caffe::NetParameter param;
	ret = readProtoText(model_path, &param);
	if (ret != eWaifu2xError_OK)
		return ret;

	ret = writeProtoBinary(param, modelbin_path);
	if (ret != eWaifu2xError_OK)
		return ret;

	ret = SetParameter(param, process);
	if (ret != eWaifu2xError_OK)
		return ret;

	net = boost::shared_ptr<caffe::Net<float>>(new caffe::Net<float>(param));

	rapidjson::Document d;
	std::vector<char> jsonBuf;

	try
	{
		boost::iostreams::stream<boost::iostreams::file_descriptor_source> is(param_path, std::ios_base::in | std::ios_base::binary);

		try
		{
			is.open(param_path, std::ios_base::in | std::ios_base::binary);
		}
		catch (...)
		{
			return Waifu2x::eWaifu2xError_FailedOpenModelFile;
		}

		if(!is)
			return eWaifu2xError_FailedOpenModelFile;

		const size_t size = is.seekg(0, std::ios::end).tellg();
		is.seekg(0, std::ios::beg);

		jsonBuf.resize(size + 1);
		is.read(jsonBuf.data(), jsonBuf.size());

		jsonBuf[jsonBuf.size() - 1] = '\0';

		d.Parse(jsonBuf.data());
	}
	catch (...)
	{
		return eWaifu2xError_FailedParseModelFile;
	}

	if (d.Size() != 7)
		return eWaifu2xError_FailedParseModelFile;

	int inputPlane = 0;
	int outputPlane = 0;
	try
	{
		inputPlane = d[0]["nInputPlane"].GetInt();
		outputPlane = d[d.Size() - 1]["nOutputPlane"].GetInt();
	}
	catch (...)
	{
		return eWaifu2xError_FailedParseModelFile;
	}

	if (inputPlane == 0 || outputPlane == 0)
		return eWaifu2xError_FailedParseModelFile;

	if (inputPlane != outputPlane)
		return eWaifu2xError_FailedParseModelFile;

	//if (param.layer_size() < 17)
	//	return eWaifu2xError_FailedParseModelFile;

	std::vector<boost::shared_ptr<caffe::Layer<float>>> list;
	auto &v = net->layers();
	for (auto &l : v)
	{
		auto lk = l->type();
		auto &bv = l->blobs();
		if (bv.size() > 0)
			list.push_back(l);
	}

	try
	{
		std::vector<float> weightList;
		std::vector<float> biasList;

		int count = 0;
		for (auto it = d.Begin(); it != d.End(); ++it)
		{
			const auto &weight = (*it)["weight"];
			const auto nInputPlane = (*it)["nInputPlane"].GetInt();
			const auto nOutputPlane = (*it)["nOutputPlane"].GetInt();
			const auto kW = (*it)["kW"].GetInt();
			const auto &bias = (*it)["bias"];

			auto leyer = list[count];

			auto &b0 = leyer->blobs()[0];
			auto &b1 = leyer->blobs()[1];

			float *b0Ptr = nullptr;
			float *b1Ptr = nullptr;

			if (caffe::Caffe::mode() == caffe::Caffe::CPU)
			{
				b0Ptr = b0->mutable_cpu_data();
				b1Ptr = b1->mutable_cpu_data();
			}
			else
			{
				b0Ptr = b0->mutable_gpu_data();
				b1Ptr = b1->mutable_gpu_data();
			}

			const auto WeightSize1 = weight.Size();
			const auto WeightSize2 = weight[0].Size();
			const auto KernelHeight = weight[0][0].Size();
			const auto KernelWidth = weight[0][0][0].Size();

			if (!(b0->count() == WeightSize1 * WeightSize2 * KernelHeight * KernelWidth))
				return eWaifu2xError_FailedConstructModel;

			if (!(b1->count() == bias.Size()))
				return eWaifu2xError_FailedConstructModel;

			weightList.resize(0);
			biasList.resize(0);

			size_t weightCount = 0;
			for (auto it2 = weight.Begin(); it2 != weight.End(); ++it2)
			{
				for (auto it3 = (*it2).Begin(); it3 != (*it2).End(); ++it3)
				{
					for (auto it4 = (*it3).Begin(); it4 != (*it3).End(); ++it4)
					{
						for (auto it5 = (*it4).Begin(); it5 != (*it4).End(); ++it5)
							weightList.push_back((float)it5->GetDouble());
					}
				}
			}

			caffe::caffe_copy(b0->count(), weightList.data(), b0Ptr);

			for (auto it2 = bias.Begin(); it2 != bias.End(); ++it2)
				biasList.push_back((float)it2->GetDouble());

			caffe::caffe_copy(b1->count(), biasList.data(), b1Ptr);

			count++;
		}

		net->ToProto(&param);

		ret = writeProtoBinary(param, caffemodel_path);
		if (ret != eWaifu2xError_OK)
			return ret;
	}
	catch (...)
	{
		return eWaifu2xError_FailedConstructModel;
	}

	input_plane = inputPlane;

	return eWaifu2xError_OK;
}
Пример #11
0
bool SelectCommand::Apply(CommandExecutionContext context)
{
   wxString mode = GetString(wxT("Mode"));
   if (mode.IsSameAs(wxT("None")))
   {
      // select none
      context.GetProject()->OnSelectNone();
   }
   else if (mode.IsSameAs(wxT("All")))
   {
      // select all
      context.GetProject()->OnSelectAll();
   }
   else if (mode.IsSameAs(wxT("Range")))
   {
      // select range
      double t0 = GetDouble(wxT("StartTime"));
      double t1 = GetDouble(wxT("EndTime"));

      TrackList *tracks = context.GetProject()->GetTracks();

      if (t0 < context.GetProject()->GetTracks()->GetMinOffset())
      {
         Error(wxT("Start time is before start of track!"));
         return false;
      }
      if (t1 > context.GetProject()->GetTracks()->GetEndTime())
      {
         Error(wxT("End time is after end of track!"));
         return false;
      }

      // PRL: to do: only setting time boundaries of current selection.
      // Should other fields be left alone, or rather
      // defaulted, as in the second branch?
      // Or should this command take more parameters?
#if 1
      context.GetProject()->mViewInfo.selectedRegion.setTimes(t0, t1);
#else
      context.GetProject()->mViewInfo.selectedRegion = SelectedRegion(t0, t1);
#endif

      // select specified tracks
      long firstTrack = GetLong(wxT("FirstTrack"));
      long lastTrack = GetLong(wxT("LastTrack"));

      if (firstTrack < 0)
      {
         Error(wxT("Trying to select a negatively numbered track!"));
         return false;
      }
      if (lastTrack >= tracks->GetCount())
      {
         Error(wxT("Trying to select higher number track than exists!"));
         return false;
      }

      int index = 0;
      TrackListIterator iter(tracks);
      Track *t = iter.First();
      while (t) {
         bool sel = firstTrack <= index && index <= lastTrack;
         t->SetSelected(sel);

         if (sel)
            Status(wxT("Selected track '") + t->GetName() + wxT("'"));

         t = iter.Next();
         ++index;
      }
      wxASSERT(index >= lastTrack);
   }
   else if (mode.IsSameAs(wxT("Name")))
   {
      wxString name = GetString(wxT("TrackName"));
      TrackList *tracks = context.GetProject()->GetTracks();
      TrackListIterator iter(tracks);
      Track *t = iter.First();
      while (t) {
         bool sel = t->GetName().IsSameAs(name);
         t->SetSelected(sel);

         if (sel)
            Status(wxT("Selected track '") + t->GetName() + wxT("'"));

         t = iter.Next();
      }
   }
   else
   {
      Error(wxT("Invalid selection mode!"));
      return false;
   }
   return true;
}
Пример #12
0
float CUini::GetFloat(const CString sAppName, const CString sKeyName)
{
	return (float)GetDouble(sAppName, sKeyName);
}
Пример #13
0
inline bool CField::operator!=(double dValue) const
{
	return (dValue != GetDouble());
}
Пример #14
0
inline CField::operator double() const
{
	return GetDouble();
}
Пример #15
0
/********************************************************************
Hermetically sealed reciprocating compressor model.  Process
modeled as polytropic compression.

States:  (1)-inlet to compressor,
			(2)-outlet of compressor.

Inputs:	H1 (enthalpy state 1, J/kg),
	P1 (pressure state 1, kPa),
	P2 (pressure state 2, kPa),
	Toa (ambient temperature, C), and
	Prms (pointer to array of 3 multiplicative fitting factors for
	volumetric, motor electrical, and polytropic efficiencies
	respectively).  These should all be 1 except when used
	for fitting experimental data.

Outputs:mr (refrigerant mass flow rate, kg/s),
	HPo (refrigerant state at compressor outlet, J/kg, kPa),
	HPi (refrigerant state at compressor inlet, J/kg, kPa),
	Ei (compressor motor power consumption, W),
	m (mass of charge in compressor and total volume, kg, m^3), and
	status (set non-zero to indicate error),
********************************************************************/
void Compressor(const char *filename,
				double H1,
				double P1,
				double P2,
				double Toa,
				double *mr,
				HP *HPo,
				HP *HPi,
				double *Ei,
				MASS *m,
				double *Prms)
{
	static int type;
	static CompP101 Q101;
	static CompP102 Q102;
	// B.S. the following is added for ARI standard
	static CompP103 Q103;
	static int endSign;

	// Load model parameters from file "comp.dat"
	if(compInit) {
		FILE *fp = fopen(filename,"r");
		if(!(type=PosComponentData(fp,COMPRESSOR,1))) {
			errorLog.Add("Compressor","Parameters not found");
			return;
		}
		switch(type) {
			int i;
			case 101: // physical model
				Q101.rpm=GetDouble(fp);
				Q101.dispVolume=GetDouble(fp);
				Q101.np=GetDouble(fp);
				for(int i=0;i<5;i++) Q101.PowerP[i]=GetDouble(fp);
				for(int i=0;i<4;i++) Q101.VolumeEffP[i]=GetDouble(fp);
				for(int i=0;i<3;i++) Q101.Adj[i]=GetDouble(fp);
				Q101.InnerVolume=GetDouble(fp);
				Q101.OilCharge=GetDouble(fp);
				Q101.OilTemp=Prms[3];//GetDouble(fp);
				Q101.OilType = (int)GetDouble(fp);
				break;
			case 102: // compressor map model
				Q102.np = GetDouble(fp);
				for(int i=0;i<11;i++) Q102.powerP[i] = GetDouble(fp);
				for(int i=0;i<11;i++) Q102.massFlowP[i] = GetDouble(fp);
				for(int i=0;i<3;i++)  Q102.Adj[i] = GetDouble(fp);
				Q102.InnerVolume=GetDouble(fp);
				Q102.OilCharge=GetDouble(fp);
				Q102.OilTemp=Prms[3];//GetDouble(fp);
				Q102.OilType = (int)GetDouble(fp);
				break;
//B.S.------------------------
//add for ARI standard compressor equations in the form of polynomial with ten terms
				case 103:
				Q103.rpm = GetDouble(fp);//B.S. no use, put it here in case
				Q103.dispVolume=GetDouble(fp);//B.S. no use, put it here in case
				Q103.np=GetDouble(fp);
				for(int i=0;i<10;i++) Q103.powerP[i] = GetDouble(fp);
				for(int i=0;i<10;i++) Q103.massFlowP[i] = GetDouble(fp);
				for(int i=0;i<3;i++)  Q103.Adj[i] = GetDouble(fp);
				Q103.InnerVolume=GetDouble(fp);//compressor free inner volume
				Q103.OilCharge=GetDouble(fp);//oil chargre amount
				//lubricant temperature
				Q103.OilTemp=GetDouble(fp);//oil temperature
				Q103.OilTemp=Prms[3];//B.S. new, input from master.in or states.in
				//---------------------------
				Q103.OilType = (int)GetDouble(fp);// oil type for getting the correct solubility equation
				break;
//--------------------------------------B.S.
				default:
				break;

		};

		endSign = (int)GetDouble(fp);//-256
		fclose(fp);

		if(endSign!=-256)
		{
		errorLog.Add("Compressor","Parameter input wrong");
		return;
		}

		compInit=0;
	}

	switch(type) {
		case 101:
			Compressor101(Q101,H1,P1,P2,Toa,mr,HPo,HPi,Ei,m,Prms);
			break;
		case 102:
			Compressor102(Q102,H1,P1,P2,Toa,mr,HPo,HPi,Ei,m,Prms);
			break;
//B.S.------------------------
//add for ARI standard compressor equations in the form of polynomial with ten terms
		case 103:
			Compressor103(Q103,H1,P1,P2,Toa,mr,HPo,HPi,Ei,m,Prms);
//--------------------------------------B.S.
			break;
	};

}
Пример #16
0
void TrackEncoder( void)
{
	const int MaxTries = 9;
	int count = 0;
	int step;
	double StepsPerSec;
	int rate;

	TE = (struct AZLong*) malloc( MsInWindings * sizeof( struct AZLong));
	if( TE == NULL)
		BadExit( "Problem with malloc of TE in TrackEncoder()");

	WriteWindow( MsgFrame);

	gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 1);
	printf( "moving motors to start position...");
	/* attempt to move both motors to microstep '0' on winding 'A' */
	do
	{
		Steps.A = (MsIx.A/MaxPWM) % MsInWindings;
		if( Steps.A && Dir.A == CW)
			Steps.A = MsInWindings - Steps.A;
		Steps.Z = (MsIx.Z/MaxPWM) % MsInWindings;
		if( Steps.Z && Dir.Z == CW)
			Steps.Z = MsInWindings - Steps.Z;
		MoveMs_f_ptr();
		count++;
	}while( count < MaxTries && (Steps.A || Steps.Z));

	/* get rate of motion */
	gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 2);
	printf( "Please enter speed in microsteps per second ");
	if( !GetDouble( &StepsPerSec))
		/* if user aborts, then set it up so that no more execution occurs */
		count = MaxTries;
	else
		/* split rate in half bec. encoders read halfway through */
		rate = (int) (.5 + ClockTicksSec / (2.*StepsPerSec));

	if( count < MaxTries)
	{
		/* move MsInWindings microsteps, taking encoder readings as we go */
		for( step = 0; step < MsInWindings; step++)
		{
			Steps.A = Steps.Z = 1;
			for( Ix = 0; Ix < rate; Ix++)
				MoveMs_f_ptr();
			QueryEncoders_f_ptr();
			for( Ix = 0; Ix < rate; Ix++)
				MoveMs_f_ptr();
			if( EncoderState == ReadReady)
				ReadEncoders_f_ptr();
			TE[step].A = EncoderCount.A;
			TE[step].Z = EncoderCount.Z;
			gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 3);
			printf( "microstep %d: encA %ld encZ %ld", step, TE[step].A, TE[step].Z);
		}
		gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 4);
		printf( "writing %s file", TrackEncodersFile);
		Output = fopen( TrackEncodersFile, "w");
		if( Input == NULL)
			BadExit( strcat( "Could not open ", TrackEncodersFile));
		for( step = 0; step < MsInWindings; step++)
			fprintf( Output, "%d %ld %ld\n", step, TE[step].A, TE[step].Z);
		fclose( Output);
		gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 5);
		ContMsgRoutine();
		RemoveWindow( MsgFrame);
	}
	else
	{
		RemoveWindow( MsgFrame);
		PressKeyToContMsg( "could not move motors to start position");
	}
	free( TE);
	PauseUntilNewSidTime();
	HPEventGetEquat();
}
Пример #17
0
	double FeatureShp::GetDouble(const char* name) const
	{
		return GetDouble(m_pFields->FindField(name));
	}
Пример #18
0
double Gdal::Band::GetDouble(int x, int y) const
{
	double out;
	GetDouble(&out, x, y, 1);
	return out;
}
JNIEXPORT jdouble JNICALL Java_jACBrFramework_ACBrECF_getVendaBruta(JNIEnv *env, jobject obj)
{
	return GetDouble(&ECF_GetVendaBruta, env, obj);
}
Пример #20
0
 float SEXPR::GetFloat() const
 {
     return static_cast< float >( GetDouble() );
 }