Borbin the 🐱

C++ aggregate using a lambda

13 October, 2024


For the EV diff plugin in cPicture, which calculates the exposure difference between pictures, I needed a simple aggregate to print the parameters used.

For example, the list values 1, 2 and 3 should be converted to the string "(1, 2, 3)". An aggregate function maps an enumerable type (vector) to a plain type (string). The function takes the vector, the toString lambda to convert individual vector elements to a string, and the start/end text and the separator.

I wanted to create a function similar to the Join-String function in PowerShell that is both simple and versatile. This is my implementation:

template<class T>
CString JoinString(typename vector<T>::const_iterator begin,
    typename vector<T>::const_iterator end,
    const function<CString(typename T)>& toString,
    const CString& startText,
    const CString& endText,
    const CString& separator)
{
    CString text(startText);

    for (typename vector<T>::const_iterator it = begin; it != end; ++it)
    {
        // Use the lambda to convert the template type data to text.
        text += toString(*it);

        // Skip separator for last element.
        if (it != end - 1)
        {
            text += separator;
        }
    }

    return text + endText;
}


Test case for JoinString using int data.

The input is a vector of three ints which gets converted to a string that starts with an opening bracket '(', separates the elements with a comma ',' and ends with a closing bracket ')'. The toString lambda 'getText' converts the data to a string.

vector <unsigned int> matchList = { 1, 2, 3 };

// toString lambda expression
auto getText([](auto id) { CString text; text.Format(L"%d", id); return text; });

const CString matchParameter(JoinString<unsigned int>(matchList.begin(), matchList.end(), getText, L"(", L")", L", "));

Assert::AreEqual(L"(1, 2, 3)", matchParameter);


Test case for JoinString using string data.

The lambda simply passes the data and can be inlined.

vector <CString> strList = { L"a", L"b", L"c" };

const CString combinedText(JoinString<CString>(strList.begin(), strList.end(), [](auto text) { return text; }, L"[", L"]", L"+"));

Assert::AreEqual(L"[a+b+c]", combinedText);



CJ750 Gearbox gets a new 3rd and 4th gear - Miscellaneous

05 October, 2024


To prevent any oil leak via the clutch shaft passing, add a piece of rubber tube over the clutch shaft and adjust the diameter for a perfect fit inside the input gear shaft.


The mounting flange on the gearbox is slanted. Use a counterbore drill to make the mounting flange perpendicular.


This is my clutch cable holder that gets mounted on the gearbox. Using the small machined tube part, it takes out any play that would otherwise cause the normal holder to flex and bend the stud each time the clutch is activated.



The new clutch cable holder is now precisely mounted.



CJ750 Gearbox gets a new 3rd and 4th gear - Final Assembly 2

05 October, 2024


Use Loctite 518 gasket maker for the reverse shifter plate.



Add the gaskets.





I created a simple tool to turn the kick start spring front cover.
But a large plier would also work.


Add gasket maker to the screw holes for a oil tight seal. This also works like a thread locker. No need to punch in the small holes to lock the screw as it was done before. Those three large screws only hold the reverse gear shaft and do not need much torque anyway.




Add Dirko (very sticky silicone sealer) to the end of the transmission rods. It will leak from there over time, even it is only a very small amount of oil.
Make sure the distance ring for the bearing that is hold with the (black) output shaft cover plate provide enough play.
Add the test adapter, and make a test run to make sure everything is running smoothly.


Installed

Along with the rebuild final drive, it makes for a perfect drive train.
1st and 2nd gears remain powerful with the 8/37 final drive, but 3rd and 4th now feel like they’re using a high-speed final drive, which is ideal. Previously, I had a high-speed final drive, but starting in 1st gear with a sidecar was challenging, especially on uphill climbs.





CJ750 Gearbox gets a new 3rd and 4th gear - Final Assembly 1

05 October, 2024


Before the gear shaft gets installed, use a reamer to slightly remove the uneven wear caused by the clutch push rod. This is a common place for oil leaks.


Put in the transmission rod half way for the reverse gear shifter.


Slide in the reverse gear shifter.


Insert the input shaft and make sure it spins freely.
The bearing has pieces of aluminium foil glued on for a perfect fit.


Insert the reverse gear shaft.


Insert the output shaft. What works best is to put in the individual gears first on a small rod. Then push the axle through once all gears are in place.


All gears should perfectly match.


Put in the gear change transmission rod along with the gear forks.


Put in the plate and shaft assembly.


The other end of the plate and shaft assembly needs to go to the reverse shifter plate.


Add the distance bushing.



Add gasket maker to the gasket on both sides. This fills in minor gaps for an oil tight seal.


And carefully tighten the cover.



CJ750 Gearbox gets a new 3rd and 4th gear - Test-Adapter

05 October, 2024


To test the gearbox, the input shaft needs to be rotated. To connect the input shaft to a drill for example, an adapter is needed for the input spline.
I'm using an unused clutch for this.


Cut with a plasma cutter since some parts are hardened.




The cut out flange is machined using the input shaft.


To hold the flange with the spline in place, I'm using an old sidecar suspension holder.




The machined parts are secured with Loctite 638.


Finished spline adapter.


The gears gets installed with the dry gaskets only and checked if all gears can be selected and that they run without any grinding noise.



CJ750 Gearbox gets a new 3rd and 4th gear - Output shaft spacers

05 October, 2024


The new 3rd and 4th gear for the output shaft are slightly thinner as the original gears.
To compensate for this, spacers need to be added to have the new gears aligned.

Fabricating spacers with an exact thickness and inner diameter can be difficult. For my new gear set, I cut them from 12L14 round stock.


The exact thickness is machined while keeping a small ridge to hold the part.




The final inner diameter is set and cut. This separates the part.


The new spacers are cut.










← Vorherige Beiträge