📄 cdbfile.ps
字号:
b(//)19 b(field)h(name)f(in)h(ASCII)g(zero-filled)2052264 y(char)279 b(Type;)159 b(//)19 b(field)h(type)f(in)h(ASCII)2052303 y(unsigned)f(char)100 b(Length;)119 b(//)19 b(field)h(length)f(in)h(binary)205 2343 y(unsigned)f(char)100 b(DecCount;)79b(//)19 b(field)h(decimal)f(count)h(in)g(binary)205 2382y(unsigned)f(char)100 b(FieldNumber;)19 b(//)g(field)h(number)f(within)h(the)g(record)205 2422 y(unsigned)f(short)80 b(Offset;)119b(//)19 b(field)h(offset)f(within)h(the)g(character)f(string)2052461 y(CField*)219 b(Next;)159 b(//)19 b(Next)h(field)f(in)h(the)g(list)205 2501 y(...)165 2540 y(};)227 2651 y Fq(Y)l(ou)11b(can)g(see)g(that)e(all)i(the)g(data)f(that)g(can)i(be)e(found)i(in)f(the)f(\256eld)i(descriptors)f(is)f(stor)o(ed)165 2697y(in)h(those)f Fn(CField)h Fq(objects)f(\(apart)g(fr)o(om)h(the)f(\256eld)i(data)e(addr)o(ess,)i(which)g(is)e(useless)g(when)1652743 y(you)f(ar)o(e)h(not)f(using)h(the)f(\256rst)g(versions)h(of)fFr(Ashton-T)-5 b(ate')n(s)10 b(dBASE)g Fq(\).)g(An)g(additional)g(value)165 2789 y(has)i(been)h(appended:)19 b(the)12b Fn(Offset)g Fq(\256eld,)i(which)f(indicates)g(the)f(beginning)h(of)f(the)h(\256eld)165 2835 y(within)7 b(the)g(raw)g(character)g(string.)13b(The)8 b Fn(CField*)24 b(Next)7 b Fq(pointer)g(points)f(to)h(the)f(next)i(\256eld)905 2960 y(4)p eop%%Page: 5 55 4 bop 165 195 a Fq(structur)o(e)9 b(in)g(the)f(ring.)15b(Every)10 b(member)e(variable)h(can)g(be)g(r)o(ead)h(or)e(written)h(to)f(using)g(the)h(as-)165 241 y(sociated)i(public)g(member)g(functions.)16 b(T)l(wo)11 b(special)g(functions)g(\(in)g(fact,)g(two)f(overloaded)165 287 y(versions)g(of)g(the)g(same)f(member)h(function\))g(ar)o(e)h(pr)o(ovided)g(to)f(access)g(the)g(right)g(CField)i(ob-)165333 y(ject)7 b(in)h(the)g(ring,)h(using)f(either)g(its)f(name)g(or)h(its)f(number)h(to)f(identify)h(it.)13 b(These)7 b(ar)o(e)i(r)o(ecursive)165 379 y(functions)i(which)h(need)g(a)f Fn(CField)gFq(pointer)g(to)g(r)o(eturn)h(the)f(position)g(of)g(a)gFn(CField)g Fq(object)165 426 y(within)g(the)g(ring)i(\320)e(see)g(the)g(code)h(for)f(mor)o(e)h(details.)17 b(So)11 b(her)o(e)h(ar)o(e)g(the)f(headers)h(for)f(those)165 472 y(member)f(functions)g(:)165584 y Fg(class)20 b(CField)165 623 y({)165 663 y(private)f(:)165702 y(...)165 742 y(public)g(:)205 781 y(CField\(\);)398b(//)19 b(default)h(constructor)205 820 y(CField\(char*)f(NName,)g(char)h(NType,)f(unsigned)h(char)f(NLength,)245 860 y(unsigned)g(char)h(NDecCount,)f(unsigned)g(char)h(FieldNum\);)783 899 y(//)f(another)h(constructor)205 939 y(\304CField\(\);)378 b(//)19 b(default)h(destructor)205 1018 y(char*)f(GetName\(\))279 b({)20b(return)f(Name;)h(})205 1057 y(void)f(SetName\(char*)g(NewName\))40b({)20 b(strcpy\(Name,)f(NewName\);)g(})205 1096 y(//)h(...and)f(so)h(on)g(for)f(all)h(the)g(member)f(variables)205 1175 y(CField*)g(GetField\(char*)g(FieldName,)g(CField*)h(Start=NULL\);)2051215 y(CField*)f(GetField\(unsigned)g(short)g(Number,)h(CField*)f(Start=NULL\);)165 1254 y(};)227 1377 y Fq(That's)8 b(all)h(for)g(the)gFn(CField)f Fq(object,)h(which)h(you)e(won't)g(have)h(to)f(use)h(dir)o(ectly)h(\320)f(unless)165 1426 y(you)h(want)g(to)f(add)i(some)e(mor)o(e)h(functions)g(to)g(CDBFile.)165 1548 y Fj(3.4)50 b(The)13b(CDBFile)f(object)165 1627 y Fq(Now)d(let's)f(get)g(down)h(to)f(some)g(serious)h(work.)k(This)d(is)f(the)f(main)h(part)g(of)f(the)h(toolbox,)g(and)165 1677 y(only)j(a)g(few)g(member)g(functions)f(of)hFn(CDBFile)g Fq(ar)o(e)g(available)g(for)g(the)g(user)g(\(i.e.,)i(the)e(pr)o(o-)165 1726 y(grammer)g(who)f(doesn't)f(want)h(to)g(handle)h(raw)f(DBF)i(\256les)e(bar)o(ehands!\).)18 b(This)12 b(object)f(ma-)1651776 y(nipulates)e(four)i(major)e(entities)g(:)227 1859y Ff(\017)21 b Fr(The)10 b(CField)g(ring:)15 b Fq(see)10b(the)f(description)i(of)f Fn(CField)g Fq(above.)2271942 y Ff(\017)21 b Fr(The)13 b(Record)h(list:)19 b Fq(A)13b(double-linked)h(list)e(of)h(structur)o(es)g(containing)g(the)f(data)h(in)g(a)269 1992 y(raw)g(ASCII)h(format,)f(straight)g(fr)o(om)g(the)g(\256le.)23 b(This)14 b(is)f(the)g(cor)o(e)h(of)f(the)g(object,)h(and)269 2042 y(most)9 b(of)g(the)h(member)g(functions)g(will)g(manipulate)g(that)f(list.)227 2125 y Ff(\017)21 b Fr(The)11 b(contents)h(of)f(those)g(records:)17 b Fq(A)11 b(character)h(table)e(containing)h(raw)g(data.)16 b(Since)269 2175 y(we)9 b(know)g(the)g(of)o(fset,)g(the)g(length)g(and)h(the)f(type)g(of)h(each)f(\256eld,)i(we)e(can)h(convert)g(that)269 2225 y(data)g(into)g(numbers)h(or)g(character)h(strings,)e(or)h(even)h(booleans;)e(we)g(can)i(also)e(do)g(the)2692274 y(r)o(everse)h(operation)e(in)i(or)o(der)g(to)f(write)g(or)g(modify)g(a)g(value)h(within)f(a)g(r)o(ecor)o(d.)2272357 y Ff(\017)21 b Fr(The)8 b(DBF)g(\256le:)13 b Fq(it)8b(will)h(be)f(accessed)h(for)f(r)o(eading)i(or)e(writing)h(r)o(ecor)o(ds.)15 b(It)8 b(is)g Fe(absolutely)269 2407 y(necessary)15b Fq(to)6 b(open)h(such)h(a)e(\256le)i(in)f(or)o(der)h(to)f(initialize)f(the)h(\256eld)h(descriptor)f(ring,)i(since)269 2457y(that)f(toolbox)g(does)g(not)g(pr)o(ovide)i(yet)f(\(shame!)i(shame!\))h(enough)d(functions)f(to)g(build)269 2507 y(a)i Fn(CDBFile)gFq(object)f(fr)o(om)h(scratch.)165 2620 y Fr(3.4.1)42b(Handling)10 b(the)g(record)i(list)165 2694 y Fq(Her)o(e)e(is)g(the)g(structur)o(e)g(of)g(the)g(r)o(ecor)o(ds,)i(as)e(declar)o(ed)i(in)e(the)g(sour)o(ce:)905 2960 y(5)p eop%%Page: 6 66 5 bop 165 235 a Fg(struct)19 b(rec)165 274 y({)205313 y(char*)g(Contents;)259 b(//)20 b(raw)f(character)g(string)205353 y(BOOL)g(ModifFlag;)259 b(//)20 b(TRUE)f(if)h(the)g(record)f(has)h(been)f(modified)205 392 y(unsigned)g(long)h(RecordNumber;)f(//)h(Position)f(of)h(the)f(record)h(within)f(the)h(file)205432 y(struct)f(rec)h(*Next;)219 b(//)20 b(Points)f(to)h(the)f(next)h(record)g(in)f(the)h(list)205 471 y(struct)f(rec)h(*Previous;)139b(//)20 b(Points)f(to)h(the)f(previous)h(record)f(in)h(the)g(list)165511 y(};)165 550 y(typedef)f(struct)h(rec)g(Record;)227662 y Fq(This)9 b(is)f(the)g(minimum)g(structur)o(e)g(that)g(we)g(need)h(to)e(pr)o(ocess)i(any)f(kind)h(of)f(DBF)h(r)o(ecor)o(ds,)165708 y(pr)o(ovided)k(that)e(we)g(know)g(the)g(\256eld)h(descriptor)g(array)-5 b(.)19 b(Let's)10 b(have)i(a)g(look)f(at)g(the)g(private)165754 y(variables)f(and)h(function)f(headers)h(below)e(:)165866 y Fg(class)20 b(CDBFile)165 906 y({)165 945 y(private)f(:)205985 y(Record*)g(RecordList;)59 b(//)20 b(Head)g(of)f(the)h(list)g(of)f(records)205 1024 y(Record*)g(CurrentRec;)59 b(//)20b(Current)f(record)h(pointed)f(in)h(the)g(list)165 1064y(...)205 1103 y(Record*)f(ReadRecord\(unsigned)g(long)g(RecNum\);)2051142 y(Record*)g(CreateNewRecord\(\);)205 1182 y(Record*)g(GetRecord\(unsigned)g(long)g(RecordNum\);)205 1221 y(void)g(Append\(Record*)g(Rec,)h(Record*)f(Tail=NULL\);)2051261 y(void)g(DeleteRecord\(Record)g(*Rec\);)205 1300y(void)g(SortAllRecords\(Record)g(*Head,)g(Record)h(*Tail,)f(CField*)h(Criter1\);)165 1340 y(};)227 1462 y Fn(CDBFile)25 bFq(contains)9 b(two)h(pointers)g(to)f(r)o(ecor)o(ds:)16b(the)10 b(former)m(,)h Fn(RecordList)p Fq(,)f(is)h(the)f(at)1651512 y(head)e(of)f(the)h(double-linked)g(list)f(of)h(r)o(ecor)o(ds,)i(wher)o(eas)d(the)g(latter)m(,)h Fn(CurrentRec)p Fq(,)g(points)f(to)1651562 y(the)h(r)o(ecor)o(d)i(that)d(is)h(being)h(handled)g(by)g(the)f(user)m(.)13 b Fn(CurrentRec)7 b Fq(is)i(mainly)f(used)g(by)g(public)165 1611 y(functions)j(that)g(give)i(the)e(user)h(some)f(possibilities)f(to)h(access)g(the)h(r)o(ecor)o(ds)h(indir)o(ectly)g(\(for)1651661 y(r)o(eading)e(or)g(writing,)f(cr)o(eating)h(or)g(deleting\).)2271711 y(As)g(for)f(the)g(private)g(functions,)g(they)g(do)h(the)f(following)f(:)227 1794 y Ff(\017)21 b Fn(ReadRecord\(\))6b Fq(r)o(eads)h(the)f Fn(RecNum)p Fd(th)h Fq(r)o(ecor)o(d)h(in)f(the)g(DBF)g(\256le,)h(and)g(r)o(eturns)f(a)f(poin-)269 1844y(ter)k(to)g(a)g(newly)g(cr)o(eated)h(r)o(ecor)o(d)h(containig)e(the)g(accessed)g(data.)227 1927 y Ff(\017)21 b Fn(CreateNewRecord\(\))9b Fq(r)o(eturns)h(a)g(pointer)g(to)g(a)g(newly)g(cr)o(eated)h(r)o(ecor)o(d.)227 2010 y Ff(\017)21 b Fn(GetRecord\(\))9 b Fq(points)g(to)h(the)g(r)o(ecor)o(d)i(whose)d(number)i(matches)e Fn(RecordNum)pFq(.)227 2093 y Ff(\017)21 b Fn(Append\(\))9 b Fq(inserts)gFn(Rec)h Fq(in)g(the)g(list)f(after)h Fn(Tail)p Fq(,)g(if)gFn(Tail)g Fq(is)f(not)h Fn(NULL)p Fq(.)g(Otherwise,)2692143 y(it)g(will)g(insert)g Fn(Rec)g Fq(in)h(the)f(list)f(accor)o(ding)j(to)e(its)g(r)o(ecor)o(d)i(number)m(.)227 2226 y Ff(\017)21b Fn(DeleteRecord\(\))9 b Fq(simply)h(deletes)f(the)h(r)o(ecor)o(d)i(and)f(its)e(contents.)227 2309 y Ff(\017)21 b Fn(SortAllRecords\(\))10b Fq(operates)g(a)i(quicksort)f(algorithm)g(on)h(the)f(r)o(ecor)o(d)i(list.)18 b(The)269 2359 y(sorting)9 b(is)h(done)g(on)g(the)f(criterium)i Fn(Criter1)p Fq(,)f(which)g(points)f(to)g(a)h(\256eld)g(descriptor:)269 2409 y(the)f(list)h(will)f(be)h(sorted)g(in)g(incr)o(easing)h(or)o(der)g(of)e(the)h Fn(Criter1)f Fq(\256eld)h(of)g(the)f(r)o(ecor)o(ds.)227 2488 y(The)14 b(public)g(functions)f(ar)o(e)h(in)g(fact)f(a)g(convenient)h(way)f(to)g(embed)g(the)g(private)h(func-)1652534 y(tions)9 b(without)f(r)o(equiring)k(the)d(user)h(to)f(manipulate)f(those)h(ugly)h(r)o(ecor)o(d)h(lists)e(or)h(structur)o(es)1652580 y(\(yuck!\),)h(let)f(alone)g(the)h(\256eld)g(descriptors)f(\(ugh!\).)15 b(He)10 b(just)f(has)i(to)e(instantiate)g(a)iFn(CDBFile)165 2626 y Fq(object)f(in)i(his)e(pr)o(ogram,)i(and)g(mind)f(his)g(own)f(business.)15 b(All)d(he)f(has)g(to)f(know)h(about)f(how)165 2672 y(that)g(object)g(works)h(is)g(that)f(ther)o(e)h(is)g(a)g(special)g(pointer)f Fn(CurrentRec)h Fq(\(see)f(above\))h(which)1652718 y(points)f(at)g(the)g(r)o(ecor)o(d)i(he)f(wants)e(to)h(access)g(or)h(to)f(modify)-5 b(,)11 b(and)g(that)e Fn(CurrentRec)hFq(can)h(be)165 2764 y(moved)h(all)g(along)f(the)h(list)f(very)i(easily)-5 b(,)12 b(in)h(an)e(iterative)h(way)-5 b(.)19b(Her)o(e)12 b(ar)o(e)g(the)f(public)i(func-)165 2810y(tions)c(that)h(will)g(enable)g(the)g(pr)o(ogrammer)h(to)e(do)h(so)g(:)905 2960 y(6)p eop%%Page: 7 77 6 bop 165 235 a Fg(class)20 b(CDBFile)165 274 y({)165313 y(...)165 353 y(public:)205 392 y(unsigned)f(long)h(LoadFileToMemory\(\);)205 432 y(unsigned)f(long)h(WriteModified\(\);)205 471 y(void)f(SortOn\(unsigned)g(short)h(Criterium1\);)205511 y(void)f(GetAtRecord\(unsigned)g(long)h(RecordNum\))265550 y({)f(CurrentRec=GetRecord\(RecordNum\);)f(})205589 y(unsigned)h(long)h(GetRecordNum\(\))265 629 y({)f(if)h(\(CurrentRec\))f(return)h(CurrentRec->RecordNumber;)304668 y(else)g(return)g(0L;})225 708 y(BOOL)f(GetNextRecord\(\))265747 y({)g(if)h(\(CurrentRec\))f({)h(CurrentRec=CurrentRec->Next;)e(return)h(TRUE;})524 787 y(else)g(return)h(FALSE;)f(})225826 y(BOOL)g(GetPreviousRecord\(\))265 866 y({)g(if)h(\(CurrentRec\))f({)h(CurrentRec=CurrentRec->Previous;)e(return)h(TRUE;})524905 y(else)g(return)h(FALSE;)f(})205 944 y(void)g(LoadRecord\(unsigned)g(long)h(RecordNum\))265 984 y({)f(CurrentRec=ReadRecord\(RecordNum\);)f(Append\(CurrentRec\);)g(})205 1023 y(void)h(DeleteCurrentRec\(\))2651063 y({)g(CurrentRec=CurrentRec->Previous;)f(DeleteRecord\(CurrentRec->Next\);})205 1102 y(void)h(CreateAndAppend\(\))265 1142 y({)g(CurrentRec=CreateNewRecord\(\);)f(Append\(CurrentRec\);})205 1181 y(void)h(ClearAllRecords\(\);)1651220 y(...)165 1260 y(};)227 1377 y Fq(For)10 b(most)e(of)h(those)f(functions,)h(the)g(souce)h(code)f(is)g(self-explanatory)-5b(.)14 b(Some)8 b(others)h(ar)o(e)165 1427 y(less)k(obvious:)21b Fn(SortOn\(\))p Fq(,)14 b(for)g(example,)h(launches)e(the)h(r)o(ecursive)h(quicksort)f(function)165 1476 y Fn(SortAllRecords\(\))6b Fq(\(see)g(above\).)13 b Fn(LoadFileToMemory\(\))6b Fq(r)o(eads)h(all)h(the)f(r)o(ecor)o(ds)h(on)165 1526y(the)j(\256le)g(using)h Fn(ReadRecord\(\))e Fq(and)i(stor)o(es)e(the)h(r)o(esulting)h(r)o(ecor)o(ds)g(in)g(the)f(list.)17 bFn(Write-)165 1576 y(Modified\(\))11 b Fq(checks)i(all)f(the)f(r)o(ecor)o(ds)i(in)g(the)e(list)g(and)i(writes)e(some)g(of)g(them)g(to)g(the)h(\256le)165 1626 y(if)g(they)f(have)h(been)f(edited)h(or)g(modi\256ed.)18 b Fn(ClearAllRecords\(\))10 b Fq(empties)h(the)g(list)g(and)165 1676 y(deletes)h(all)h(the)g(r)o(ecor)o(ds.)24b(Some)12 b(mor)o(e)h(complex)g(functions)g(also)f(involve)i(manipulating)165 1726 y(the)8 b(contents)f(of)h(those)f(r)o(ecor)o(ds)i(\()p Fn(SortAllRecords\(\))e Fq(is)g(one)h(of)g(those\),)g(or)g(the)g(DBF)h(\256le.)165 1775 y(They)i(will)f(be)g(explained)h(in)g(the)f(next)g(paragraphs.)165 1887 y Fr(3.4.2)42 b(Handling)10b(the)g(contents)i(of)e(the)h(records)165 1962 y Fq(W)l(e)f(have)i(seen)e(the)g(structur)o(e)h(of)f(the)h(r)o(ecor)o(ds)h(in)f(the)f(pr)o(evious)h(section;)g(let's)f(have)h(a)g(look)165 2008y(at)f(the)g(functions)f(that)h(can)h(access)f(the)g(contents)f(of)h(those)f(r)o(ecor)o(ds.)165 2114 y Fg(class)20 b(CDBFile)1652154 y({)165 2193 y(...)165 2233 y(private:)205 2272y(void*)f(GetFieldValue\(Record*)g(Rec,)g(CField*)h(Field\);)2052311 y(void)f(SetFieldValue\(Record*)g(Rec,)g(CField*)h(Field,)f(void*)h(Value\);)205 2351 y(BOOL)f(IsBigger\(void)g(*v1,)h(void)g(*v2,)f(CField*)h(Criterium\);)205 2390 y(BOOL)f(IsSmaller\(void)g(*v1,)h(void)g(*v2,)f(CField*)h(Criterium\);)165 2430 y(...)1652469 y(};)227 2586 y Fq(The)8 b(\256rst)e(one)h(is)gFn(GetFieldValue\(\))p Fq(.)k(That)c(function)g(takes)f(two)f(ar)o(guments:)12 b(a)7 b(poin-)165 2636 y(ter)h(to)g(the)g(r)o(ecor)o(d)i(that)d(is)h(being)h(accessed)f(and)h(a)f(pointer)g(to)g(the)g(\256eld)h(descriptor)g(\(the)f(\256eld)165 2686 y(that)k(contains)h(the)g(accessed)g(value\).)24 b(Knowing)13 b(the)g(of)o(fset)f(and)i(the)e(length)i(of)f(the)g(\256eld)165 2736 y(within)e(the)h(contents)e(string,)j(the)e(function)g(\256rst)h(extracts)f(the)g(corr)o(esponding)i(substring.)165 2785 y(Then)d(it)g(checks)g(the)f(type)g(of)g(the)g(\256eld.)15 b(If)9 b(the)g(\256eld)h(is)g(of)f(type)gFn('N')p Fq(\(numeric)h(value\),)g(ther)o(e)165 2835y(ar)o(e)e(two)f(cases:)13 b(if)8 b(its)f(decimal)h(count)g(is)g(null,)h(then)f(the)g(substring)f(will)h(be)g(converted)h(into)e(a)9052960 y(7)p eop%%Page: 8 88 7 bop 165 195 a Fn(long)7 b Fq(integer)g(value;)h(if)f(not,)h(it)e(will)h(be)g(converted)h(into)e(a)h Fn(double)f Fq(\257oating-point)g(value.)13 b(If)165 245 y(the)8 b(\256eld)g(is)f(of)h(type)fFn('L')p Fq(\(logical)h(value\),)h(the)e(substring)h(will)f(be)h(converted)h(into)e(a)h(boolean)165 295 y(value)13 b(\(de\256ned)g(as)eFn(BOOL)h Fq(in)h(that)e(package,)j(and)e(in)h(Micr)o(o$oft's)e(V)n(isual)h(C++\).)21 b(In)12 b(other)165 345 y(cases,)e(if)f(the)h(\256eld)g(is)g(of)f(type)h Fn('C')f Fq(\(character)i(string\))e(or)hFn('D')p Fq(\(date\),)g(or)g(even)g Fn('M')p Fq(\(Memo)165394 y(number)g(for)g(.DBT)i(blocks\))e(,)g(ther)o(e)h(will)f(be)g(no)g(conversion,)h(the)f(character)h(substring)e(will)165444 y(be)i(kept)g(`as)f(is'.)16 b(Maybe)11 b(some)g(speci\256c)g
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -